Closed Akeboshiwind closed 5 years ago
Thanks for the PR. Why does :max-queued-requests
need to be greater than 8? Is that hard-coded into Jetty?
Yeah, it's the minimum value that queue-capacity
can have in the threadpool buffer.
See here: https://github.com/ring-clojure/ring/blob/master/ring-jetty-adapter/src/ring/adapter/jetty.clj#L105
The error could probably be worded better but I didn't want to mention queue-capacity
in the error because that's an internal variable name.
I've been looking into the reasons behind the current queuepool code, and it looks like it's designed to mirror the code in Jetty. The reason that there is an 8 minimum capacity is because that's what the QueuedThreadPool implements by default.
Now that we know this, we can see the intent is to allow a minimum default queue size even if the number of threads is very low. However, if someone is explicitly passing the :max-queued-requests
option, then this default no longer applies. Therefore we should have something like:
queue-max-capacity (options :max-queued-requests Integer/MAX_VALUE)
queue-capacity (-> min-threads (max 8) (min queue-max-capacity))
In other words:
Rule 1 takes precedence over rules 2 and 3.
So I think we can actually do away with the exceptions (sorry for telling you to write them), now that the reasons for the underlying code are better understood.
No problem, you're correct this solution is better. Thanks for taking a more detailed look into the issue :)
I'll close this PR as presumably you will make the one line change that's needed.
If accepted should close #354.