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
Fix #5575 SEARCH method #5576
Fix #5575 SEARCH method #5576
Conversation
Fix #5575 SEARCH and PATCH methods
@lorban note that we have "manual" tries as well! |
Better test
Hmmm perhaps we should do all known methods and just use a Trie:
|
@lorban if you want to make this part of your Trie cleanup and implement all of those methods above, then just take the test, make a new CACHE and close this PR. |
Note that list is from http://www.iana.org/assignments/http-methods/http-methods.xhtml |
+ Used Trie for most lookups + Fixed ArrayTernayTrie lookup
….. helps with readability
jetty-http/src/main/java/org/eclipse/jetty/http/HttpMethod.java
Outdated
Show resolved
Hide resolved
jetty-http/src/main/java/org/eclipse/jetty/http/HttpMethod.java
Outdated
Show resolved
Hide resolved
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.
Reduce the amount of work you are doing by using enum features properly.
jetty-http/src/main/java/org/eclipse/jetty/http/HttpMethod.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
Issue #5575 - simpler HttpMethod enum
return toString(); | ||
int len = buffer.remaining(); | ||
// Short cut for 3 char methods, mostly for GET optimisation | ||
if (len > 3) |
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.
Is this really necessary?
Does this really produce any measurable performance improvement? (have you jmh'd this?)
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.
The getInt switch is an order of magnitude better. Interestingly the Map is slightly better than the Trie in this case sensitive case, but the map needs to allocate.
So doing this benchmark has convinced me I should do the getInt trick for POST and HEAD as well!
Benchmark Mode Cnt Score Error Units
HttpMethodBenchmark.testIntSwitch thrpt 10 234190385.517 ± 1954845.858 ops/s
HttpMethodBenchmark.testIntSwitch:·gc.alloc.rate.norm thrpt 10 ≈ 10⁻⁵ B/op
HttpMethodBenchmark.testMapGet thrpt 10 21957916.326 ± 507531.533 ops/s
HttpMethodBenchmark.testMapGet:·gc.alloc.rate.norm thrpt 10 48.000 ± 0.001 B/op
HttpMethodBenchmark.testTrieGetBest thrpt 10 18475001.742 ± 205942.699 ops/s
HttpMethodBenchmark.testTrieGetBest:·gc.alloc.rate.norm thrpt 10 ≈ 10⁻⁴ B/op
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.
Extending the int switch to POST and benchmarking against MOVE which doesn't have the optimisation gives:
Benchmark Mode Cnt Score Error Units
HttpMethodBenchmark.testHttpMethodMove thrpt 10 10435118.064 ± 240925.892 ops/s
HttpMethodBenchmark.testHttpMethodMove:·gc.alloc.rate.norm thrpt 10 ≈ 10⁻⁴ B/op
HttpMethodBenchmark.testHttpMethodPost thrpt 10 148142781.323 ± 14602351.496 ops/s
HttpMethodBenchmark.testHttpMethodPost:·gc.alloc.rate.norm thrpt 10 ≈ 10⁻⁵ B/op
HttpMethodBenchmark.testIntSwitch thrpt 10 206759099.264 ± 6371501.120 ops/s
HttpMethodBenchmark.testIntSwitch:·gc.alloc.rate.norm thrpt 10 ≈ 10⁻⁵ B/op
HttpMethodBenchmark.testMapGet thrpt 10 20527043.581 ± 415407.826 ops/s
HttpMethodBenchmark.testMapGet:·gc.alloc.rate.norm thrpt 10 48.000 ± 0.001 B/op
HttpMethodBenchmark.testTrieGetBest thrpt 10 18573224.811 ± 591011.908 ops/s
HttpMethodBenchmark.testTrieGetBest:·gc.alloc.rate.norm thrpt 10 ≈ 10⁻⁴ B/op
So even the slightly more complex lookup for POST easily beats the non optimised MOVE by an order of magnitude.
Makes me wonder if we shouldn't make Trie (or is it now an Index) that uses getLong and getInt for most of the work!
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.
Like @joakime I wonder if those shortcuts in lookAheadGet
are worth it.
+ added benchmark + optimised POST and HEAD
@joakime @lorban whilst a
I think this could be very memory intensive, as even something simple like HttpMethod would result in have 20 or 30 Maps in its tree. Perhaps it is something we could look at if ever a Trie lookup was seen in the a flamegraph. So for now, I think having a simple optimisation for GET and POST is a reasonable thing to do as it can be done with minimal complexity. Note that we have for a very long time had a hand coded optimisation for direct matching of common methods, so this is not adding an optimisation, but simply changing it's implementation to be a little better whilst handling more methods in general. |
@joakime nudge |
Fix #5575 SEARCH and PATCH methods