Anirban Roy Das
Anirban Roy Das

Reputation: 262

Should I use MySQL Database Pool or a Single Persistant Connection in Tornado

If I am using async mysql library like Tornado-MySQL(by PyMySQL) or TorMySQL or Asynctorndb which are async libraries to do MySQL database calls so to not block the IOLoop.

What I want to know is in what way should I use them in my given scenario?

Scenario : Suppose I am running my Tornado Web Application behind Nginx as Load Balancer. The whole setup is in AWS EC2 instance. Now Nginx, Tornado, MySQL all running in the same host. The Tornado Instances are run with Supervisord as the process management program.

If the no. of VCPUs of my EC2 instance are x, and no. of Nginx worker processes are y and no. of Tornado Instances are z, then given this condition, how should I use my async MySQL library?

  1. Should I create a single persistant connection in my Application initialization which will be passed to all the handlers? Or should I use a connection pool?

  2. Considering the fact that what will be the effect of each method with the no. of Tornado Instances running.

  3. What are the advantages and disadvantages for each of the method?

Upvotes: 0

Views: 571

Answers (1)

Ben Darnell
Ben Darnell

Reputation: 22154

The "single persistent connection" strategy is for using synchronous database drivers with Tornado (in which case the IOLoop guarantees that only one request can use the connection at a time). With an asynchronous driver, multiple requests can be using the database at a time, which means you must use a connection pool.

Upvotes: 3

Related Questions