简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM