mirror of
https://github.com/wg/wrk
synced 2025-03-13 18:07:17 +08:00
reduce system calls to improve performance
This commit is contained in:
parent
d0582223a2
commit
acb9a78925
12
src/wrk.c
12
src/wrk.c
@ -249,10 +249,7 @@ static int connect_socket(thread *thread, connection *c) {
|
|||||||
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
||||||
|
|
||||||
if (connect(fd, addr.ai_addr, addr.ai_addrlen) == -1) {
|
if (connect(fd, addr.ai_addr, addr.ai_addrlen) == -1) {
|
||||||
if (errno != EINPROGRESS) {
|
if (errno != EINPROGRESS) goto error;
|
||||||
thread->errors.connect++;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flags = 1;
|
flags = 1;
|
||||||
@ -262,6 +259,10 @@ static int connect_socket(thread *thread, connection *c) {
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (aeCreateFileEvent(loop, fd, AE_READABLE, socket_readable, c) != AE_OK) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
http_parser_init(&c->parser, HTTP_RESPONSE);
|
http_parser_init(&c->parser, HTTP_RESPONSE);
|
||||||
c->parser.data = c;
|
c->parser.data = c;
|
||||||
c->fd = fd;
|
c->fd = fd;
|
||||||
@ -269,6 +270,7 @@ static int connect_socket(thread *thread, connection *c) {
|
|||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
thread->errors.connect++;
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -315,7 +317,6 @@ static int request_complete(http_parser *parser) {
|
|||||||
if (!http_should_keep_alive(parser)) goto reconnect;
|
if (!http_should_keep_alive(parser)) goto reconnect;
|
||||||
|
|
||||||
http_parser_init(parser, HTTP_RESPONSE);
|
http_parser_init(parser, HTTP_RESPONSE);
|
||||||
aeDeleteFileEvent(thread->loop, c->fd, AE_READABLE);
|
|
||||||
aeCreateFileEvent(thread->loop, c->fd, AE_WRITABLE, socket_writeable, c);
|
aeCreateFileEvent(thread->loop, c->fd, AE_WRITABLE, socket_writeable, c);
|
||||||
|
|
||||||
goto done;
|
goto done;
|
||||||
@ -353,7 +354,6 @@ static void socket_writeable(aeEventLoop *loop, int fd, void *data, int mask) {
|
|||||||
if (write(fd, request.buf, request.size) < request.size) goto error;
|
if (write(fd, request.buf, request.size) < request.size) goto error;
|
||||||
c->start = time_us();
|
c->start = time_us();
|
||||||
aeDeleteFileEvent(loop, fd, AE_WRITABLE);
|
aeDeleteFileEvent(loop, fd, AE_WRITABLE);
|
||||||
aeCreateFileEvent(loop, fd, AE_READABLE, socket_readable, c);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user