-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve HTTP parsing long look-ahead #11486
Conversation
Use ByteBuffer.getLong to look for entire request (GET / HTTP/1.1) or response (HTTP/1.1 200 OK) line with 2 long lookups. Failing that, a single long lookup is sufficient to determine the common methods and/or HttpVersion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a perf improvement, a JMH benchmark to prove this change is worthy would be nice.
jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
Outdated
Show resolved
Hide resolved
@lorban done. Note we already have a JMH for HttpMethod, showing that an int lookup is much better than a byte by byte walk of a Trie.
The tests are give a GET request (which will match the longs) or a POST request (which will not). If the long lookAhead misses, it calls the normal parse. JMH results are:
For 100% hits, the performance of the long lookAhead is more than an order of magnitude better! 240M op/s vs 20M op/s ! So this is obviously a very advantageous technique if we can hit frequently. (@sbordet wow!) For 0% hits, the lookAhead is slightly slower: 20.0M op/s vs 20.4M op/s. This is is within the error margins of the runs (+/- 2M op/s). So we can say that the cost of doing the lookAhead is insignificant even if it never hits. For just 1% of hits, we get a small gain of 22.6M op/s vs 19.4 op/s, which is just above the margin of error (+/- 0.5M op/s) For 10% hits the gain is a bit more 23.5M op/s vs 19.1 op/s, so it looks like gains are real. Thus I think this will be really beneficial for the client as "HTTP/1.1 200 OK" should be a very frequent match. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Splendid! LGTM.
Added a fallback int lookup
@lorban I've just done a little tweak, so if the long looked up to try to match "GET / HT" misses, then the high int of that long is used by the |
Added a fallback int lookup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nit if you want to fix it. LGTM.
Use ByteBuffer.getLong to look for entire request (GET / HTTP/1.1) or response (HTTP/1.1 200 OK) line with 2 long lookups. Failing that, a single long lookup is sufficient to determine the common methods and/or HttpVersion.