From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id DB12A1F4B6 for ; Thu, 4 Jul 2019 22:01:08 +0000 (UTC) From: Eric Wong 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> In-Reply-To: <20190704220108.7849-1-e@80x24.org> References: <20190704220108.7849-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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