How to use http persistent connection

carol <hrxue-9Onoh4P/[email protected]> Mon, 23 Mar 2015 15:57:55 +0800 (CST)
Newsgroups gmane.comp.java.grinder.user
Message-ID <[email protected]>
Dear,
       According to the grinder user guide, the default http connection is keep-alive. 
       But even I tried to request with a ‘‘Connection:Keep-Alive’’ header as show in the attached script, it seemed to be not a persistent connection。 
       Anything wrong with this script? How to request via a Http persistent connection by a worker thread?


      Waiting to hear from you,  


Yours sincerely, 


 carol

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/

_______________________________________________
grinder-use mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/grinder-use
getInfo.py (application/octet-stream, 1.6 KB)
# simple example using the HTTP plugin that shows the retrieval of a
# single page via HTTP. 
# The resulting page is written to a file.
# More complex HTTP scripts are best created with the TCPProxy.

from net.grinder.script.Grinder import grinder
from net.grinder.script import Test
from net.grinder.plugin.http import HTTPPluginControl,HTTPRequest
from HTTPClient import NVPair

control = HTTPPluginControl.getConnectionDefaults()
control.setDefaultHeaders((NVPair("Connection", "Keep-Alive"),NVPair("Keep-Alive","timeout=20")))
test1 = Test(1, "Request resource")
request1 = HTTPRequest()
test1.record(request1)

headers= \
  [ NVPair('Connection', 'Keep-Alive'), 
    NVPair('Keep-Alive', 'timeout=20'),]

class TestRunner:
    def __call__(self):
        #result = request1.GET("http://192.168.32.123:8084/quote/v1/real?en_prod_code=600570.SS,600000.SS&access_token=3A38D82FEE994EA78D19AE0452D43DC02015032310543039435591")
        result = request1.GET("https://192.168.30.125:443/quote/v1/real?en_prod_code=600570.SS,600000.SS&access_token=3A38D82FEE994EA78D19AE0452D43DC02015032310543039435591", None, headers)
        # result is a HTTPClient.HTTPResult. We get the message body
        # using the getText() method.
        if result.getStatusCode() != 200:
            writeToFile("status code = " + str(result.getStatusCode()))
            writeToFile(result.text)
# Utility method that writes the given string to a uniquely named file.
def writeToFile(text):
    filename = "/root/grinder-3.11/log/%s-page-%d.txt" % (grinder.processName, grinder.threadNumber)
    file = open(filename, "w")
    print >> file, text
    file.close()