diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2011-08-06 03:38:11 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-08-06 03:38:11 -0700 |
commit | 88afc406caa64628a249d726659b3b054f8dc70d (patch) | |
tree | 9365cf67355848fd8f465ac48df402d80e1cdfe3 /deps/uv/test | |
parent | 13d6a1f67fe3d95ba674923c96c7f0ecc8e6575a (diff) | |
download | android-node-v8-88afc406caa64628a249d726659b3b054f8dc70d.tar.gz android-node-v8-88afc406caa64628a249d726659b3b054f8dc70d.tar.bz2 android-node-v8-88afc406caa64628a249d726659b3b054f8dc70d.zip |
Upgrade libuv to 48877ed
Diffstat (limited to 'deps/uv/test')
-rw-r--r-- | deps/uv/test/benchmark-list.h | 16 | ||||
-rw-r--r-- | deps/uv/test/benchmark-pound.c | 237 | ||||
-rw-r--r-- | deps/uv/test/echo-server.c | 19 |
3 files changed, 267 insertions, 5 deletions
diff --git a/deps/uv/test/benchmark-list.h b/deps/uv/test/benchmark-list.h index bc654b5afe..c05f37f7b5 100644 --- a/deps/uv/test/benchmark-list.h +++ b/deps/uv/test/benchmark-list.h @@ -21,6 +21,10 @@ BENCHMARK_DECLARE (sizes) BENCHMARK_DECLARE (ping_pongs) +BENCHMARK_DECLARE (tcp4_pound_100) +BENCHMARK_DECLARE (tcp4_pound_1000) +BENCHMARK_DECLARE (pipe_pound_100) +BENCHMARK_DECLARE (pipe_pound_1000) BENCHMARK_DECLARE (tcp_pump100_client) BENCHMARK_DECLARE (tcp_pump1_client) BENCHMARK_DECLARE (pipe_pump100_client) @@ -46,12 +50,24 @@ TASK_LIST_START BENCHMARK_ENTRY (tcp_pump1_client) BENCHMARK_HELPER (tcp_pump1_client, tcp_pump_server) + BENCHMARK_ENTRY (tcp4_pound_100) + BENCHMARK_HELPER (tcp4_pound_100, tcp4_echo_server) + + BENCHMARK_ENTRY (tcp4_pound_1000) + BENCHMARK_HELPER (tcp4_pound_1000, tcp4_echo_server) + BENCHMARK_ENTRY (pipe_pump100_client) BENCHMARK_HELPER (pipe_pump100_client, pipe_pump_server) BENCHMARK_ENTRY (pipe_pump1_client) BENCHMARK_HELPER (pipe_pump1_client, pipe_pump_server) + BENCHMARK_ENTRY (pipe_pound_100) + BENCHMARK_HELPER (pipe_pound_100, pipe_echo_server) + + BENCHMARK_ENTRY (pipe_pound_1000) + BENCHMARK_HELPER (pipe_pound_1000, pipe_echo_server) + BENCHMARK_ENTRY (gethostbyname) BENCHMARK_HELPER (gethostbyname, dns_server) diff --git a/deps/uv/test/benchmark-pound.c b/deps/uv/test/benchmark-pound.c new file mode 100644 index 0000000000..f45734f246 --- /dev/null +++ b/deps/uv/test/benchmark-pound.c @@ -0,0 +1,237 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "task.h" +#include "uv.h" + +/* Base class for tcp_conn_rec and pipe_conn_rec. + * The ordering of fields matters! + */ +typedef struct { + uv_connect_t conn_req; + uv_write_t write_req; + uv_stream_t stream; +} conn_rec; + +typedef struct { + uv_connect_t conn_req; + uv_write_t write_req; + uv_tcp_t stream; +} tcp_conn_rec; + +typedef struct { + uv_connect_t conn_req; + uv_write_t write_req; + uv_pipe_t stream; +} pipe_conn_rec; + +static char buffer[] = "QS"; + +static int64_t start_time, end_time; +static int closed_streams, concurrency; + +typedef void *(*setup_fn)(int num, void* arg); +typedef int (*connect_fn)(int num, void* handles, void* arg); + +static uv_buf_t alloc_cb(uv_stream_t* stream, size_t suggested_size); +static void connect_cb(uv_connect_t* conn_req, int status); +static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf); +static void close_cb(uv_handle_t* handle); + + +static uv_buf_t alloc_cb(uv_stream_t* stream, size_t suggested_size) { + static char slab[65536]; + uv_buf_t buf; + buf.base = slab; + buf.len = sizeof(slab); + return buf; +} + + +static void connect_cb(uv_connect_t* req, int status) { + conn_rec* conn; + uv_buf_t buf; + int r; + + ASSERT(req != NULL); + ASSERT(status == 0); + + conn = req->data; + ASSERT(conn != NULL); + + r = uv_read_start(&conn->stream, alloc_cb, read_cb); + ASSERT(r == 0); + + buf.base = buffer; + buf.len = sizeof(buffer) - 1; + + r = uv_write(&conn->write_req, &conn->stream, &buf, 1, NULL); + ASSERT(r == 0); +} + + +static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) { + ASSERT(stream != NULL); + ASSERT(nread == -1 && uv_last_error().code == UV_EOF); + uv_close((uv_handle_t*)stream, close_cb); +} + + +static void close_cb(uv_handle_t* handle) { + ASSERT(handle != NULL); + closed_streams++; + + if (closed_streams == concurrency) { + uv_update_time(); + end_time = uv_now(); + } +} + + +static void* tcp_do_setup(int num, void* arg) { + tcp_conn_rec* conns; + tcp_conn_rec* pe; + tcp_conn_rec* p; + int r; + + concurrency = num; + closed_streams = 0; + + conns = calloc(num, sizeof(tcp_conn_rec)); + ASSERT(conns != NULL); + + for (p = conns, pe = p + num; p < pe; p++) { + r = uv_tcp_init(&p->stream); + ASSERT(r == 0); + p->stream.data = p; + p->conn_req.data = p; + p->write_req.data = p; + p->conn_req.handle = (uv_stream_t*)&p->stream; + p->write_req.handle = (uv_stream_t*)&p->stream; + } + + return conns; +} + + +static void* pipe_do_setup(int num, void* arg) { + pipe_conn_rec* conns; + pipe_conn_rec* pe; + pipe_conn_rec* p; + int r; + + concurrency = num; + closed_streams = 0; + + conns = calloc(num, sizeof(pipe_conn_rec)); + ASSERT(conns != NULL); + + for (p = conns, pe = p + num; p < pe; p++) { + r = uv_pipe_init(&p->stream); + ASSERT(r == 0); + p->stream.data = p; + p->conn_req.data = p; + p->write_req.data = p; + p->conn_req.handle = (uv_stream_t*)&p->stream; + p->write_req.handle = (uv_stream_t*)&p->stream; + } + + return conns; +} + + +static int tcp_do_connect(int num, void* conns, void* arg) { + struct sockaddr_in addr; + tcp_conn_rec* pe; + tcp_conn_rec* p; + int r; + + addr = uv_ip4_addr("127.0.0.1", TEST_PORT); + for (p = conns, pe = p + num; p < pe; p++) { + r = uv_tcp_connect(&p->conn_req, &p->stream, addr, connect_cb); + ASSERT(r == 0); + } + + return 0; +} + + +static int pipe_do_connect(int num, void* conns, void* arg) { + pipe_conn_rec* pe; + pipe_conn_rec* p; + int r; + + for (p = conns, pe = p + num; p < pe; p++) { + r = uv_pipe_connect(&p->conn_req, &p->stream, TEST_PIPENAME, connect_cb); + ASSERT(r == 0); + } + + return 0; +} + + +static int pound_it(int concurrency, + const char* type, + setup_fn do_setup, + connect_fn do_connect, + void* arg) { + void* state; + int r; + + uv_init(); + + state = do_setup(concurrency, arg); + ASSERT(state != NULL); + + uv_update_time(); + start_time = uv_now(); + + r = do_connect(concurrency, state, arg); + ASSERT(!r); + + uv_run(); + + LOGF("%s-conn-pound-%d: %.0f accepts/s\n", + type, concurrency, + (double) concurrency / (double) (end_time - start_time) * 1000.0); + + return 0; +} + + +BENCHMARK_IMPL(tcp4_pound_100) { + return pound_it(100, "tcp", tcp_do_setup, tcp_do_connect, NULL); +} + + +BENCHMARK_IMPL(tcp4_pound_1000) { + return pound_it(1000, "tcp", tcp_do_setup, tcp_do_connect, NULL); +} + + +BENCHMARK_IMPL(pipe_pound_100) { + return pound_it(100, "pipe", pipe_do_setup, pipe_do_connect, NULL); +} + + +BENCHMARK_IMPL(pipe_pound_1000) { + return pound_it(1000, "pipe", pipe_do_setup, pipe_do_connect, NULL); +}
\ No newline at end of file diff --git a/deps/uv/test/echo-server.c b/deps/uv/test/echo-server.c index add2383983..a912dfebba 100644 --- a/deps/uv/test/echo-server.c +++ b/deps/uv/test/echo-server.c @@ -90,12 +90,21 @@ static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { return; } - /* Scan for the letter Q which signals that we should quit. */ + /* + * Scan for the letter Q which signals that we should quit the server. + * If we get QS it means close the stream. + */ if (!server_closed) { for (i = 0; i < nread; i++) { if (buf.base[i] == 'Q') { - uv_close(server, on_server_close); - server_closed = 1; + if (i + 1 < nread && buf.base[i + 1] == 'S') { + free(buf.base); + uv_close((uv_handle_t*)handle, NULL); + return; + } else { + uv_close(server, on_server_close); + server_closed = 1; + } } } } @@ -187,7 +196,7 @@ static int tcp4_echo_start(int port) { return 1; } - r = uv_listen((uv_stream_t*)&tcpServer, 128, on_connection); + r = uv_listen((uv_stream_t*)&tcpServer, SOMAXCONN, on_connection); if (r) { /* TODO: Error codes */ fprintf(stderr, "Listen error\n"); @@ -220,7 +229,7 @@ static int tcp6_echo_start(int port) { return 0; } - r = uv_listen((uv_stream_t*)&tcpServer, 128, on_connection); + r = uv_listen((uv_stream_t*)&tcpServer, SOMAXCONN, on_connection); if (r) { /* TODO: Error codes */ fprintf(stderr, "Listen error\n"); |