Commit Graph

5 Commits

Author SHA1 Message Date
Tom Dryer
667edacaa3
Fix hung connection from consecutive requests (#7)
A client making quick consecutive requests with keep-alive, such as `ab`
with `-k`, can cause the connection to become hung.

This happens because of an optimization in `http_poll` function. When a
connection state becomes `DONE`, `httpd_poll` recycles the connection
and immediately calls `poll_recv_request`. However, it doesn't handle
this resulting in the connection state becoming `DONE` again. If this
occurs, the state stays in `DONE`, and the further calls to `httpd_poll`
ignore the connection.

Fix this by calling `poll_recv_request` in a loop until the state is no
longer `DONE`.

* Enable TCP_NODELAY optimization

It looks like `TCP_NODELAY` was disabled due to the bug fixed in the
previous commit. Enabling it substantially improves keep-alive
performance with `ab`:

Before:

```
Time per request:       0.272 [ms] (mean)
```

After:

```
Time per request:       0.033 [ms] (mean)
```

* Remove keep-alive optimization from `httpd_poll`

Benchmarking with `ab` shows that bypassing `select` for keep-alive
connections in the `DONE` state doesn't significantly impact
performance. Since this optimization previously caused a bug, remove it.
2021-06-14 11:44:55 +10:00
Emil Mikulic
ba63a6d60f Add test for --timeout. 2018-12-10 23:52:42 +11:00
Emil Mikulic
f0a8dc6c6c Add --timeout cmdline option. 2018-12-10 23:35:31 +11:00
Emil Mikulic
89af6956e2 Fix timeouts to close connections. 2018-12-10 21:03:17 +11:00
Emil Mikulic
cfcbdf0ad7 Stuff to do when I find the time. 2013-04-28 19:56:51 +10:00