|
20 | 20 | #include <sys/stat.h> |
21 | 21 | #include <boost/test/unit_test.hpp> |
22 | 22 | #include <inttypes.h> |
| 23 | +#include <time.h> |
23 | 24 | #include "ds3.h" |
24 | 25 | #include "ds3_net.h" |
25 | 26 | #include "test.h" |
@@ -150,6 +151,10 @@ void put_chunks(void* args) { |
150 | 151 | } |
151 | 152 | } |
152 | 153 |
|
| 154 | +double _timespec_to_seconds(struct timespec* ts) { |
| 155 | + return (double)ts->tv_sec + (double)ts->tv_nsec / 1000000000.0; |
| 156 | +} |
| 157 | + |
153 | 158 | BOOST_AUTO_TEST_CASE( bulk_put_10k_very_small_files ) { |
154 | 159 | printf("-----Testing Bulk PUT of 10k very small files-------\n"); |
155 | 160 | ds3_request* request = NULL; |
@@ -231,7 +236,7 @@ BOOST_AUTO_TEST_CASE( bulk_put_200_very_small_files_multithreaded ) { |
231 | 236 | * Assert no errors are encountered. |
232 | 237 | */ |
233 | 238 | BOOST_AUTO_TEST_CASE( put_large_and_small_objects_concurrently ) { |
234 | | - printf("-----Testing BULK_PUT of large(15mb) & small objects(20bytes) concurrently-------\n"); |
| 239 | + printf("-----Testing BULK_PUT of large(46mb) & small objects(20bytes) concurrently-------\n"); |
235 | 240 |
|
236 | 241 | const char* bucket_name = "test_bulk_put_large_and_small_objects_concurrently"; |
237 | 242 | const char* small_object_name = "resources/very_small_file.txt"; // 20 bytes |
@@ -290,6 +295,105 @@ BOOST_AUTO_TEST_CASE( put_large_and_small_objects_concurrently ) { |
290 | 295 | free_client(client); |
291 | 296 | } |
292 | 297 |
|
| 298 | +BOOST_AUTO_TEST_CASE( sequential_vs_parallel_xfer ) { |
| 299 | + printf("-----Testing BULK_PUT of objects in parallel (4 threads) vs sequentially (1 thread)-------\n"); |
| 300 | + |
| 301 | + const char* sequential_bucket_name = "test_bulk_put_sequential"; |
| 302 | + const char* obj_name = "resources/ulysses_46mb.txt"; |
| 303 | + |
| 304 | + long start_time, end_time, elapsed_sequential, elapsed_parallel; |
| 305 | + struct timespec start_time_t, end_time_t; |
| 306 | + double elapsed_sequential_t, elapsed_parallel_t; |
| 307 | + |
| 308 | + ds3_bulk_object_list_response* obj_list = create_bulk_object_list_single_file(obj_name, 100); |
| 309 | + ds3_client* client = get_client(); |
| 310 | + ds3_master_object_list_response* mol = NULL; |
| 311 | + ds3_request* request = NULL; |
| 312 | + |
| 313 | + |
| 314 | + //*** Start Sequential test config *** |
| 315 | + ds3_error* error = create_bucket_with_data_policy(client, sequential_bucket_name, ids.data_policy_id->value); |
| 316 | + |
| 317 | + request = ds3_init_put_bulk_job_spectra_s3_request(sequential_bucket_name, obj_list); |
| 318 | + error = ds3_put_bulk_job_spectra_s3_request(client, request, &mol); |
| 319 | + ds3_request_free(request); |
| 320 | + handle_error(error); |
| 321 | + |
| 322 | + ds3_master_object_list_response* sequential_chunks = ensure_available_chunks(client, mol->job_id); |
| 323 | + |
| 324 | + GPtrArray* put_sequential_objs_threads_array = new_put_chunks_threads_args(client, obj_name, sequential_bucket_name, mol, sequential_chunks, 1, False); |
| 325 | + |
| 326 | + // capture sequential test start time |
| 327 | + start_time = clock(); |
| 328 | + clock_gettime(CLOCK_MONOTONIC, &start_time_t); |
| 329 | + |
| 330 | + GThread* xfer_sequential_thread = g_thread_new("sequential_objs_xfer", (GThreadFunc)put_chunks, g_ptr_array_index(put_sequential_objs_threads_array, 0)); |
| 331 | + |
| 332 | + // Block and cleanup GThreads |
| 333 | + g_thread_join(xfer_sequential_thread); |
| 334 | + |
| 335 | + // find elapsed CPU and real time |
| 336 | + end_time = clock(); |
| 337 | + clock_gettime(CLOCK_MONOTONIC, &end_time_t); |
| 338 | + elapsed_sequential = (end_time - start_time) / CLOCKS_PER_SEC; |
| 339 | + printf(" Sequential CPU time[%ld]\n", elapsed_sequential); |
| 340 | + elapsed_sequential_t = _timespec_to_seconds(&end_time_t) - _timespec_to_seconds(&start_time_t); |
| 341 | + printf(" Sequential elapsed time[%f]\n", elapsed_sequential_t); |
| 342 | + |
| 343 | + ds3_master_object_list_response_free(sequential_chunks); |
| 344 | + ds3_master_object_list_response_free(mol); |
| 345 | + put_chunks_threads_args_free(put_sequential_objs_threads_array); |
| 346 | + |
| 347 | + clear_bucket(client, sequential_bucket_name); |
| 348 | + |
| 349 | + |
| 350 | + //*** Start Parallel test config *** |
| 351 | + const char* parallel_bucket_name = "test_bulk_put_parallel"; |
| 352 | + |
| 353 | + error = create_bucket_with_data_policy(client, parallel_bucket_name, ids.data_policy_id->value); |
| 354 | + |
| 355 | + request = ds3_init_put_bulk_job_spectra_s3_request(parallel_bucket_name, obj_list); |
| 356 | + error = ds3_put_bulk_job_spectra_s3_request(client, request, &mol); |
| 357 | + ds3_request_free(request); |
| 358 | + handle_error(error); |
| 359 | + |
| 360 | + ds3_master_object_list_response* parallel_chunks = ensure_available_chunks(client, mol->job_id); |
| 361 | + |
| 362 | + GPtrArray* put_parallel_objs_threads_array = new_put_chunks_threads_args(client, obj_name, parallel_bucket_name, mol, parallel_chunks, 4, False); |
| 363 | + |
| 364 | + // capture sequential test start time |
| 365 | + start_time = clock(); |
| 366 | + clock_gettime(CLOCK_MONOTONIC, &start_time_t); |
| 367 | + |
| 368 | + GThread* xfer_parallel_thread_0 = g_thread_new("parallel_objs_xfer", (GThreadFunc)put_chunks, g_ptr_array_index(put_parallel_objs_threads_array, 0)); |
| 369 | + GThread* xfer_parallel_thread_1 = g_thread_new("parallel_objs_xfer", (GThreadFunc)put_chunks, g_ptr_array_index(put_parallel_objs_threads_array, 1)); |
| 370 | + GThread* xfer_parallel_thread_2 = g_thread_new("parallel_objs_xfer", (GThreadFunc)put_chunks, g_ptr_array_index(put_parallel_objs_threads_array, 2)); |
| 371 | + GThread* xfer_parallel_thread_3 = g_thread_new("parallel_objs_xfer", (GThreadFunc)put_chunks, g_ptr_array_index(put_parallel_objs_threads_array, 3)); |
| 372 | + |
| 373 | + // Block and cleanup GThreads |
| 374 | + g_thread_join(xfer_parallel_thread_0); |
| 375 | + g_thread_join(xfer_parallel_thread_1); |
| 376 | + g_thread_join(xfer_parallel_thread_2); |
| 377 | + g_thread_join(xfer_parallel_thread_3); |
| 378 | + |
| 379 | + // find elapsed CPU and real time |
| 380 | + end_time = clock(); |
| 381 | + clock_gettime(CLOCK_MONOTONIC, &end_time_t); |
| 382 | + elapsed_parallel = (end_time - start_time) / CLOCKS_PER_SEC; |
| 383 | + printf(" Parallel CPU time[%ld]\n", elapsed_parallel); |
| 384 | + elapsed_parallel_t = _timespec_to_seconds(&end_time_t) - _timespec_to_seconds(&start_time_t); |
| 385 | + printf(" Parallel elapsed time[%f]\n", elapsed_parallel_t); |
| 386 | + |
| 387 | + ds3_master_object_list_response_free(parallel_chunks); |
| 388 | + ds3_master_object_list_response_free(mol); |
| 389 | + put_chunks_threads_args_free(put_parallel_objs_threads_array); |
| 390 | + |
| 391 | + clear_bucket(client, parallel_bucket_name); |
| 392 | + |
| 393 | + ds3_bulk_object_list_response_free(obj_list); |
| 394 | + free_client(client); |
| 395 | +} |
| 396 | + |
293 | 397 | BOOST_AUTO_TEST_CASE( put_utf_object_name ) { |
294 | 398 | printf("-----Testing PUT object with UTF Characters in name-------\n"); |
295 | 399 |
|
|
0 commit comments