Created
          December 14, 2010 20:10 
        
      - 
      
 - 
        
Save vangberg/741008 to your computer and use it in GitHub Desktop.  
    persistent http w/ ruby
  
        
  
    
      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 "curb" | |
| # Persistent. | |
| c = Curl::Easy.new | |
| c.url = "http://127.0.0.1" | |
| 2.times { c.perform } | |
| # Not persistent. | |
| 2.times { | |
| c = Curl::Easy.new | |
| c.url = "http://127.0.0.1" | |
| c.perform | |
| } | 
  
    
      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 "httpclient" | |
| # Persistent. | |
| client = HTTPClient.new | |
| 2.times { client.get("http://127.0.0.1") } | |
| # Not persistent. | |
| 2.times { | |
| client = HTTPClient.new | |
| client.get("http://127.0.0.1") | |
| } | 
  
    
      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 "uri" | |
| require "net/http/persistent" | |
| uri = URI.parse "http://127.0.0.1" | |
| # Persistent. | |
| per = Net::HTTP::Persistent.new | |
| get = Net::HTTP::Get.new(uri.request_uri) | |
| 2.times { per.request uri, get } | |
| # Persistent. | |
| 2.times { | |
| per = Net::HTTP::Persistent.new | |
| get = Net::HTTP::Get.new(uri.request_uri) | |
| per.request uri, get | |
| } | |
| # DUDE! It's "net-http-persistent" - of course it's persistent. Wtf, c'mon. | 
  
    
      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 "typhoeus" | |
| # Persistent. | |
| Typhoeus::Request.get("http://127.0.0.1") | |
| Typhoeus::Request.get("http://127.0.0.1") | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment