-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathloadtest_labelblk.cpp
135 lines (112 loc) · 4.92 KB
/
loadtest_labelblk.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*!
* This file tests the performance of creating a large
* label volume, adding it to DVID, and then doing a
* series of label blk fetches.
*
* \author Stephen Plaza ([email protected])
*/
#include <libdvid/DVIDNodeService.h>
#include <libdvid/DVIDServerService.h>
#include "ScopeTime.h"
#include <iostream>
#include <fstream>
using std::cerr; using std::cout; using std::endl;
using namespace libdvid;
using std::vector;
using std::ifstream;
using std::string;
// assume all blocks are BLK_SIZE in each dimension
int BLK_SIZE = 32;
// size of the segmentation to be created
int VOLDIM = 512;
// number of random fetches to do
int NUM_FETCHES = 100;
// size of the small volume gets
int SMALLFETCH = 128;
/*!
* Exercises the nD GETs and PUTs for the labelblk datatype. Assume input
* binary is VOLDIMxVOLDIMxVOLDIM 64bit numbers compressed with lz4 (example
* in the inputs directory of a segmentation of an EM dataset with 8nm voxels).
*/
int main(int argc, char** argv)
{
if (argc != 3) {
cout << "Usage: <program> <server_name>" << endl;
return -1;
}
try {
ScopeTime overall_time;
DVIDServerService server(argv[1]);
string uuid = server.create_new_repo("newrepo", "This is my new repo");
DVIDNodeService dvid_node(argv[1], uuid);
cout << "Large volume dimension: " << VOLDIM << endl;
cout << "Small volume dimension: " << SMALLFETCH << endl;
string label_datatype_name = "labels1";
// should be a new instance
if(!dvid_node.create_labelblk(label_datatype_name)) {
cerr << label_datatype_name << " already exists" << endl;
return -1;
}
// create binary data string wrapper (64 bits per pixel)
// calculate time to post volume
{
Dims_t dims;
dims.push_back(VOLDIM); dims.push_back(VOLDIM); dims.push_back(VOLDIM);
// read a representative segmentation
ifstream fin(argv[2]);
BinaryDataPtr binary = BinaryData::create_binary_data(fin);
binary = BinaryData::decompress_lz4(binary, VOLDIM*VOLDIM*VOLDIM*sizeof(uint64));
Labels3D labelbin = Labels3D(binary, dims);
vector<int> start;
start.push_back(0); start.push_back(0); start.push_back(0);
ScopeTime post_timer(false);
dvid_node.put_labels3D(label_datatype_name, labelbin, start, true, true);
double post_time = post_timer.getElapsed();
cout << "Time to POST large label volume: " << post_time << " seconds" << endl;
cout << int(VOLDIM * VOLDIM * VOLDIM * sizeof(unsigned long long) / post_time)
<< " bytes posted per second for large label volume" << endl;
}
// retrieve the image volume
// this might be artifically fast as it might be completely in DVID's cache
{
vector<int> start;
start.push_back(0); start.push_back(0); start.push_back(0);
Dims_t lsizes;
lsizes.push_back(VOLDIM); lsizes.push_back(VOLDIM); lsizes.push_back(VOLDIM);
ScopeTime get_timer(false);
Labels3D labelcomp = dvid_node.get_labels3D(label_datatype_name, lsizes, start, true, true);
double read_time = get_timer.getElapsed();
cout << "Time to GET large label volume: " << read_time << " seconds" << endl;
cout << int(VOLDIM * VOLDIM * VOLDIM * sizeof(unsigned long long)/ read_time)
<< " bytes read per second for large label volume" << endl;
}
// do a lot of small requests (like already in DVID cache)
double total_time = 0.0;
for (int i = 0; i < NUM_FETCHES; ++i) {
ScopeTime get_timer(false);
int max_val = VOLDIM - SMALLFETCH + 1;
// grab random small cube
vector<int> start;
start.push_back(rand()%max_val);
start.push_back(rand()%max_val);
start.push_back(rand()%max_val);
vector<unsigned int> lsizes;
lsizes.push_back(SMALLFETCH);
lsizes.push_back(SMALLFETCH);
lsizes.push_back(SMALLFETCH);
Labels3D labelcomp =
dvid_node.get_labels3D(label_datatype_name, lsizes, start, true, true);
double read_time = get_timer.getElapsed();
cout << "Time to GET small label volume: " << read_time << " seconds" << endl;
total_time += read_time;
}
cout << NUM_FETCHES << " fetches performed in " << total_time << " seconds" << endl;
cout << total_time / NUM_FETCHES << " seconds per fetch" << endl;
cout << int(SMALLFETCH * SMALLFETCH * SMALLFETCH * NUM_FETCHES * sizeof(unsigned long long)/ total_time)
<< " bytes read per second" << endl;
} catch (std::exception& e) {
cerr << e.what() << endl;
return -1;
}
return 0;
}