Created
May 4, 2012 19:27
-
-
Save zonpantli/2597168 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'net/http' | |
| require 'faraday' | |
| require 'em-http-request' | |
| require 'httpclient' | |
| class HttpRunner | |
| def self.run(client) | |
| case client.to_i | |
| # persistent | |
| when 1 | |
| Net::HTTP.start('localhost', 9000) do |http| | |
| while true | |
| response = http.get "/" | |
| puts response.body | |
| sleep 1 | |
| end | |
| end | |
| # not persistent | |
| when 2 | |
| http = Net::HTTP.new('localhost', 9000) | |
| while true | |
| response = http.get "/" | |
| puts response.body | |
| sleep 1 | |
| end | |
| # not persistent | |
| when 3 | |
| http = Faraday.new(:url => "http://localhost:9000") do |builder| | |
| builder.adapter :net_http | |
| end | |
| while true | |
| response = http.get do |req| | |
| req.url "/" | |
| end | |
| puts response.body | |
| sleep 1 | |
| end | |
| # not persistent | |
| when 4 | |
| while true | |
| EM.run do | |
| conn = EM::HttpRequest.new('http://localhost:9000/') | |
| request = conn.get :keepalive => true | |
| request.callback do | |
| puts request.response | |
| EM.stop | |
| end | |
| end | |
| sleep 1 | |
| end | |
| # persistent | |
| when 5 | |
| client = HTTPClient.new | |
| while true | |
| response = client.get_content("http://localhost:9000") | |
| puts response | |
| sleep 1 | |
| end | |
| # persistent | |
| when 6 | |
| http = Faraday.new(:url => "http://localhost:9000") do |builder| | |
| builder.adapter :net_http_persistent | |
| end | |
| while true | |
| response = http.get do |req| | |
| req.url "/" | |
| end | |
| puts response.body | |
| sleep 1 | |
| end | |
| else | |
| puts "No client type specified" | |
| end | |
| end | |
| end | |
| if __FILE__ == $0 | |
| HttpRunner.run(ARGV[0]) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment