Sanic: Is there anyway to measure sanic performance?

Created on 1 Mar 2017  路  17Comments  路  Source: sanic-org/sanic

Hi,

Is there a way to measure sanic performance with Newrelic or Any other way to do? As per discussion with newrelic, it won't support sanic as of now. Is there any other way to measure it?

All 17 comments

Yes it looks like new relic only works with wsgi as of now. Have you looked at data dog? http://docs.datadoghq.com/integrations/python/

It's probably quite a bit more manual to integrate than New Relic, but that would probably give you more control anyway so it might not be a bad thing. Looks fairly easy...

No, I checked with netuitive, appinternals riverbed. But that doesn't seems working.

@Gowtham95india Any of those could have more readily Gunicorn support, in which case you could consider running it as a GunicornUVLoopWorker as referenced in #61 . I'm not sure if it has a considerable effect on performance, however as @r0fls said, data dog looks worth it to integrate for your needs.

@Sniedes722

Yeah.., I want to avoid Gunicorn, just to check pure performance of Sanic. We want to some high load and see the response time. So, I think it is better to test with pure sanic web workers.

I'm trying to implement datadoghq as metioned by r0fls.

@Gowtham95india any luck? :) I'm curious...

@r0fls as of now, no luck. I tested with almost 5-6 monitoring solutions. Nothing seems working. But, as per my discussion with datadoghq., they are going to release new version of python agent very soon, in which they are adding support of asynchronous frameworks.

Newrelic stated the same, but it is like, they didn't even start working on that.

So, waiting for datadoghq update for python agent. The only problem with all the monitoring solution providers is that Sanic is ASYNC framework.

I'll update once I get the response from Datadoghq.

Good to know they're working on it anyway...

yea, at last. Hope, will get at least one way to measure it.

Hey folks I actually was working on creating a more formal version of this but a MVP using prometheus looks like

    import prometheus_client as pc
    from time import perf_counter
    from sanic import Blueprint
    from sanic.response import HTTPResponse

    bp = Blueprint('prometheus')

    rec_counter = pc.Counter('http_requests_total',
        'Total number of HTTP requests made.', ['method', 'url', 'status'])
    timer = pc.Histogram('http_request_duration_seconds',
        'The HTTP request latencies in seconds.', ['method', 'url', 'status'])
    concurrent_req = pc.Gauge('http_concurrent_requests',
        'The current number of HTTP requests being processed.', ['method', 'url'])
    timers = {}


    @bp.middleware('request')
    def set_timers(request):
        timers[id(request)] = perf_counter()
        labels = [request.method, request.url]
        concurrent_req.labels(*labels).inc()


    @bp.middleware('response')
    def observe(request, response):
        dur = perf_counter() - timers.pop(id(request))
        labels = [request.method, request.url, response.status]
        timer.labels(*labels).observe(dur)
        rec_counter.labels(*labels).inc()
        concurrent_req.labels(*labels[:-1]).dec()


    @bp.route("/metrics")
    async def metrics(request):
        return HTTPResponse(body_bytes=pc.generate_latest(pc.REGISTRY),
                                headers={'Content-Type': pc.CONTENT_TYPE_LATEST})

My only qualm with it is using a global timers dictionary to track requests by id, it seems like there should be a better way to do it.

If you are doing reverse proxying With Nginx, you can set header proxy_set_header X-Request-Start "t=${msec}"; and use that in response middleware to calculate the response time. So that you can avoid request middleware and storing those details.

I think dynatrace looks like a good option. I'm able to measure the response time. Quickly, i'll try to do load test with it and get back to you guys. As of now, little busy with another work. Can anyone take a look at dyntrace and benchmark Sanic ?

Now that the gunicorn worker has been merged, and the performance is great, why not try that?

Is this solved? Many solutions provided. I think solutions for testing performance should be added to Wiki also.

yep, I think you can close this issue.

For anyone who was interested in Datadog as mentioned here: https://github.com/channelcat/sanic/issues/501#issuecomment-284322741

They have apparently now released the python 3 async monitoring support. Curious if anyone has a chance to give it a shot!

Graphite is also a good choice for monitoring/metrics storing. You can also use it by grafana.

We are using statsd and grafana in production for a service built on Sanic.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eseglem picture eseglem  路  4Comments

olalonde picture olalonde  路  3Comments

ubergarm picture ubergarm  路  4Comments

graingert picture graingert  路  3Comments

vlad0337187 picture vlad0337187  路  3Comments