From: Eric Wong <e@80x24.org> To: unicorn-public@bogomips.org Subject: [PATCH 1/3] unit benchmark for our HTTP parser Date: Thu, 4 Jul 2019 22:01:06 +0000 Message-ID: <20190704220108.7849-2-e@80x24.org> (raw) In-Reply-To: <20190704220108.7849-1-e@80x24.org> 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
next prev parent reply other threads:[~2019-07-04 22:01 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-07-04 22:01 [PATCH 0/3] http: use gperf for common field memoization Eric Wong 2019-07-04 22:01 ` Eric Wong [this message] 2019-07-04 22:01 ` [PATCH 2/3] http: use gperf for common fields optimization Eric Wong 2019-07-04 22:01 ` [PATCH 3/3] http: memoize more common fields Eric Wong 2019-07-05 20:30 ` [PATCH 4/3] http: gperf 3.0.3 compatibility Eric Wong
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: https://yhbt.net/unicorn/ * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190704220108.7849-2-e@80x24.org \ --to=e@80x24.org \ --cc=unicorn-public@bogomips.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help This inbox may be cloned and mirrored by anyone: git clone --mirror https://yhbt.net/unicorn-public git clone --mirror http://ou63pmih66umazou.onion/unicorn-public # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V1 unicorn-public unicorn-public/ https://yhbt.net/unicorn-public \ unicorn-public@yhbt.net unicorn-public@bogomips.org mongrel-unicorn@rubyforge.org mongrel-unicorn-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org public-inbox-index unicorn-public Example config snippet for mirrors. Newsgroups are available over NNTP: nntp://news.public-inbox.org/inbox.comp.lang.ruby.unicorn nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.unicorn note: .onion URLs require Tor: https://www.torproject.org/ code repositories for the project(s) associated with this inbox: ../../unicorn.git AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git