X-Git-Url: http://git.vrable.net/?p=bluesky.git;a=blobdiff_plain;f=cloudbench%2Freaddelay.c;fp=cloudbench%2Freaddelay.c;h=c733e096529c4678a2cd9ccf08e04e6b5631739b;hp=0000000000000000000000000000000000000000;hb=432c0ffa8e2437880a4ed593819881df8c1eaac3;hpb=ed60311f777fe5e2c86d71f2647812050c9bea56 diff --git a/cloudbench/readdelay.c b/cloudbench/readdelay.c new file mode 100644 index 0000000..c733e09 --- /dev/null +++ b/cloudbench/readdelay.c @@ -0,0 +1,122 @@ +/* Simple benchmark for Amazon S3: measures download times to fetch files over + * a single connection, with variable amounts of delay between requests. This + * is intended to test whether the TCP congestion control state gets reset and + * slow start needs to restart, depending on how long the connection was left + * idle. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libs3.h" + +const char *key = NULL; + +S3BucketContext bucket; + +struct callback_state { + //struct thread_state *ts; + size_t bytes_remaining; +}; + +int64_t get_ns() +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + + return ts.tv_sec * 1000000000LL + ts.tv_nsec; +} + +void do_sleep(int64_t delay) +{ + if (delay <= 0) + return; + + struct timespec t; + t.tv_sec = delay / 1000000000; + t.tv_nsec = delay % 1000000000; + nanosleep(&t, NULL); +} + +static S3Status data_callback(int bufferSize, const char *buffer, + void *callbackData) +{ + struct callback_state *state = (struct callback_state *)callbackData; + state->bytes_remaining -= bufferSize; + /* + if (state->ts->first_byte_timestamp == 0) + state->ts->first_byte_timestamp = get_ns(); */ + return S3StatusOK; +} + +static S3Status properties_callback(const S3ResponseProperties *properties, + void *callbackData) +{ + return S3StatusOK; +} + +static void complete_callback(S3Status status, + const S3ErrorDetails *errorDetails, + void *callbackData) +{ +} + +static void do_get(const char *key, size_t bytes) +{ + struct callback_state state; + struct S3GetObjectHandler handler; + + state.bytes_remaining = bytes; + //state.ts = ts; + handler.responseHandler.propertiesCallback = properties_callback; + handler.responseHandler.completeCallback = complete_callback; + handler.getObjectDataCallback = data_callback; + + S3_get_object(&bucket, key, NULL, 0, 0, NULL, &handler, &state); +} + +void run_test(int64_t delay_ns) +{ + for (int i = 0; i <= 25; i++) { + int64_t start, finish; + start = get_ns(); + do_get(key, 0); + finish = get_ns(); + + int64_t elapsed = finish - start; + if (i > 0) { + printf("%f\n", elapsed / 1e9); + fflush(stdout); + } + + do_sleep(delay_ns); + } +} + +int main(int argc, char *argv[]) +{ + S3_initialize(NULL, S3_INIT_ALL); + + bucket.bucketName = "mvrable-benchmark"; + bucket.protocol = S3ProtocolHTTP; + bucket.uriStyle = S3UriStyleVirtualHost; + bucket.accessKeyId = getenv("AWS_ACCESS_KEY_ID"); + bucket.secretAccessKey = getenv("AWS_SECRET_ACCESS_KEY"); + + if (argc != 3) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + key = argv[1]; + double inter_request_delay = atof(argv[2]); + run_test(inter_request_delay * 1e9); + + return 0; +}