Skip to content

Commit c46b6e9

Browse files
committed
[core] reduce syscalls in some backend connect
reduce syscalls in some backend connect scenarios
1 parent fc7cd36 commit c46b6e9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/gw_backend.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,14 +2074,24 @@ static handler_t gw_write_request(gw_handler_ctx * const hctx, request_st * cons
20742074
/*(disable Nagle algorithm if streaming and content-length unknown)*/
20752075
if (AF_UNIX != hctx->host->family) {
20762076
if (r->reqbody_length < 0) {
2077-
if (-1 == fdevent_set_tcp_nodelay(hctx->fd, 1)) {
2078-
/*(error, but not critical)*/
2077+
/*(skip if hctx->create_env() already called
2078+
* gw_set_transparent() to fdevent_set_tcp_nodelay() */
2079+
if (hctx->state != GW_STATE_WRITE) {
2080+
if (-1 == fdevent_set_tcp_nodelay(hctx->fd, 1)) {
2081+
/*(error, but not critical)*/
2082+
}
20792083
}
20802084
}
20812085
}
20822086

20832087
hctx->read_ts = log_monotonic_secs;
2084-
fdevent_fdnode_event_add(hctx->ev, hctx->fdn, FDEVENT_IN|FDEVENT_RDHUP);
2088+
{
2089+
int events = fdevent_fdnode_interest(hctx->fdn)
2090+
| FDEVENT_IN|FDEVENT_RDHUP;
2091+
if (chunkqueue_is_empty(&hctx->wb))
2092+
events &= ~FDEVENT_OUT; /*(no data ready; avoid extra syscall)*/
2093+
fdevent_fdnode_event_set(hctx->ev, hctx->fdn, events);
2094+
}
20852095
gw_set_state(hctx, GW_STATE_WRITE);
20862096
__attribute_fallthrough__
20872097
case GW_STATE_WRITE:

0 commit comments

Comments
 (0)