-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathloadtest_tile.cpp
266 lines (201 loc) · 9.03 KB
/
loadtest_tile.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*!
* This file is a DVID load test that simulates a client
* scrolling through several image planes. The program tries
* fetching data 2D slices in tile, grayscale, and labelblk format. Tiles
* should be the fastest and labels the slowest. Note:
* that because DVID typically splits the volume in 32x32x32
* chunks, every 32nd image slice retrieved using the grayscale
* and labelblk interface often results in a higher latency
* call. Users calling this load test should note that the DVID
* database may cache recent requests (running this command twice
* could result in different performance the second time).
*
* \author Stephen Plaza ([email protected])
*/
#include <libdvid/DVIDNodeService.h>
#include <libdvid/DVIDThreadedFetch.h>
#include "ScopeTime.h"
#include "DVIDCache.h"
#include <iostream>
using std::cerr; using std::cout; using std::endl;
using namespace libdvid;
using std::vector;
using std::string;
// assume all blocks are BLK_SIZE in each dimension
int BLK_SIZE = 32;
// number of planes to scroll through
int NUM_FETCHES = 500;
// the size of the tile on DVID
int TILESIZE = 512;
// the size of the window to be fetched
int FETCHSIZE = 1024;
/*!
* Exercises 2D plane access using the nD grayscale and labelblk interface and
* grayscale tiles.
*/
int main(int argc, char** argv)
{
// must point to a DVID instance with tiles (with name tile name) and
// starting voxel coordinates
if (argc != 7 && argc != 8) {
cout << "Usage: <program> <server_name> <uuid> <tilename> <startx> <starty> <startz> <seg: opt>" << endl;
return -1;
}
try {
ScopeTime overall_time;
DVIDCache::get_cache()->set_cache_size(1000000000);
DVIDNodeService dvid_node(argv[1], argv[2]);
// some arithmetic to get tiles aligned to the tile space (indicated
// by TILESIZE)
int xstart = atoi(argv[4]);
int ystart = atoi(argv[5]);
int zstart = atoi(argv[6]);
if (xstart % TILESIZE) {
xstart += (TILESIZE - (xstart % TILESIZE));
}
if (ystart % TILESIZE) {
ystart += (TILESIZE - (ystart % TILESIZE));
}
// make 2D calls in the middle of a block to get a worse-case scenario
int xstartm = xstart + TILESIZE / 2;
int ystartm = ystart + TILESIZE / 2;
cout << "Starting Location: " << xstart << ", " << ystart << ", " << zstart << endl;
string tilename = argv[3];
string segname = "";
if (argc == 8) {
segname = argv[7];
}
cout << "*** Tile Fetching (Single Thread 9 Tiles Per Slice) ***" << endl;
// assuming a 1024x1024 window, 9 tiles could be needed if the window
// is not completely aligned to tile space
vector<int> tilepos;
tilepos.push_back(0);
tilepos.push_back(0);
tilepos.push_back(zstart);
int total_bytes_read = 0;
ScopeTime tiles_timer(false);
// multi-threading might reduce latency further
for (int z = zstart; z < (zstart+NUM_FETCHES); ++z) {
// fetch 9 tiles
ScopeTime tile_timer(false);
tilepos[2] = z;
int bytes_read = 0;
vector<vector<int> > tilepos_array;
tilepos[0] = xstart / TILESIZE;
tilepos[1] = ystart / TILESIZE;
tilepos_array.push_back(tilepos);
tilepos[0] += 1;
tilepos_array.push_back(tilepos);
tilepos[0] += 1;
tilepos_array.push_back(tilepos);
tilepos[0] -= 2;
tilepos[1] += 1;
tilepos_array.push_back(tilepos);
tilepos[0] += 1;
tilepos_array.push_back(tilepos);
tilepos[0] += 1;
tilepos_array.push_back(tilepos);
tilepos[0] -= 2;
tilepos[1] += 1;
tilepos_array.push_back(tilepos);
tilepos[0] += 1;
tilepos_array.push_back(tilepos);
tilepos[0] += 1;
tilepos_array.push_back(tilepos);
vector<BinaryDataPtr> tiles = get_tile_array_binary(dvid_node, tilename, XY, 0, tilepos_array, 0);
for (int i = 0; i < tiles.size(); ++i) {
bytes_read += tiles[i]->length();
}
total_bytes_read += bytes_read;
double read_time = tile_timer.getElapsed();
cout << "Read " << bytes_read << " bytes (9 tiles) in " << read_time << " seconds" << endl;
}
double total_read_time = tiles_timer.getElapsed();
cout << "Read " << total_bytes_read << " bytes (" << NUM_FETCHES << " tile planes) in " << total_read_time << " seconds" << endl;
cout << "Frame rate: " << total_read_time / NUM_FETCHES * 1000 << " milliseconds" << endl;
// with cache
ScopeTime tiles_timer2(false);
for (int z = zstart; z < (zstart+NUM_FETCHES); ++z) {
// fetch 9 tiles
ScopeTime tile_timer(false);
tilepos[2] = z;
int bytes_read = 0;
vector<vector<int> > tilepos_array;
tilepos[0] = xstart / TILESIZE;
tilepos[1] = ystart / TILESIZE;
tilepos_array.push_back(tilepos);
tilepos[0] += 1;
tilepos_array.push_back(tilepos);
tilepos[0] += 1;
tilepos_array.push_back(tilepos);
tilepos[0] -= 2;
tilepos[1] += 1;
tilepos_array.push_back(tilepos);
tilepos[0] += 1;
tilepos_array.push_back(tilepos);
tilepos[0] += 1;
tilepos_array.push_back(tilepos);
tilepos[0] -= 2;
tilepos[1] += 1;
tilepos_array.push_back(tilepos);
tilepos[0] += 1;
tilepos_array.push_back(tilepos);
tilepos[0] += 1;
tilepos_array.push_back(tilepos);
vector<BinaryDataPtr> tiles = get_tile_array_binary(dvid_node, tilename, XY, 0, tilepos_array, 0);
for (int i = 0; i < tiles.size(); ++i) {
bytes_read += tiles[i]->length();
}
total_bytes_read += bytes_read;
double read_time = tile_timer.getElapsed();
cout << "Read " << bytes_read << " bytes (9 tiles) in " << read_time << " seconds" << endl;
}
total_read_time = tiles_timer2.getElapsed();
cout << "Read " << total_bytes_read << " bytes (" << NUM_FETCHES << " tile planes) in " << total_read_time << " seconds" << endl;
cout << "Frame rate: " << total_read_time / NUM_FETCHES * 1000 << " milliseconds" << endl;
//exit(0);
// size for gray and label fetch
vector<int> start;
start.push_back(xstartm); start.push_back(ystartm); start.push_back(zstart);
Dims_t lsizes;
lsizes.push_back(FETCHSIZE); lsizes.push_back(FETCHSIZE); lsizes.push_back(1);
// **************** Segmentation Fetch Time ******************8
if (segname != "") {
int bytes_read = FETCHSIZE * FETCHSIZE * sizeof(uint64);
total_bytes_read = bytes_read * NUM_FETCHES;
ScopeTime label_timer(false);
// retrieve the image volume and make sure it makes the posted volume
for (int z = zstart; z < (zstart+NUM_FETCHES); ++z) {
ScopeTime get_timer(false);
start[2] = z;
Labels3D labelcomp = dvid_node.get_labels3D(segname, lsizes, start, false);
double read_time = get_timer.getElapsed();
cout << "Read " << bytes_read << " bytes in " << read_time << " seconds" << endl;
}
total_read_time = label_timer.getElapsed();
cout << "Read " << total_bytes_read << " bytes (" << NUM_FETCHES << " segmentation "
<< FETCHSIZE << "x" << FETCHSIZE << " planes) in " << total_read_time << " seconds" << endl;
cout << "Frame rate: " << total_read_time / NUM_FETCHES * 1000 << " milliseconds" << endl;
}
// **************** Grayscale Fetch Time ******************8
int bytes_read = FETCHSIZE * FETCHSIZE;
total_bytes_read = bytes_read * NUM_FETCHES;
ScopeTime gray_timer(false);
// retrieve the image volume and make sure it makes the posted volume
for (int z = zstart; z < (zstart+NUM_FETCHES); ++z) {
ScopeTime get_timer(false);
start[2] = z;
Grayscale3D graycomp = dvid_node.get_gray3D("grayscale", lsizes, start, false);
double read_time = get_timer.getElapsed();
cout << "Read " << bytes_read << " bytes in " << read_time << " seconds" << endl;
}
total_read_time = gray_timer.getElapsed();
cout << "Read " << total_bytes_read << " bytes (" << NUM_FETCHES << " grayscale "
<< FETCHSIZE << "x" << FETCHSIZE << " planes) in " << total_read_time << " seconds" << endl;
cout << "Frame rate: " << total_read_time / NUM_FETCHES * 1000 << " milliseconds" << endl;
} catch (std::exception& e) {
cerr << e.what() << endl;
return -1;
}
return 0;
}