Permalink
Browse files

multiplicity: update benchmarks

  • Loading branch information...
piscisaureus committed Aug 31, 2011
1 parent 8e3a860 commit b44ecf99292e9892a5ef89fff19e95958d380dc0
View
@@ -26,6 +26,8 @@
#include <stdio.h>
#include <string.h> /* strlen */
+static uv_loop_t* loop;
+
ares_channel channel;
struct ares_options options;
int optmask;
@@ -67,7 +69,7 @@ static void prep_tcploopback()
options.tcp_port = htons(TEST_PORT_2);
options.flags = ARES_FLAG_USEVC;
- rc = uv_ares_init_options(&channel, &options, optmask);
+ rc = uv_ares_init_options(loop, &channel, &options, optmask);
ASSERT(rc == ARES_SUCCESS);
}
@@ -85,11 +87,13 @@ BENCHMARK_IMPL(gethostbyname) {
}
uv_init();
+ loop = uv_default_loop();
+
ares_callbacks = 0;
ares_errors = 0;
- uv_update_time();
- start_time = uv_now();
+ uv_update_time(loop);
+ start_time = uv_now(loop);
prep_tcploopback();
@@ -101,11 +105,11 @@ BENCHMARK_IMPL(gethostbyname) {
&argument);
}
- uv_run();
+ uv_run(loop);
- uv_ares_destroy(channel);
+ uv_ares_destroy(loop, channel);
- end_time = uv_now();
+ end_time = uv_now(loop);
if (ares_errors > 0) {
printf("There were %d failures\n", ares_errors);
@@ -32,6 +32,8 @@
const char* name = "localhost";
+static uv_loop_t* loop;
+
static uv_getaddrinfo_t handles[CONCURRENT_CALLS];
static int calls_initiated = 0;
@@ -58,27 +60,28 @@ static void getaddrinfo_initiate(uv_getaddrinfo_t* handle) {
calls_initiated++;
- r = uv_getaddrinfo(handle, &getaddrinfo_cb, name, NULL, NULL);
+ r = uv_getaddrinfo(loop, handle, &getaddrinfo_cb, name, NULL, NULL);
ASSERT(r == 0);
}
BENCHMARK_IMPL(getaddrinfo) {
int i;
- uv_init();
+ uv_init(loop);
+ loop = uv_default_loop();
- uv_update_time();
- start_time = uv_now();
+ uv_update_time(loop);
+ start_time = uv_now(loop);
for (i = 0; i < CONCURRENT_CALLS; i++) {
getaddrinfo_initiate(&handles[i]);
}
- uv_run();
+ uv_run(loop);
- uv_update_time();
- end_time = uv_now();
+ uv_update_time(loop);
+ end_time = uv_now(loop);
ASSERT(calls_initiated == TOTAL_CALLS);
ASSERT(calls_completed == TOTAL_CALLS);
@@ -46,6 +46,8 @@ typedef struct buf_s {
static char PING[] = "PING\n";
+static uv_loop_t* loop;
+
static buf_t* buf_freelist = NULL;
static int pinger_shutdown_cb_called;
static int completed_pingers = 0;
@@ -130,7 +132,7 @@ static void pinger_read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
pinger = (pinger_t*)tcp->data;
if (nread < 0) {
- ASSERT(uv_last_error().code == UV_EOF);
+ ASSERT(uv_last_error(loop).code == UV_EOF);
if (buf.base) {
buf_free(buf);
@@ -148,7 +150,7 @@ static void pinger_read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
pinger->state = (pinger->state + 1) % (sizeof(PING) - 1);
if (pinger->state == 0) {
pinger->pongs++;
- if (uv_now() - start_time > TIME) {
+ if (uv_now(loop) - start_time > TIME) {
uv_shutdown(&pinger->shutdown_req, (uv_stream_t*) tcp, pinger_shutdown_cb);
break;
} else {
@@ -185,7 +187,7 @@ static void pinger_new() {
pinger->pongs = 0;
/* Try to connec to the server and do NUM_PINGS ping-pongs. */
- r = uv_tcp_init(&pinger->tcp);
+ r = uv_tcp_init(loop, &pinger->tcp);
ASSERT(!r);
pinger->tcp.data = pinger;
@@ -199,10 +201,12 @@ static void pinger_new() {
BENCHMARK_IMPL(ping_pongs) {
uv_init();
- start_time = uv_now();
+ loop = uv_default_loop();
+
+ start_time = uv_now(loop);
pinger_new();
- uv_run();
+ uv_run(loop);
ASSERT(completed_pingers == 1);
View
@@ -65,6 +65,8 @@ typedef struct {
static char buffer[] = "QS";
+static uv_loop_t* loop;
+
static tcp_conn_rec tcp_conns[MAX_CONNS];
static pipe_conn_rec pipe_conns[MAX_CONNS];
@@ -89,7 +91,7 @@ static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) {
static void after_write(uv_write_t* req, int status) {
if (status != 0) {
- fprintf(stderr, "write error %s\n", uv_err_name(uv_last_error()));
+ fprintf(stderr, "write error %s\n", uv_err_name(uv_last_error(loop)));
uv_close((uv_handle_t*)req->handle, close_cb);
conns_failed++;
return;
@@ -134,7 +136,7 @@ static void connect_cb(uv_connect_t* req, int status) {
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) {
conn_rec* p = (conn_rec*)stream->data;
- uv_err_t err = uv_last_error();
+ uv_err_t err = uv_last_error(loop);
ASSERT(stream != NULL);
@@ -150,7 +152,7 @@ static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) {
} else if (err.code == UV_ECONNRESET) {
conns_failed++;
} else {
- fprintf(stderr, "read error %s\n", uv_err_name(uv_last_error()));
+ fprintf(stderr, "read error %s\n", uv_err_name(uv_last_error(loop)));
ASSERT(0);
}
}
@@ -167,7 +169,7 @@ static void close_cb(uv_handle_t* handle) {
printf("close_cb %d\n", p->i);
#endif
- if (uv_now() - start < 10000) {
+ if (uv_now(loop) - start < 10000) {
p->make_connect(p);
}
}
@@ -195,15 +197,15 @@ static void tcp_make_connect(conn_rec* p) {
struct sockaddr_in addr;
int r;
- r = uv_tcp_init((uv_tcp_t*)&p->stream);
+ r = uv_tcp_init(loop, (uv_tcp_t*)&p->stream);
ASSERT(r == 0);
addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
r = uv_tcp_connect(&((tcp_conn_rec*)p)->conn_req, (uv_tcp_t*)&p->stream, addr, connect_cb);
if (r) {
fprintf(stderr, "uv_tcp_connect error %s\n",
- uv_err_name(uv_last_error()));
+ uv_err_name(uv_last_error(loop)));
ASSERT(0);
}
@@ -220,13 +222,13 @@ static void tcp_make_connect(conn_rec* p) {
static void pipe_make_connect(conn_rec* p) {
int r;
- r = uv_pipe_init((uv_pipe_t*)&p->stream);
+ r = uv_pipe_init(loop, (uv_pipe_t*)&p->stream);
ASSERT(r == 0);
r = uv_pipe_connect(&((pipe_conn_rec*)p)->conn_req, (uv_pipe_t*)&p->stream, TEST_PIPENAME, connect_cb);
if (r) {
fprintf(stderr, "uv_tcp_connect error %s\n",
- uv_err_name(uv_last_error()));
+ uv_err_name(uv_last_error(loop)));
ASSERT(0);
}
@@ -276,9 +278,10 @@ static int pound_it(int concurrency,
uint64_t end_time;
uv_init();
+ loop = uv_default_loop();
- uv_update_time();
- start = uv_now();
+ uv_update_time(loop);
+ start = uv_now(loop);
/* Run benchmark for at least five seconds. */
start_time = uv_hrtime();
@@ -288,7 +291,7 @@ static int pound_it(int concurrency,
r = do_connect(concurrency, make_connect, arg);
ASSERT(!r);
- uv_run();
+ uv_run(loop);
end_time = uv_hrtime();
Oops, something went wrong.

0 comments on commit b44ecf9

Please sign in to comment.