multiplicity: update benchmarks
This commit is contained in:
parent
8e3a8602ad
commit
b44ecf9929
@ -26,6 +26,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h> /* strlen */
|
#include <string.h> /* strlen */
|
||||||
|
|
||||||
|
static uv_loop_t* loop;
|
||||||
|
|
||||||
ares_channel channel;
|
ares_channel channel;
|
||||||
struct ares_options options;
|
struct ares_options options;
|
||||||
int optmask;
|
int optmask;
|
||||||
@ -67,7 +69,7 @@ static void prep_tcploopback()
|
|||||||
options.tcp_port = htons(TEST_PORT_2);
|
options.tcp_port = htons(TEST_PORT_2);
|
||||||
options.flags = ARES_FLAG_USEVC;
|
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);
|
ASSERT(rc == ARES_SUCCESS);
|
||||||
}
|
}
|
||||||
@ -85,11 +87,13 @@ BENCHMARK_IMPL(gethostbyname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uv_init();
|
uv_init();
|
||||||
|
loop = uv_default_loop();
|
||||||
|
|
||||||
ares_callbacks = 0;
|
ares_callbacks = 0;
|
||||||
ares_errors = 0;
|
ares_errors = 0;
|
||||||
|
|
||||||
uv_update_time();
|
uv_update_time(loop);
|
||||||
start_time = uv_now();
|
start_time = uv_now(loop);
|
||||||
|
|
||||||
prep_tcploopback();
|
prep_tcploopback();
|
||||||
|
|
||||||
@ -101,11 +105,11 @@ BENCHMARK_IMPL(gethostbyname) {
|
|||||||
&argument);
|
&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) {
|
if (ares_errors > 0) {
|
||||||
printf("There were %d failures\n", ares_errors);
|
printf("There were %d failures\n", ares_errors);
|
||||||
|
|||||||
@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
const char* name = "localhost";
|
const char* name = "localhost";
|
||||||
|
|
||||||
|
static uv_loop_t* loop;
|
||||||
|
|
||||||
static uv_getaddrinfo_t handles[CONCURRENT_CALLS];
|
static uv_getaddrinfo_t handles[CONCURRENT_CALLS];
|
||||||
|
|
||||||
static int calls_initiated = 0;
|
static int calls_initiated = 0;
|
||||||
@ -58,7 +60,7 @@ static void getaddrinfo_initiate(uv_getaddrinfo_t* handle) {
|
|||||||
|
|
||||||
calls_initiated++;
|
calls_initiated++;
|
||||||
|
|
||||||
r = uv_getaddrinfo(handle, &getaddrinfo_cb, name, NULL, NULL);
|
r = uv_getaddrinfo(loop, handle, &getaddrinfo_cb, name, NULL, NULL);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,19 +68,20 @@ static void getaddrinfo_initiate(uv_getaddrinfo_t* handle) {
|
|||||||
BENCHMARK_IMPL(getaddrinfo) {
|
BENCHMARK_IMPL(getaddrinfo) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
uv_init();
|
uv_init(loop);
|
||||||
|
loop = uv_default_loop();
|
||||||
|
|
||||||
uv_update_time();
|
uv_update_time(loop);
|
||||||
start_time = uv_now();
|
start_time = uv_now(loop);
|
||||||
|
|
||||||
for (i = 0; i < CONCURRENT_CALLS; i++) {
|
for (i = 0; i < CONCURRENT_CALLS; i++) {
|
||||||
getaddrinfo_initiate(&handles[i]);
|
getaddrinfo_initiate(&handles[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
uv_run();
|
uv_run(loop);
|
||||||
|
|
||||||
uv_update_time();
|
uv_update_time(loop);
|
||||||
end_time = uv_now();
|
end_time = uv_now(loop);
|
||||||
|
|
||||||
ASSERT(calls_initiated == TOTAL_CALLS);
|
ASSERT(calls_initiated == TOTAL_CALLS);
|
||||||
ASSERT(calls_completed == TOTAL_CALLS);
|
ASSERT(calls_completed == TOTAL_CALLS);
|
||||||
|
|||||||
@ -46,6 +46,8 @@ typedef struct buf_s {
|
|||||||
|
|
||||||
static char PING[] = "PING\n";
|
static char PING[] = "PING\n";
|
||||||
|
|
||||||
|
static uv_loop_t* loop;
|
||||||
|
|
||||||
static buf_t* buf_freelist = NULL;
|
static buf_t* buf_freelist = NULL;
|
||||||
static int pinger_shutdown_cb_called;
|
static int pinger_shutdown_cb_called;
|
||||||
static int completed_pingers = 0;
|
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;
|
pinger = (pinger_t*)tcp->data;
|
||||||
|
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
ASSERT(uv_last_error().code == UV_EOF);
|
ASSERT(uv_last_error(loop).code == UV_EOF);
|
||||||
|
|
||||||
if (buf.base) {
|
if (buf.base) {
|
||||||
buf_free(buf);
|
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);
|
pinger->state = (pinger->state + 1) % (sizeof(PING) - 1);
|
||||||
if (pinger->state == 0) {
|
if (pinger->state == 0) {
|
||||||
pinger->pongs++;
|
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);
|
uv_shutdown(&pinger->shutdown_req, (uv_stream_t*) tcp, pinger_shutdown_cb);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@ -185,7 +187,7 @@ static void pinger_new() {
|
|||||||
pinger->pongs = 0;
|
pinger->pongs = 0;
|
||||||
|
|
||||||
/* Try to connec to the server and do NUM_PINGS ping-pongs. */
|
/* 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);
|
ASSERT(!r);
|
||||||
|
|
||||||
pinger->tcp.data = pinger;
|
pinger->tcp.data = pinger;
|
||||||
@ -199,10 +201,12 @@ static void pinger_new() {
|
|||||||
|
|
||||||
BENCHMARK_IMPL(ping_pongs) {
|
BENCHMARK_IMPL(ping_pongs) {
|
||||||
uv_init();
|
uv_init();
|
||||||
start_time = uv_now();
|
loop = uv_default_loop();
|
||||||
|
|
||||||
|
start_time = uv_now(loop);
|
||||||
|
|
||||||
pinger_new();
|
pinger_new();
|
||||||
uv_run();
|
uv_run(loop);
|
||||||
|
|
||||||
ASSERT(completed_pingers == 1);
|
ASSERT(completed_pingers == 1);
|
||||||
|
|
||||||
|
|||||||
@ -65,6 +65,8 @@ typedef struct {
|
|||||||
|
|
||||||
static char buffer[] = "QS";
|
static char buffer[] = "QS";
|
||||||
|
|
||||||
|
static uv_loop_t* loop;
|
||||||
|
|
||||||
static tcp_conn_rec tcp_conns[MAX_CONNS];
|
static tcp_conn_rec tcp_conns[MAX_CONNS];
|
||||||
static pipe_conn_rec pipe_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) {
|
static void after_write(uv_write_t* req, int status) {
|
||||||
if (status != 0) {
|
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);
|
uv_close((uv_handle_t*)req->handle, close_cb);
|
||||||
conns_failed++;
|
conns_failed++;
|
||||||
return;
|
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) {
|
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) {
|
||||||
conn_rec* p = (conn_rec*)stream->data;
|
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);
|
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) {
|
} else if (err.code == UV_ECONNRESET) {
|
||||||
conns_failed++;
|
conns_failed++;
|
||||||
} else {
|
} 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);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,7 +169,7 @@ static void close_cb(uv_handle_t* handle) {
|
|||||||
printf("close_cb %d\n", p->i);
|
printf("close_cb %d\n", p->i);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (uv_now() - start < 10000) {
|
if (uv_now(loop) - start < 10000) {
|
||||||
p->make_connect(p);
|
p->make_connect(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,7 +197,7 @@ static void tcp_make_connect(conn_rec* p) {
|
|||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = uv_tcp_init((uv_tcp_t*)&p->stream);
|
r = uv_tcp_init(loop, (uv_tcp_t*)&p->stream);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
|
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);
|
r = uv_tcp_connect(&((tcp_conn_rec*)p)->conn_req, (uv_tcp_t*)&p->stream, addr, connect_cb);
|
||||||
if (r) {
|
if (r) {
|
||||||
fprintf(stderr, "uv_tcp_connect error %s\n",
|
fprintf(stderr, "uv_tcp_connect error %s\n",
|
||||||
uv_err_name(uv_last_error()));
|
uv_err_name(uv_last_error(loop)));
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,13 +222,13 @@ static void tcp_make_connect(conn_rec* p) {
|
|||||||
static void pipe_make_connect(conn_rec* p) {
|
static void pipe_make_connect(conn_rec* p) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = uv_pipe_init((uv_pipe_t*)&p->stream);
|
r = uv_pipe_init(loop, (uv_pipe_t*)&p->stream);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
r = uv_pipe_connect(&((pipe_conn_rec*)p)->conn_req, (uv_pipe_t*)&p->stream, TEST_PIPENAME, connect_cb);
|
r = uv_pipe_connect(&((pipe_conn_rec*)p)->conn_req, (uv_pipe_t*)&p->stream, TEST_PIPENAME, connect_cb);
|
||||||
if (r) {
|
if (r) {
|
||||||
fprintf(stderr, "uv_tcp_connect error %s\n",
|
fprintf(stderr, "uv_tcp_connect error %s\n",
|
||||||
uv_err_name(uv_last_error()));
|
uv_err_name(uv_last_error(loop)));
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,9 +278,10 @@ static int pound_it(int concurrency,
|
|||||||
uint64_t end_time;
|
uint64_t end_time;
|
||||||
|
|
||||||
uv_init();
|
uv_init();
|
||||||
|
loop = uv_default_loop();
|
||||||
|
|
||||||
uv_update_time();
|
uv_update_time(loop);
|
||||||
start = uv_now();
|
start = uv_now(loop);
|
||||||
|
|
||||||
/* Run benchmark for at least five seconds. */
|
/* Run benchmark for at least five seconds. */
|
||||||
start_time = uv_hrtime();
|
start_time = uv_hrtime();
|
||||||
@ -288,7 +291,7 @@ static int pound_it(int concurrency,
|
|||||||
r = do_connect(concurrency, make_connect, arg);
|
r = do_connect(concurrency, make_connect, arg);
|
||||||
ASSERT(!r);
|
ASSERT(!r);
|
||||||
|
|
||||||
uv_run();
|
uv_run(loop);
|
||||||
|
|
||||||
end_time = uv_hrtime();
|
end_time = uv_hrtime();
|
||||||
|
|
||||||
|
|||||||
@ -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 uv_buf_t buf_alloc(uv_handle_t*, size_t size);
|
||||||
static void buf_free(uv_buf_t uv_buf_t);
|
static void buf_free(uv_buf_t uv_buf_t);
|
||||||
|
|
||||||
|
static uv_loop_t* loop;
|
||||||
|
|
||||||
static uv_tcp_t tcpServer;
|
static uv_tcp_t tcpServer;
|
||||||
static uv_pipe_t pipeServer;
|
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 */
|
/* Exit if the show is over */
|
||||||
if (!--stats_left) {
|
if (!--stats_left) {
|
||||||
|
|
||||||
uv_update_time();
|
uv_update_time(loop);
|
||||||
diff = uv_now() - start_time;
|
diff = uv_now(loop) - start_time;
|
||||||
|
|
||||||
LOGF("%s_pump%d_client: %.1f gbit/s\n", type == TCP ? "tcp" : "pipe", write_sockets,
|
LOGF("%s_pump%d_client: %.1f gbit/s\n", type == TCP ? "tcp" : "pipe", write_sockets,
|
||||||
gbit(nsent_total, diff));
|
gbit(nsent_total, diff));
|
||||||
@ -119,8 +120,8 @@ static void show_stats(uv_timer_t* handle, int status) {
|
|||||||
static void read_show_stats() {
|
static void read_show_stats() {
|
||||||
int64_t diff;
|
int64_t diff;
|
||||||
|
|
||||||
uv_update_time();
|
uv_update_time(loop);
|
||||||
diff = uv_now() - start_time;
|
diff = uv_now(loop) - start_time;
|
||||||
|
|
||||||
LOGF("%s_pump%d_server: %.1f gbit/s\n", type == TCP ? "tcp" : "pipe", max_read_sockets,
|
LOGF("%s_pump%d_server: %.1f gbit/s\n", type == TCP ? "tcp" : "pipe", max_read_sockets,
|
||||||
gbit(nrecv_total, diff));
|
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
|
/* If it's past the first second and everyone has closed their connection
|
||||||
* Then print stats.
|
* 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();
|
read_show_stats();
|
||||||
uv_close((uv_handle_t*)server, NULL);
|
uv_close((uv_handle_t*)server, NULL);
|
||||||
}
|
}
|
||||||
@ -153,21 +154,21 @@ static void start_stats_collection() {
|
|||||||
|
|
||||||
/* Show-stats timer */
|
/* Show-stats timer */
|
||||||
stats_left = STATS_COUNT;
|
stats_left = STATS_COUNT;
|
||||||
r = uv_timer_init(&timer_handle);
|
r = uv_timer_init(loop, &timer_handle);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
r = uv_timer_start(&timer_handle, show_stats, STATS_INTERVAL, STATS_INTERVAL);
|
r = uv_timer_start(&timer_handle, show_stats, STATS_INTERVAL, STATS_INTERVAL);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
uv_update_time();
|
uv_update_time(loop);
|
||||||
start_time = uv_now();
|
start_time = uv_now(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void read_cb(uv_stream_t* stream, ssize_t bytes, uv_buf_t buf) {
|
static void read_cb(uv_stream_t* stream, ssize_t bytes, uv_buf_t buf) {
|
||||||
if (nrecv_total == 0) {
|
if (nrecv_total == 0) {
|
||||||
ASSERT(start_time == 0);
|
ASSERT(start_time == 0);
|
||||||
uv_update_time();
|
uv_update_time(loop);
|
||||||
start_time = uv_now();
|
start_time = uv_now(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes < 0) {
|
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) {
|
static void connect_cb(uv_connect_t* req, int status) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (status) LOG(uv_strerror(uv_last_error()));
|
if (status) LOG(uv_strerror(uv_last_error(loop)));
|
||||||
ASSERT(status == 0);
|
ASSERT(status == 0);
|
||||||
|
|
||||||
write_sockets++;
|
write_sockets++;
|
||||||
@ -243,7 +244,7 @@ static void maybe_connect_some() {
|
|||||||
if (type == TCP) {
|
if (type == TCP) {
|
||||||
tcp = &tcp_write_handles[max_connect_socket++];
|
tcp = &tcp_write_handles[max_connect_socket++];
|
||||||
|
|
||||||
r = uv_tcp_init(tcp);
|
r = uv_tcp_init(loop, tcp);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
req = (uv_connect_t*) req_alloc();
|
req = (uv_connect_t*) req_alloc();
|
||||||
@ -252,7 +253,7 @@ static void maybe_connect_some() {
|
|||||||
} else {
|
} else {
|
||||||
pipe = &pipe_write_handles[max_connect_socket++];
|
pipe = &pipe_write_handles[max_connect_socket++];
|
||||||
|
|
||||||
r = uv_pipe_init(pipe);
|
r = uv_pipe_init(loop, pipe);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
req = (uv_connect_t*) req_alloc();
|
req = (uv_connect_t*) req_alloc();
|
||||||
@ -272,10 +273,10 @@ static void connection_cb(uv_stream_t* s, int status) {
|
|||||||
|
|
||||||
if (type == TCP) {
|
if (type == TCP) {
|
||||||
stream = (uv_stream_t*)malloc(sizeof(uv_tcp_t));
|
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 {
|
} else {
|
||||||
stream = (uv_stream_t*)malloc(sizeof(uv_pipe_t));
|
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);
|
r = uv_accept(s, stream);
|
||||||
@ -367,18 +368,20 @@ HELPER_IMPL(tcp_pump_server) {
|
|||||||
|
|
||||||
type = TCP;
|
type = TCP;
|
||||||
uv_init();
|
uv_init();
|
||||||
|
loop = uv_default_loop();
|
||||||
|
|
||||||
listen_addr = uv_ip4_addr("0.0.0.0", TEST_PORT);
|
listen_addr = uv_ip4_addr("0.0.0.0", TEST_PORT);
|
||||||
|
|
||||||
/* Server */
|
/* Server */
|
||||||
server = (uv_stream_t*)&tcpServer;
|
server = (uv_stream_t*)&tcpServer;
|
||||||
r = uv_tcp_init(&tcpServer);
|
r = uv_tcp_init(loop, &tcpServer);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
r = uv_tcp_bind(&tcpServer, listen_addr);
|
r = uv_tcp_bind(&tcpServer, listen_addr);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
r = uv_listen((uv_stream_t*)&tcpServer, MAX_WRITE_HANDLES, connection_cb);
|
r = uv_listen((uv_stream_t*)&tcpServer, MAX_WRITE_HANDLES, connection_cb);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
uv_run();
|
uv_run(loop);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -389,17 +392,18 @@ HELPER_IMPL(pipe_pump_server) {
|
|||||||
type = PIPE;
|
type = PIPE;
|
||||||
|
|
||||||
uv_init();
|
uv_init();
|
||||||
|
loop = uv_default_loop();
|
||||||
|
|
||||||
/* Server */
|
/* Server */
|
||||||
server = (uv_stream_t*)&pipeServer;
|
server = (uv_stream_t*)&pipeServer;
|
||||||
r = uv_pipe_init(&pipeServer);
|
r = uv_pipe_init(loop, &pipeServer);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
r = uv_pipe_bind(&pipeServer, TEST_PIPENAME);
|
r = uv_pipe_bind(&pipeServer, TEST_PIPENAME);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
r = uv_listen((uv_stream_t*)&pipeServer, MAX_WRITE_HANDLES, connection_cb);
|
r = uv_listen((uv_stream_t*)&pipeServer, MAX_WRITE_HANDLES, connection_cb);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
uv_run();
|
uv_run(loop);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -411,13 +415,14 @@ void tcp_pump(int n) {
|
|||||||
type = TCP;
|
type = TCP;
|
||||||
|
|
||||||
uv_init();
|
uv_init();
|
||||||
|
loop = uv_default_loop();
|
||||||
|
|
||||||
connect_addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
|
connect_addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
|
||||||
|
|
||||||
/* Start making connections */
|
/* Start making connections */
|
||||||
maybe_connect_some();
|
maybe_connect_some();
|
||||||
|
|
||||||
uv_run();
|
uv_run(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -427,11 +432,12 @@ void pipe_pump(int n) {
|
|||||||
type = PIPE;
|
type = PIPE;
|
||||||
|
|
||||||
uv_init();
|
uv_init();
|
||||||
|
loop = uv_default_loop();
|
||||||
|
|
||||||
/* Start making connections */
|
/* Start making connections */
|
||||||
maybe_connect_some();
|
maybe_connect_some();
|
||||||
|
|
||||||
uv_run();
|
uv_run(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -24,6 +24,8 @@
|
|||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "uv.h"
|
#include "uv.h"
|
||||||
|
|
||||||
|
static uv_loop_t* loop;
|
||||||
|
|
||||||
static int N = 1000;
|
static int N = 1000;
|
||||||
static int done;
|
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) {
|
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) {
|
if (nread > 0) {
|
||||||
ASSERT(pipe_open == 1);
|
ASSERT(pipe_open == 1);
|
||||||
@ -111,10 +113,10 @@ static void spawn() {
|
|||||||
options.args = args;
|
options.args = args;
|
||||||
options.exit_cb = exit_cb;
|
options.exit_cb = exit_cb;
|
||||||
|
|
||||||
uv_pipe_init(&out);
|
uv_pipe_init(loop, &out);
|
||||||
options.stdout_stream = &out;
|
options.stdout_stream = &out;
|
||||||
|
|
||||||
r = uv_spawn(&process, options);
|
r = uv_spawn(loop, &process, options);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
process_open = 1;
|
process_open = 1;
|
||||||
@ -131,21 +133,22 @@ BENCHMARK_IMPL(spawn) {
|
|||||||
static int64_t start_time, end_time;
|
static int64_t start_time, end_time;
|
||||||
|
|
||||||
uv_init();
|
uv_init();
|
||||||
|
loop = uv_default_loop();
|
||||||
|
|
||||||
r = uv_exepath(exepath, &exepath_size);
|
r = uv_exepath(exepath, &exepath_size);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
exepath[exepath_size] = '\0';
|
exepath[exepath_size] = '\0';
|
||||||
|
|
||||||
uv_update_time();
|
uv_update_time(loop);
|
||||||
start_time = uv_now();
|
start_time = uv_now(loop);
|
||||||
|
|
||||||
spawn();
|
spawn();
|
||||||
|
|
||||||
r = uv_run();
|
r = uv_run(loop);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
uv_update_time();
|
uv_update_time(loop);
|
||||||
end_time = uv_now();
|
end_time = uv_now(loop);
|
||||||
|
|
||||||
LOGF("spawn: %.0f spawns/s\n",
|
LOGF("spawn: %.0f spawns/s\n",
|
||||||
(double) N / (double) (end_time - start_time) * 1000.0);
|
(double) N / (double) (end_time - start_time) * 1000.0);
|
||||||
|
|||||||
@ -37,6 +37,8 @@
|
|||||||
|
|
||||||
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
|
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
|
||||||
|
|
||||||
|
static uv_loop_t* loop;
|
||||||
|
|
||||||
static int n_senders_;
|
static int n_senders_;
|
||||||
static int n_receivers_;
|
static int n_receivers_;
|
||||||
static uv_udp_t senders[MAX_SENDERS];
|
static uv_udp_t senders[MAX_SENDERS];
|
||||||
@ -91,7 +93,7 @@ static void recv_cb(uv_udp_t* handle,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (nread == -1) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,24 +135,25 @@ static int do_packet_storm(int n_senders, int n_receivers) {
|
|||||||
ASSERT(n_receivers <= MAX_RECEIVERS);
|
ASSERT(n_receivers <= MAX_RECEIVERS);
|
||||||
|
|
||||||
uv_init();
|
uv_init();
|
||||||
|
loop = uv_default_loop();
|
||||||
|
|
||||||
n_senders_ = n_senders;
|
n_senders_ = n_senders;
|
||||||
n_receivers_ = n_receivers;
|
n_receivers_ = n_receivers;
|
||||||
|
|
||||||
r = uv_timer_init(&timeout);
|
r = uv_timer_init(loop, &timeout);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
r = uv_timer_start(&timeout, timeout_cb, TEST_DURATION, 0);
|
r = uv_timer_start(&timeout, timeout_cb, TEST_DURATION, 0);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
/* Timer should not keep loop alive. */
|
/* Timer should not keep loop alive. */
|
||||||
uv_unref();
|
uv_unref(loop);
|
||||||
|
|
||||||
for (i = 0; i < n_receivers; i++) {
|
for (i = 0; i < n_receivers; i++) {
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
handle = &receivers[i];
|
handle = &receivers[i];
|
||||||
|
|
||||||
r = uv_udp_init(handle);
|
r = uv_udp_init(loop, handle);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
addr = uv_ip4_addr("0.0.0.0", BASE_PORT + i);
|
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++) {
|
for (i = 0; i < n_senders; i++) {
|
||||||
handle = &senders[i];
|
handle = &senders[i];
|
||||||
|
|
||||||
r = uv_udp_init(handle);
|
r = uv_udp_init(loop, handle);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
req = malloc(sizeof(*req) + sizeof(*ss));
|
req = malloc(sizeof(*req) + sizeof(*ss));
|
||||||
@ -185,7 +188,7 @@ static int do_packet_storm(int n_senders, int n_receivers) {
|
|||||||
req->data = ss;
|
req->data = ss;
|
||||||
}
|
}
|
||||||
|
|
||||||
uv_run();
|
uv_run(loop);
|
||||||
|
|
||||||
printf("udp_packet_storm_%dv%d: %.0f/s received, %.0f/s sent\n",
|
printf("udp_packet_storm_%dv%d: %.0f/s received, %.0f/s sent\n",
|
||||||
n_receivers,
|
n_receivers,
|
||||||
|
|||||||
@ -47,6 +47,9 @@ typedef struct {
|
|||||||
} dnshandle;
|
} dnshandle;
|
||||||
|
|
||||||
|
|
||||||
|
static uv_loop_t* loop;
|
||||||
|
|
||||||
|
|
||||||
static int server_closed;
|
static int server_closed;
|
||||||
static uv_tcp_t server;
|
static uv_tcp_t server;
|
||||||
|
|
||||||
@ -71,7 +74,7 @@ static void after_write(uv_write_t* req, int status) {
|
|||||||
write_req_t* wr;
|
write_req_t* wr;
|
||||||
|
|
||||||
if (status) {
|
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));
|
fprintf(stderr, "uv_write error: %s\n", uv_strerror(err));
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
@ -220,7 +223,7 @@ static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
|
|||||||
|
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
/* Error or EOF */
|
/* Error or EOF */
|
||||||
ASSERT (uv_last_error().code == UV_EOF);
|
ASSERT (uv_last_error(loop).code == UV_EOF);
|
||||||
|
|
||||||
if (buf.base) {
|
if (buf.base) {
|
||||||
free(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_pos = 0;
|
||||||
handle->state.prevbuf_rem = 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);
|
r = uv_accept(server, (uv_stream_t*)handle);
|
||||||
ASSERT(r == 0);
|
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);
|
struct sockaddr_in addr = uv_ip4_addr("0.0.0.0", port);
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = uv_tcp_init(&server);
|
r = uv_tcp_init(loop, &server);
|
||||||
if (r) {
|
if (r) {
|
||||||
/* TODO: Error codes */
|
/* TODO: Error codes */
|
||||||
fprintf(stderr, "Socket creation error\n");
|
fprintf(stderr, "Socket creation error\n");
|
||||||
@ -315,9 +318,11 @@ static int dns_start(int port) {
|
|||||||
|
|
||||||
HELPER_IMPL(dns_server) {
|
HELPER_IMPL(dns_server) {
|
||||||
uv_init();
|
uv_init();
|
||||||
|
loop = uv_default_loop();
|
||||||
|
|
||||||
if (dns_start(TEST_PORT_2))
|
if (dns_start(TEST_PORT_2))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
uv_run();
|
uv_run(loop);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user