Open dselivanov opened 4 years ago
Several discoveries here
Recent changes in https://github.com/rexyai/RestRserve/commit/3516e896d8a036b69dce64212431e3f2b163a4b2 led to noticeable speedup when keep-alive
disabled / each request opens new connection: 8 req/s -> 105 req/s on fibonacci benchmark. Pure Rserve is about 550 req/s.
Fork overhead is ~1ms on my machine.
Another speed up to R6 classes - https://github.com/duncantl/R6CompileNew
Issue #146 brought interesting discovery.
@s-u I actually haven't check the R benchmark code from #146. I was pretty sure that the main issue was due to fork overhead (which was somewhat aligned with my benchmarks here).
However I've run your code and indeed the fork overhead is very small. And that pointed me to the real source of why things are pretty slow when keep-alive is disabled: R's byte compiler. The "issue" here is that it seems compile
.http.request
and functions which are used inside it during every invocation. And since each request is handled in a fresh fork, it compiles it every time which adds significant overhead. I was suspecting this and tried to mitigate it here, but it seems it is not enough.Consider following (pure Rserve) example:
Testing with disabled JIT and disabled
keep-alive
gives around 550 req/s
Testing with enabled JIT and disabled
keep-alive
gives around 25 req/s
@s-u do you have any ideas on how to mitigate this apart from disabling byte compiler? (I don't really have an idea on how R's byte compiler works)