1 /* Simple benchmark for Amazon S3: measures download times to fetch files over
2 * a single connection, with variable amounts of delay between requests. This
3 * is intended to test whether the TCP congestion control state gets reset and
4 * slow start needs to restart, depending on how long the connection was left
19 const char *key = NULL;
21 S3BucketContext bucket;
23 struct callback_state {
24 //struct thread_state *ts;
25 size_t bytes_remaining;
31 clock_gettime(CLOCK_MONOTONIC, &ts);
33 return ts.tv_sec * 1000000000LL + ts.tv_nsec;
36 void do_sleep(int64_t delay)
42 t.tv_sec = delay / 1000000000;
43 t.tv_nsec = delay % 1000000000;
47 static S3Status data_callback(int bufferSize, const char *buffer,
50 struct callback_state *state = (struct callback_state *)callbackData;
51 state->bytes_remaining -= bufferSize;
53 if (state->ts->first_byte_timestamp == 0)
54 state->ts->first_byte_timestamp = get_ns(); */
58 static S3Status properties_callback(const S3ResponseProperties *properties,
64 static void complete_callback(S3Status status,
65 const S3ErrorDetails *errorDetails,
70 static void do_get(const char *key, size_t bytes)
72 struct callback_state state;
73 struct S3GetObjectHandler handler;
75 state.bytes_remaining = bytes;
77 handler.responseHandler.propertiesCallback = properties_callback;
78 handler.responseHandler.completeCallback = complete_callback;
79 handler.getObjectDataCallback = data_callback;
81 S3_get_object(&bucket, key, NULL, 0, 0, NULL, &handler, &state);
84 void run_test(int64_t delay_ns)
86 for (int i = 0; i <= 25; i++) {
87 int64_t start, finish;
92 int64_t elapsed = finish - start;
94 printf("%f\n", elapsed / 1e9);
102 int main(int argc, char *argv[])
104 S3_initialize(NULL, S3_INIT_ALL);
106 bucket.bucketName = "mvrable-benchmark";
107 bucket.protocol = S3ProtocolHTTP;
108 bucket.uriStyle = S3UriStyleVirtualHost;
109 bucket.accessKeyId = getenv("AWS_ACCESS_KEY_ID");
110 bucket.secretAccessKey = getenv("AWS_SECRET_ACCESS_KEY");
113 fprintf(stderr, "Usage: %s <file> <delay>\n", argv[0]);
118 double inter_request_delay = atof(argv[2]);
119 run_test(inter_request_delay * 1e9);