1 /* Blue Sky: File Systems in the Cloud
3 * Copyright (C) 2011 The Regents of the University of California
4 * Written by Michael Vrable <mvrable@cs.ucsd.edu>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 /* Simple benchmark for Amazon S3: measures download times to fetch files over
32 * a single connection, with variable amounts of delay between requests. This
33 * is intended to test whether the TCP congestion control state gets reset and
34 * slow start needs to restart, depending on how long the connection was left
49 const char *key = NULL;
51 S3BucketContext bucket;
53 struct callback_state {
54 //struct thread_state *ts;
55 size_t bytes_remaining;
61 clock_gettime(CLOCK_MONOTONIC, &ts);
63 return ts.tv_sec * 1000000000LL + ts.tv_nsec;
66 void do_sleep(int64_t delay)
72 t.tv_sec = delay / 1000000000;
73 t.tv_nsec = delay % 1000000000;
77 static S3Status data_callback(int bufferSize, const char *buffer,
80 struct callback_state *state = (struct callback_state *)callbackData;
81 state->bytes_remaining -= bufferSize;
83 if (state->ts->first_byte_timestamp == 0)
84 state->ts->first_byte_timestamp = get_ns(); */
88 static S3Status properties_callback(const S3ResponseProperties *properties,
94 static void complete_callback(S3Status status,
95 const S3ErrorDetails *errorDetails,
100 static void do_get(const char *key, size_t bytes)
102 struct callback_state state;
103 struct S3GetObjectHandler handler;
105 state.bytes_remaining = bytes;
107 handler.responseHandler.propertiesCallback = properties_callback;
108 handler.responseHandler.completeCallback = complete_callback;
109 handler.getObjectDataCallback = data_callback;
111 S3_get_object(&bucket, key, NULL, 0, 0, NULL, &handler, &state);
114 void run_test(int64_t delay_ns)
116 for (int i = 0; i <= 25; i++) {
117 int64_t start, finish;
122 int64_t elapsed = finish - start;
124 printf("%f\n", elapsed / 1e9);
132 int main(int argc, char *argv[])
134 S3_initialize(NULL, S3_INIT_ALL, NULL);
136 bucket.bucketName = "mvrable-benchmark";
137 bucket.protocol = S3ProtocolHTTP;
138 bucket.uriStyle = S3UriStyleVirtualHost;
139 bucket.accessKeyId = getenv("AWS_ACCESS_KEY_ID");
140 bucket.secretAccessKey = getenv("AWS_SECRET_ACCESS_KEY");
143 fprintf(stderr, "Usage: %s <file> <delay>\n", argv[0]);
148 double inter_request_delay = atof(argv[2]);
149 run_test(inter_request_delay * 1e9);