Skip to main content

A profiler for Tornado Web Server

Project description

Tornado-Profiler

A profiler measures endpoints defined in your tornado application.

Screenshots

Dashboard: Give a summary of all datas

If an endpoint has been accessed before, you can see its summary data as follows.

dashboard

Filtering: Give filtered datas

You can create filters to get datas that meet the criterias.

filtering

Context: Give all details of a request

You can get all details of a request as you wish.

context

Installation

PyPI version:

$ pip install tornado-profiler

Development version:

$ pip install https://github.com/garenchan/tornado-profiler/zipball/master

Quick Start

Just add a few lines to you codes:

# demo.py
import tornado.ioloop
import tornado.web

from tornado_profiler import Profiler


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("main")

class HelloHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

def make_app():
    app = tornado.web.Application([
        (r"/", MainHandler),
    ])

    # use to store measurement datas
    backend = {
        "engine": "sqlalchemy",
    }
    # instantiate profiler
    profiler = Profiler(backend)
    # do something to your app
    profiler.init_app(app)

    # you can add some rules that won't be profiled here
    app.add_handlers(r".*", [
        (r"/hello", HelloHandler),
    ])

    return app

if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()

Now run your demo.py and make some requests as follows:

$ curl http://127.0.0.1:8888/
$ curl http://127.0.0.1:8888/hello

If everything is ok, tornado-profiler will measure these requests. You can see the result heading to http://127.0.0.1:8888/tornado-profiler or get results as JSON http://127.0.0.1:8888/tornado-profiler/api/measurements

Data Storage Backend

You can use some databases to store your measurement data, such as SQLite, Mysql. The drivers we support are shown as follows:

SQLAlchemy

In order to use SQLAlchemy, just specify backend's engine as "sqlalchemy". This will use SQLite by default and save it to tornado_profiler.db in your working directory.

backend = {
    "engine": "sqlalchemy",
}

If your want to change default sqlite database filename or use other databases, you need to set db_url manually:

backend = {
    "engine": "sqlalchemy",
    "db_url": "sqlite:///dbname.db",
}

backend = {
    "engine": "sqlalchemy",
    "db_url": "mysql+<driver-name>://user:password@<host>[:<port>]/<dbname>",
}

Setting some attributes of SQLAlchemy is also necessary, you just need to pass them into the backend dict:

backend = {
    "engine": "sqlalchemy",
    "db_url": "mysql+<driver-name>://user:password@<host>[:<port>]/<dbname>",
    # attributes
    "pool_recycle": 3600,
    "pool_timeout": 30,
    "pool_size": 30,
    "max_overflow": 20,
}

In some scenarios, we do not want to persist measurement datas, we can use the in-memory database of SQLite and datas will be lost when your web server stops or restarts:

backend = {
    "engine": "sqlalchemy",
    "db_url": "sqlite://",
}

Other Drivers

coming soon!

Comment

If you have any other requirements, please submit PR or issues. I will reply to you as soon as possible.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tornado-profiler-1.0.0.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

tornado_profiler-1.0.0-py3-none-any.whl (1.2 MB view details)

Uploaded Python 3

File details

Details for the file tornado-profiler-1.0.0.tar.gz.

File metadata

File hashes

Hashes for tornado-profiler-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f7ba8422333d0886c070b06a0c5777e237175d20208efb386dc240400ac69392
MD5 c03f4438b9ade3f8a49def3fe4565701
BLAKE2b-256 b153650b3d4c31213c71afba652d821d562298f8a03a70a8a2522ec9df1d5811

See more details on using hashes here.

File details

Details for the file tornado_profiler-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tornado_profiler-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59b977563c583ca553b921d88111fac49e534df8a375d5d437dcf2e0af8959ee
MD5 222a3e63667b01cb7f6e6330bcb5dcea
BLAKE2b-256 668e9a4b34d81d2fa4cdf01d5b6f3fd96af3c6a0f45b54bd9a3ce5112e980469

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page