Repository navigation
more optimizations - #121
Conversation
Baseline @ 2.5K requests/second for 2 minutes:
Requests [total, rate, throughput] 300000, 2500.01, 2500.00
Duration [total, attack, wait] 2m0s, 2m0s, 633.693µs
Latencies [min, mean, 50, 90, 95, 99, max] 228.976µs, 2.808ms, 360.599µs, 808.569µs, 1.1ms, 99.642ms, 340.486ms
Bytes In [total, mean] 1500000, 5.00
Bytes Out [total, mean] 0, 0.00
Success [ratio] 100.00%
Status Codes [code:count] 200:300000
Error Set:
After this change:
Requests [total, rate, throughput] 300000, 2500.01, 2500.00
Duration [total, attack, wait] 2m0s, 2m0s, 660.098µs
Latencies [min, mean, 50, 90, 95, 99, max] 221.044µs, 666.861µs, 328.204µs, 635.192µs, 794.381µs, 6.891ms, 132.629ms
Bytes In [total, mean] 1500000, 5.00
Bytes Out [total, mean] 0, 0.00
Success [ratio] 100.00%
Status Codes [code:count] 200:300000
Error Set:
Memory use is the same between this and the master branch on my
machine, but I suspect my machine's IO is just too fast. If I were to
try this on a cloud machine, I suspect there would be a significant
improvement with this change.
This preserves the behavior of run-server except for timeouts. The mzlib server spawns two threads for every connection: one to handle the connection, and another to break the first thread on timeout. The web server never used the timeout functionality, so the second thread would be spawned and forced to wait until the handling thread finished, then close the connection custodian.
The behavior remains mostly the same, except now we don't need to set up a new handler on every request.
The non-private export of `make-read-request' has a contract and the `dispatch-server^' signature also installs one. This avoids taking that hit twice.
|
|
||
|
|
||
| (define-safety-limits/private-submodule | ||
| max-concurrent positive-count/c 1000 #:unlimited +inf.0 |
There was a problem hiding this comment.
This limit may be too conservative, so it might be worth raising. It's a hard balance, though:
- if there's no limit, then it's easy to DoS the server,
- if the default limit is too low, we may be limiting performance on very fast servers
- if the default limit is too high, slow servers may be open to DoS
IME, once you have several thousands of threads running, performance tends to degrade so 1000 feels right. Arguably, people doing very high performance stuff w/ the web server should be aware of and tweaking safety-limits anyway. I'll have to take a look at what other servers' defaults are.
There was a problem hiding this comment.
In the end, I bumped this to 10k. Most of the servers I looked at had no default limit (but they did have ways to enforce a limit), except for gunicorn which has a limit of 1k by default.
|
Does removing |
jeapostrophe
left a comment
There was a problem hiding this comment.
This looks awesome to me
Yup, looks like it does. |
|
Re replacing It's a pathological case, but mechanisms like #lang racket
(dynamic-wind
void
(λ ()
(kill-thread (current-thread)))
(λ ()
(println 'this-never-prints)))I think This sort of subtlety is why I suggested in #106 (comment):
More broadly, this is reminding me of mailing-list discussion in https://groups.google.com/g/racket-users/c/AAeEp_llxaY/m/uRviksPGAgAJ and https://groups.google.com/g/racket-dev/c/PyetqHSjtAA/m/slBdazdqAwAJ about the subtleties of delimited control and the Concurrent ML subsystem and the limitations of finalization with
I'll try to take a look at other aspects of this PR later. |
|
The
I'm not sure I understand what you mean here. The custodian that gets shut down is the one that wraps both the thread and the TCP ports. |
@LiberalArtist pointed out that the version that doesn't use a cleanup thread can get in a bad state when handlers kill the current thread.
|
Here's how we're doing so far:
For comparison, here's the plaintext benchmark on express.js on the same machine. The test machine in this case is a 24-core AMD server. |
|
I think we should merge and brag ;) |
|
I'll wrap this up tomorrow morning and then we can merge. There are more improvements that could be made, but we can leave those for another time so this doesn't get too large and because I'm not sure when I'll have time to do them. |
`check-exn` was recently[1] changed to enforce its `message` argument and this test was using it wrong. [1]: racket/rackunit@d5676a9#diff-be44254d70efbdd4192059f2a369dd9223835927001e849ed2e9628c5f63901eR116
|
OK, I think this is good to go now. |
Also tweak parameters and adjust `place-tcp-listener` implementation for recent web-server changes[1]. [1]: racket/web-server#121
Also tweak parameters and adjust `place-tcp-listener` implementation for recent web-server changes[1]. [1]: racket/web-server#121
I'm opening this as a draft in case folks want to weigh in on the changes. I've still got a few changes I want to make over the next couple weeks so this isn't quite ready yet. This PR includes the commit from #120, but that can be merged independently so it doesn't block #119.
The PR may be easier to read if you read the commits independently. I forgot @samth also worked on removing
run-serveruntil I looked at the list of open PRs just now, but I took that a little further by also improving the server loop in a couple ways so I think this PR supersedes #106.Tested against the
/plaintextendpoint of this app. Master branch:(note that this app uses its own dispatcher, not
dispatch/servlet, which is why these numbers are better than the baseline numbers in commit 4506e72 --dispatch/servletneeds to do a lot of work that applications that don't use continuations don't benefit from)This branch:
For comparison, here's how Node 17 running express does on the same benchmark on my machine: