* [PATCH 1/3] unit benchmark for our HTTP parser
2019-07-04 22:01 4% [PATCH 0/3] http: use gperf for common field memoization Eric Wong
@ 2019-07-04 22:01 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2019-07-04 22:01 UTC (permalink / raw)
To: unicorn-public
Some changes coming to the HTTP parser, so might as well throw
some sort of benchmark we can work with to validate
improvements.
---
test/benchmark/http_parser.rb | 43 +++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 test/benchmark/http_parser.rb
diff --git a/test/benchmark/http_parser.rb b/test/benchmark/http_parser.rb
new file mode 100644
index 0000000..9509637
--- /dev/null
+++ b/test/benchmark/http_parser.rb
@@ -0,0 +1,43 @@
+# encoding: binary
+# benchmark for HTTP parser hackers:
+# make http && ruby -I lib:ext/unicorn_http test/benchmark/http_parser.rb
+require 'unicorn'
+require 'optparse'
+require 'benchmark'
+$stdout.sync = true
+extra = []
+nr = 100000
+op = OptionParser.new("", 24, ' ') do |opts|
+ opts.banner = "Usage: #$0"
+ opts.separator "#$0 options:"
+ # some of these switches exist for rackup command-line compatibility,
+
+ opts.on('-n NUM', Integer, 'number of iterations') { |i| nr = i }
+ opts.on('-H HEADER:VALUE', String) { |h| extra << h }
+ opts.parse! ARGV
+end
+extra << '' if extra[0]
+
+payload = <<"".freeze
+GET /nowhere HTTP/1.0\r
+Host: example.com\r
+Accept-Encoding: gzip\r
+Accept-Language: en-US\r
+User-Agent: curl/7.52.1\r
+Accept: */*\r
+Referer: https://example.com/eye-kant-spel\r
+Cache-Control: max-age=0\r
+X-Forwarded-For: 0.6.6.6\r
+#{extra.join("\r\n")}\r
+
+hp = Unicorn::HttpParser.new
+puts payload.gsub(/^/, '> ')
+puts "#{nr} iterations"
+res = Benchmark.measure do
+ nr.times do
+ hp.buf << payload
+ hp.parse or abort
+ hp.clear
+ end
+end
+puts Benchmark::CAPTION, res
--
EW
^ permalink raw reply related [relevance 7%]
* [PATCH 0/3] http: use gperf for common field memoization
@ 2019-07-04 22:01 4% Eric Wong
2019-07-04 22:01 7% ` [PATCH 1/3] unit benchmark for our HTTP parser Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2019-07-04 22:01 UTC (permalink / raw)
To: unicorn-public
I've been using gperf in other places, so I figured I might
as well make HTTP parsing a teeny bit faster and allow us
to avoid generating more garbage up front.
Eric Wong (3):
unit benchmark for our HTTP parser
http: use gperf for common fields optimization
http: memoize more common fields
.gitignore | 1 +
GNUmakefile | 18 ++++-
ext/unicorn_http/common_field_optimization.h | 79 +++++---------------
ext/unicorn_http/common_fields.gperf | 66 ++++++++++++++++
ext/unicorn_http/gperf.rb | 27 +++++++
test/benchmark/http_parser.rb | 43 +++++++++++
6 files changed, 170 insertions(+), 64 deletions(-)
create mode 100644 ext/unicorn_http/common_fields.gperf
create mode 100644 ext/unicorn_http/gperf.rb
create mode 100644 test/benchmark/http_parser.rb
--
EW
^ permalink raw reply [relevance 4%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2019-07-04 22:01 4% [PATCH 0/3] http: use gperf for common field memoization Eric Wong
2019-07-04 22:01 7% ` [PATCH 1/3] unit benchmark for our HTTP parser Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/unicorn.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).