question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The pycurl client

See original GitHub issue

I want to use pycurl to do the http request, so I make a pycurl client likes below:

coding=utf-8

from locust import Locust, events import time import pycurl from cStringIO import StringIO from exceptions import AttributeError

class PycurlClient(object):

def __init__(self):
    self.curl = None
    self.recordFuncs = ['perform']

def openCurl(self):
    self.curl = pycurl.Curl()

def closeCurl(self):
    try:
        self.curl.close()
    except:
        pass

def __getattr__(self, name):
    try:
        func = eval('self.curl.' + name)
    except AttributeError:
        print 'pycurl does not have the method %s' % name

    def wrapper(*args, **kwargs):
        start_time = time.time()
        try:
            result = func(*args, **kwargs)
        except Exception as e:
            total_time = int((time.time() - start_time) * 1000)
            events.request_failure.fire(request_type="pycurl", name=name, response_time=total_time, exception=e)
        else:
            if name in self.recordFuncs:
                total_time = int((time.time() - start_time) * 1000)
                events.request_success.fire(request_type="pycurl", name=name, response_time=total_time, response_length=0)
    return wrapper

class PycurlLocust(Locust):

client = None

def __init__(self, *args, **kwargs):
    super(PycurlLocust, self).__init__(*args, **kwargs)
    self.client = PycurlClient()

And, I use this client in my new task like this:

coding=utf-8

import pycurl from locust.pycurlclients import PycurlClient, PycurlLocust from locust import TaskSet, task from cStringIO import StringIO

class TestTaskSet(TaskSet): @task def index(self): print ‘%s get index’ % str(self.locust) self.client.openCurl() self.client.setopt(pycurl.URL, r’http://www.so.com’) sio = StringIO() self.client.setopt(pycurl.WRITEFUNCTION, sio.write) self.client.perform() self.client.closeCurl()

def on_start(self):
    print 'locust %s' % str(self.locust)

class TestPycurlClient(PycurlLocust): max_wait = min_wait = 1 task_set = TestTaskSet host = r’http://www.so.com

When the user was 1, the pycurl’s performance was better than requests, but when I increased the user’s number, the requests number of per second equals to the 1 user almostly. So do you have some suggestions about this?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
gautamdivgicommented, Jul 9, 2019

I came upon this issue and know its closed. However, I just wanted to point out one thing. The reason I was looking to use pycurl is to get internal metrics on the actual HTTP call. The “response time” for an call will include multiple things - DNS lookup, TLS negotiation, server latency to process the call, etc. Curl makes those available. That’s the reason I was looking to use pycurl. Are those metrics provided via locust today? I didn’t see them but thought I’d ask. For reference here’s what curl provides for metrics - https://ec.haxx.se/usingcurl-writeout.html

1reaction
likezjuiseecommented, Dec 13, 2016

I known the monkey patches, but I guess it may be worse than asyncio. You might look around the web server framework sanic https://github.com/channelcat/sanic, it benefits from the httptools and uvloop. So I supposed you to update the locust to python3.5. If you persist with your own plan, it is ok. ^_^

Read more comments on GitHub >

github_iconTop Results From Across the Web

PycURL Home Page
PycURL is a Python interface to libcurl. PycURL can be used to fetch objects identified by a URL from a Python program, similar...
Read more >
pycurl-client - PyPI
pycurl -client 3.13.1 · Project description · Project details · Release history Release notifications | RSS feed · Download files · Help ·...
Read more >
The curl client requires the pycurl library Docker + Django
This issue was with the libcurl4-nss-dev libssl-dev installation. In the following installation script. RUN set -ex \ && BUILD_DEPS=" ...
Read more >
PycURL -- A Python Interface To The cURL library - GitHub
Similarly to the urllib Python module, PycURL can be used to fetch objects identified by a URL from a Python program. Beyond simple...
Read more >
Installing PycURL on macOS High Sierra - Chi Shang Cheng
ImportError: The curl client requires the pycurl library. Which is weird, since there were no errors when I installed celery[sqs] .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found