Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

multiplicity: update benchmarks

  • Loading branch information...
commit b44ecf99292e9892a5ef89fff19e95958d380dc0 1 parent 8e3a860
@piscisaureus piscisaureus authored
View
16 test/benchmark-ares.c
@@ -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);
View
17 test/benchmark-getaddrinfo.c
@@ -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,7 +60,7 @@ 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);
}
@@ -66,19 +68,20 @@ static void getaddrinfo_initiate(uv_getaddrinfo_t* handle) {
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);
View
14 test/benchmark-ping-pongs.c
@@ -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
25 test/benchmark-pound.c
@@ -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,7 +197,7 @@ 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);
@@ -203,7 +205,7 @@ static void tcp_make_connect(conn_rec* p) {
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();
View
48 test/benchmark-pump.c
@@ -44,6 +44,7 @@ static void req_free(uv_req_t* uv_req);
static uv_buf_t buf_alloc(uv_handle_t*, size_t size);
static void buf_free(uv_buf_t uv_buf_t);
+static uv_loop_t* loop;
static uv_tcp_t tcpServer;
static uv_pipe_t pipeServer;
@@ -97,8 +98,8 @@ static void show_stats(uv_timer_t* handle, int status) {
/* Exit if the show is over */
if (!--stats_left) {
- uv_update_time();
- diff = uv_now() - start_time;
+ uv_update_time(loop);
+ diff = uv_now(loop) - start_time;
LOGF("%s_pump%d_client: %.1f gbit/s\n", type == TCP ? "tcp" : "pipe", write_sockets,
gbit(nsent_total, diff));
@@ -119,8 +120,8 @@ static void show_stats(uv_timer_t* handle, int status) {
static void read_show_stats() {
int64_t diff;
- uv_update_time();
- diff = uv_now() - start_time;
+ uv_update_time(loop);
+ diff = uv_now(loop) - start_time;
LOGF("%s_pump%d_server: %.1f gbit/s\n", type == TCP ? "tcp" : "pipe", max_read_sockets,
gbit(nrecv_total, diff));
@@ -141,7 +142,7 @@ void read_sockets_close_cb(uv_handle_t* handle) {
/* If it's past the first second and everyone has closed their connection
* Then print stats.
*/
- if (uv_now() - start_time > 1000 && read_sockets == 0) {
+ if (uv_now(loop) - start_time > 1000 && read_sockets == 0) {
read_show_stats();
uv_close((uv_handle_t*)server, NULL);
}
@@ -153,21 +154,21 @@ static void start_stats_collection() {
/* Show-stats timer */
stats_left = STATS_COUNT;
- r = uv_timer_init(&timer_handle);
+ r = uv_timer_init(loop, &timer_handle);
ASSERT(r == 0);
r = uv_timer_start(&timer_handle, show_stats, STATS_INTERVAL, STATS_INTERVAL);
ASSERT(r == 0);
- uv_update_time();
- start_time = uv_now();
+ uv_update_time(loop);
+ start_time = uv_now(loop);
}
static void read_cb(uv_stream_t* stream, ssize_t bytes, uv_buf_t buf) {
if (nrecv_total == 0) {
ASSERT(start_time == 0);
- uv_update_time();
- start_time = uv_now();
+ uv_update_time(loop);
+ start_time = uv_now(loop);
}
if (bytes < 0) {
@@ -213,7 +214,7 @@ static void do_write(uv_stream_t* stream) {
static void connect_cb(uv_connect_t* req, int status) {
int i;
- if (status) LOG(uv_strerror(uv_last_error()));
+ if (status) LOG(uv_strerror(uv_last_error(loop)));
ASSERT(status == 0);
write_sockets++;
@@ -243,7 +244,7 @@ static void maybe_connect_some() {
if (type == TCP) {
tcp = &tcp_write_handles[max_connect_socket++];
- r = uv_tcp_init(tcp);
+ r = uv_tcp_init(loop, tcp);
ASSERT(r == 0);
req = (uv_connect_t*) req_alloc();
@@ -252,7 +253,7 @@ static void maybe_connect_some() {
} else {
pipe = &pipe_write_handles[max_connect_socket++];
- r = uv_pipe_init(pipe);
+ r = uv_pipe_init(loop, pipe);
ASSERT(r == 0);
req = (uv_connect_t*) req_alloc();
@@ -272,10 +273,10 @@ static void connection_cb(uv_stream_t* s, int status) {
if (type == TCP) {
stream = (uv_stream_t*)malloc(sizeof(uv_tcp_t));
- uv_tcp_init((uv_tcp_t*)stream);
+ uv_tcp_init(loop, (uv_tcp_t*)stream);
} else {
stream = (uv_stream_t*)malloc(sizeof(uv_pipe_t));
- uv_pipe_init((uv_pipe_t*)stream);
+ uv_pipe_init(loop, (uv_pipe_t*)stream);
}
r = uv_accept(s, stream);
@@ -367,18 +368,20 @@ HELPER_IMPL(tcp_pump_server) {
type = TCP;
uv_init();
+ loop = uv_default_loop();
+
listen_addr = uv_ip4_addr("0.0.0.0", TEST_PORT);
/* Server */
server = (uv_stream_t*)&tcpServer;
- r = uv_tcp_init(&tcpServer);
+ r = uv_tcp_init(loop, &tcpServer);
ASSERT(r == 0);
r = uv_tcp_bind(&tcpServer, listen_addr);
ASSERT(r == 0);
r = uv_listen((uv_stream_t*)&tcpServer, MAX_WRITE_HANDLES, connection_cb);
ASSERT(r == 0);
- uv_run();
+ uv_run(loop);
return 0;
}
@@ -389,17 +392,18 @@ HELPER_IMPL(pipe_pump_server) {
type = PIPE;
uv_init();
+ loop = uv_default_loop();
/* Server */
server = (uv_stream_t*)&pipeServer;
- r = uv_pipe_init(&pipeServer);
+ r = uv_pipe_init(loop, &pipeServer);
ASSERT(r == 0);
r = uv_pipe_bind(&pipeServer, TEST_PIPENAME);
ASSERT(r == 0);
r = uv_listen((uv_stream_t*)&pipeServer, MAX_WRITE_HANDLES, connection_cb);
ASSERT(r == 0);
- uv_run();
+ uv_run(loop);
return 0;
}
@@ -411,13 +415,14 @@ void tcp_pump(int n) {
type = TCP;
uv_init();
+ loop = uv_default_loop();
connect_addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
/* Start making connections */
maybe_connect_some();
- uv_run();
+ uv_run(loop);
}
@@ -427,11 +432,12 @@ void pipe_pump(int n) {
type = PIPE;
uv_init();
+ loop = uv_default_loop();
/* Start making connections */
maybe_connect_some();
- uv_run();
+ uv_run(loop);
}
View
19 test/benchmark-spawn.c
@@ -24,6 +24,8 @@
#include "task.h"
#include "uv.h"
+static uv_loop_t* loop;
+
static int N = 1000;
static int done;
@@ -85,7 +87,7 @@ void pipe_close_cb(uv_handle_t* pipe) {
void on_read(uv_stream_t* pipe, ssize_t nread, uv_buf_t buf) {
- uv_err_t err = uv_last_error();
+ uv_err_t err = uv_last_error(loop);
if (nread > 0) {
ASSERT(pipe_open == 1);
@@ -111,10 +113,10 @@ static void spawn() {
options.args = args;
options.exit_cb = exit_cb;
- uv_pipe_init(&out);
+ uv_pipe_init(loop, &out);
options.stdout_stream = &out;
- r = uv_spawn(&process, options);
+ r = uv_spawn(loop, &process, options);
ASSERT(r == 0);
process_open = 1;
@@ -131,21 +133,22 @@ BENCHMARK_IMPL(spawn) {
static int64_t start_time, end_time;
uv_init();
+ loop = uv_default_loop();
r = uv_exepath(exepath, &exepath_size);
ASSERT(r == 0);
exepath[exepath_size] = '\0';
- uv_update_time();
- start_time = uv_now();
+ uv_update_time(loop);
+ start_time = uv_now(loop);
spawn();
- r = uv_run();
+ r = uv_run(loop);
ASSERT(r == 0);
- uv_update_time();
- end_time = uv_now();
+ uv_update_time(loop);
+ end_time = uv_now(loop);
LOGF("spawn: %.0f spawns/s\n",
(double) N / (double) (end_time - start_time) * 1000.0);
View
15 test/benchmark-udp-packet-storm.c
@@ -37,6 +37,8 @@
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
+static uv_loop_t* loop;
+
static int n_senders_;
static int n_receivers_;
static uv_udp_t senders[MAX_SENDERS];
@@ -91,7 +93,7 @@ static void recv_cb(uv_udp_t* handle,
return;
if (nread == -1) {
- ASSERT(uv_last_error().code == UV_EINTR); /* FIXME change error code */
+ ASSERT(uv_last_error(loop).code == UV_EINTR); /* FIXME change error code */
return;
}
@@ -133,24 +135,25 @@ static int do_packet_storm(int n_senders, int n_receivers) {
ASSERT(n_receivers <= MAX_RECEIVERS);
uv_init();
+ loop = uv_default_loop();
n_senders_ = n_senders;
n_receivers_ = n_receivers;
- r = uv_timer_init(&timeout);
+ r = uv_timer_init(loop, &timeout);
ASSERT(r == 0);
r = uv_timer_start(&timeout, timeout_cb, TEST_DURATION, 0);
ASSERT(r == 0);
/* Timer should not keep loop alive. */
- uv_unref();
+ uv_unref(loop);
for (i = 0; i < n_receivers; i++) {
struct sockaddr_in addr;
handle = &receivers[i];
- r = uv_udp_init(handle);
+ r = uv_udp_init(loop, handle);
ASSERT(r == 0);
addr = uv_ip4_addr("0.0.0.0", BASE_PORT + i);
@@ -171,7 +174,7 @@ static int do_packet_storm(int n_senders, int n_receivers) {
for (i = 0; i < n_senders; i++) {
handle = &senders[i];
- r = uv_udp_init(handle);
+ r = uv_udp_init(loop, handle);
ASSERT(r == 0);
req = malloc(sizeof(*req) + sizeof(*ss));
@@ -185,7 +188,7 @@ static int do_packet_storm(int n_senders, int n_receivers) {
req->data = ss;
}
- uv_run();
+ uv_run(loop);
printf("udp_packet_storm_%dv%d: %.0f/s received, %.0f/s sent\n",
n_receivers,
View
15 test/dns-server.c
@@ -47,6 +47,9 @@ typedef struct {
} dnshandle;
+static uv_loop_t* loop;
+
+
static int server_closed;
static uv_tcp_t server;
@@ -71,7 +74,7 @@ static void after_write(uv_write_t* req, int status) {
write_req_t* wr;
if (status) {
- uv_err_t err = uv_last_error();
+ uv_err_t err = uv_last_error(loop);
fprintf(stderr, "uv_write error: %s\n", uv_strerror(err));
ASSERT(0);
}
@@ -220,7 +223,7 @@ static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
if (nread < 0) {
/* Error or EOF */
- ASSERT (uv_last_error().code == UV_EOF);
+ ASSERT (uv_last_error(loop).code == UV_EOF);
if (buf.base) {
free(buf.base);
@@ -269,7 +272,7 @@ static void on_connection(uv_stream_t* server, int status) {
handle->state.prevbuf_pos = 0;
handle->state.prevbuf_rem = 0;
- uv_tcp_init((uv_tcp_t*)handle);
+ uv_tcp_init(loop, (uv_tcp_t*)handle);
r = uv_accept(server, (uv_stream_t*)handle);
ASSERT(r == 0);
@@ -288,7 +291,7 @@ static int dns_start(int port) {
struct sockaddr_in addr = uv_ip4_addr("0.0.0.0", port);
int r;
- r = uv_tcp_init(&server);
+ r = uv_tcp_init(loop, &server);
if (r) {
/* TODO: Error codes */
fprintf(stderr, "Socket creation error\n");
@@ -315,9 +318,11 @@ static int dns_start(int port) {
HELPER_IMPL(dns_server) {
uv_init();
+ loop = uv_default_loop();
+
if (dns_start(TEST_PORT_2))
return 1;
- uv_run();
+ uv_run(loop);
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.