void setUp(void) { KineticClientConfig clientConfig = { .logFile = "stdout", .logLevel = 1, }; client = KineticClient_Init(&clientConfig); // Create sessions with primary device KineticSessionConfig sessionConfig = { .clusterVersion = 0, .identity = 1, .hmacKey = ByteArray_CreateWithCString(HmacKeyString), }; strncpy(sessionConfig.host, GetSystemTestHost1(), sizeof(sessionConfig.host)-1); sessionConfig.port = GetSystemTestPort1(); KineticStatus status = KineticClient_CreateSession(&sessionConfig, client, &session); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); KineticSessionConfig adminSessionConfig = { .clusterVersion = 0, .identity = 1, .hmacKey = ByteArray_CreateWithCString(HmacKeyString), .useSsl = true, }; strncpy(adminSessionConfig.host, GetSystemTestHost1(), sizeof(adminSessionConfig.host)-1); adminSessionConfig.port = GetSystemTestTlsPort1(); status = KineticAdminClient_CreateSession(&adminSessionConfig, client, &adminSession); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); // Create sessions with peer device
KineticClientConfig clientConfig = { .logFile = "stdout", .logLevel = log_level, }; Fixture = (SystemTestFixture) { .connected = false, .client = KineticClient_Init(&clientConfig), }; KineticSessionConfig config = { .clusterVersion = SESSION_CLUSTER_VERSION, .identity = identity, .hmacKey = ByteArray_Create((void *)key, key_size), }; strncpy((char*)config.host, GetSystemTestHost1(), sizeof(config.host)-1); config.port = GetSystemTestPort1(); strncpy((char*)config.keyData, SESSION_HMAC_KEY, sizeof(config.keyData)-1); KineticStatus status = KineticClient_CreateSession(&config, Fixture.client, &Fixture.session); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); KineticSessionConfig adminConfig = { .clusterVersion = SESSION_CLUSTER_VERSION, .identity = identity, .hmacKey = ByteArray_Create((void *)key, key_size), .useSsl = true, }; strncpy(adminConfig.host, GetSystemTestHost1(), sizeof(adminConfig.host)-1); adminConfig.port = GetSystemTestTlsPort1(); strncpy((char*)adminConfig.keyData, SESSION_HMAC_KEY, sizeof(adminConfig.keyData)-1); status = KineticAdminClient_CreateSession(&adminConfig, Fixture.client, &Fixture.adminSession);
void run_throughput_tests(KineticClient * client, size_t num_ops, size_t value_size) { LOGF0("STRESS THREAD: object_size: %zu bytes, count: %zu entries", value_size, num_ops); // Configure and establish a session with the specified device KineticSession* session; const char HmacKeyString[] = "asdfasdf"; KineticSessionConfig config = { .clusterVersion = 0, .identity = 1, .hmacKey = ByteArray_CreateWithCString(HmacKeyString), }; strncpy(config.host, GetSystemTestHost1(), sizeof(config.host)-1); config.port = GetSystemTestPort1(); KineticStatus status = KineticClient_CreateSession(&config, client, &session); if (status != KINETIC_STATUS_SUCCESS) { char msg[128]; sprintf(msg, "Failed connecting to the Kinetic device w/status: %s", Kinetic_GetStatusDescription(status)); TEST_FAIL_MESSAGE(msg); } // Generate test entry data ByteBuffer test_data = ByteBuffer_Malloc(value_size); ByteBuffer_AppendDummyData(&test_data, test_data.array.len); uint8_t tag_data[] = {0x00, 0x01, 0x02, 0x03}; ByteBuffer tag = ByteBuffer_Create(tag_data, sizeof(tag_data), sizeof(tag_data)); uint64_t r = rand(); uint64_t keys[num_ops]; KineticEntry entries[num_ops]; for (uint32_t put = 0; put < num_ops; put++) { keys[put] = put | (r << 16); } // Measure PUT performance { OpStatus put_statuses[num_ops]; for (size_t i = 0; i < num_ops; i++) { put_statuses[i] = (OpStatus){ .sem = KineticSemaphore_Create(), .status = KINETIC_STATUS_INVALID, }; }; struct timeval start_time; gettimeofday(&start_time, NULL); for (uint32_t put = 0; put < num_ops; put++) { ByteBuffer key = ByteBuffer_Create(&keys[put], sizeof(keys[put]), sizeof(keys[put])); KineticSynchronization sync = (put == num_ops - 1) ? KINETIC_SYNCHRONIZATION_FLUSH : KINETIC_SYNCHRONIZATION_WRITEBACK; entries[put] = (KineticEntry) { .key = key, .tag = tag, .algorithm = KINETIC_ALGORITHM_SHA1, .value = test_data, .synchronization = sync, }; KineticStatus status = KineticClient_Put( session, &entries[put], &(KineticCompletionClosure) { .callback = op_finished, .clientData = &put_statuses[put], } ); if (status != KINETIC_STATUS_SUCCESS) { char msg[128]; sprintf(msg, "PUT failed w/status: %s", Kinetic_GetStatusDescription(status)); TEST_FAIL_MESSAGE(msg); } } for (size_t i = 0; i < num_ops; i++) { KineticSemaphore_WaitForSignalAndDestroy(put_statuses[i].sem); if (put_statuses[i].status != KINETIC_STATUS_SUCCESS) { char msg[128]; sprintf(msg, "PUT failed w/status: %s", Kinetic_GetStatusDescription(put_statuses[i].status)); TEST_FAIL_MESSAGE(msg); } } struct timeval stop_time; gettimeofday(&stop_time, NULL); size_t bytes_written = num_ops * test_data.array.len; int64_t elapsed_us = ((stop_time.tv_sec - start_time.tv_sec) * 1000000) + (stop_time.tv_usec - start_time.tv_usec); float elapsed_ms = elapsed_us / 1000.0f; float bandwidth = (bytes_written * 1000.0f) / (elapsed_ms * 1024 * 1024); LOGF0("PUT Performance: wrote: %.1f kB, duration: %.3f sec, throughput: %.2f MB/sec", bytes_written / 1024.0f, elapsed_ms / 1000.0f, bandwidth); } // Measure GET performance { OpStatus get_statuses[num_ops]; for (size_t i = 0; i < num_ops; i++) { get_statuses[i] = (OpStatus){ .sem = KineticSemaphore_Create(), .status = KINETIC_STATUS_INVALID, }; }; ByteBuffer test_get_datas[num_ops]; for (size_t i = 0; i < num_ops; i++) { test_get_datas[i] = ByteBuffer_Malloc(value_size); } struct timeval start_time; gettimeofday(&start_time, NULL); for (uint32_t get = 0; get < num_ops; get++) { ByteBuffer key = ByteBuffer_Create(&keys[get], sizeof(keys[get]), sizeof(keys[get])); entries[get] = (KineticEntry) { .key = key, .tag = tag, .value = test_get_datas[get], }; KineticStatus status = KineticClient_Get( session, &entries[get], &(KineticCompletionClosure) { .callback = op_finished, .clientData = &get_statuses[get], } ); if (status != KINETIC_STATUS_SUCCESS) { char msg[128]; sprintf(msg, "GET failed w/status: %s", Kinetic_GetStatusDescription(status)); TEST_FAIL_MESSAGE(msg); } } size_t bytes_read = 0; for (size_t i = 0; i < num_ops; i++) { KineticSemaphore_WaitForSignalAndDestroy(get_statuses[i].sem); if (get_statuses[i].status != KINETIC_STATUS_SUCCESS) { char msg[128]; sprintf(msg, "GET failed w/status: %s", Kinetic_GetStatusDescription(get_statuses[i].status)); TEST_FAIL_MESSAGE(msg); } else { bytes_read += entries[i].value.bytesUsed; } } // Check data for integrity size_t numFailures = 0; for (size_t i = 0; i < num_ops; i++) { int res = memcmp(test_data.array.data, test_get_datas[i].array.data, test_data.array.len); if (res != 0) { LOGF0("Failed validating data in object %zu of %zu!", i+1, num_ops); numFailures++; } } TEST_ASSERT_EQUAL_MESSAGE(0, numFailures, "DATA INTEGRITY CHECK FAILED UPON READBACK!"); // Calculate and report performance struct timeval stop_time; gettimeofday(&stop_time, NULL); int64_t elapsed_us = ((stop_time.tv_sec - start_time.tv_sec) * 1000000) + (stop_time.tv_usec - start_time.tv_usec); float elapsed_ms = elapsed_us / 1000.0f; float bandwidth = (bytes_read * 1000.0f) / (elapsed_ms * 1024 * 1024); LOGF0("GET Performance: read: %.1f kB, duration: %.3f sec, throughput: %.2f MB/sec", bytes_read / 1024.0f, elapsed_ms / 1000.0f, bandwidth); for (size_t i = 0; i < num_ops; i++) { ByteBuffer_Free(test_get_datas[i]); } }