title: Tornado performance issue with MySQLand Redis
body: <p>I have a tornado server running with MySQL for DB and Redis for cache. I am using web socket to send/receive data. My code is like this: <br></p>
  
  <p><strong>Server</strong><br></p>
  
  <pre><code>import logging
  import os.path
  import uuid
  import sys
  import json
  
  import tornadis
  import tormysql
  import tornado.escape
  import tornado.ioloop
  import tornado.options
  import tornado.web
  import tornado.websocket
  from tornado import gen
  from tornado.concurrent import Future
  from tornado.options import define, options
  
  @gen.coroutine
  def getFromDB(query):
      with (yield dbPool.Connection()) as conn:
          with conn.cursor() as cursor:
              yield cursor.execute(query)
              datas = cursor.fetchall()
              return datas
      return None
  
  @gen.coroutine
  def getFromCache(cmd):
      pipeline = tornadis.Pipeline()
      pipeline.stack_call(cmd)
      with (yield cachePool.connected_client()) as singleClient:
          redisResult = yield singleClient.call(pipeline)
          if isinstance(redisResult, tornadis.TornadisException):
              print("Redis exception: %s"%(redisResult))
          else:
              return redisResult
  
  async def getData(dbQuery, cacheQuery):
      waitDict = {}
      if dbQuery:
          waitDict['db'] = getFromDB(dbQuery)
      if cacheQuery:
          waitDict['cache'] = getFromCache(cacheQuery)
      resultList = []
      if len(waitDict) &gt; 0:
          await gen.multi(waitDict)
          if 'db' in waitDict:
              dbRes = waitDict['db'].result()
              if dbRes:
                  for eachResult in dbRes:
                      changeRes = someFunct(eachResult) 
                      resultList.append(changeRes)
          if 'cache' in waitDict:
              cacheRes = waitDict['cache'].result()
              if cacheRes:
                  for eachResult in cacheRes:
                      changeRes = someFunct(eachResult) 
                      resultList.append(changeRes)
      return resultList
  
  class SocketHandler(tornado.websocket.WebSocketHandler):
      SUPPORTED_METHODS = ("GET")
  
      def open(self):
          print("Socket open:%s"%(self))
  
      def on_close(self):
          print("Socket closed:%s"%(self))
  
      async def on_message(self, inp):
          if requestForData:
              ret = await getData(dbQuery, cacheQuery)
              self.write_message(ret)
  
  class Application(tornado.web.Application):
      def __init__(self):
          handlers = [
              (r"/sock", SocketHandler),
          ]
  
  define("port", default=8000, help="run on the given port", type=int)
  tornado.options.parse_command_line()
  app = Application()
  app.listen(options.port)
  print("PORT:%s"%(options.port))
  tornado.ioloop.IOLoop.current().start()
  </code></pre>
  
  <p>I am using <code>tornadis</code> for Redis and <code>tormysql</code> for MySQL.<br>
  I am running this setup on amazon linux instance m5.large with 2vCPUs memeory:8Gib.<br></p>
  
  <p><strong>Client</strong><br></p>
  
  <p>I am trying to simulate the traffic using web socket. The code is like this:<br></p>
  
  <pre><code>import sys
  import json
  import asyncio
  import websockets
  
  def getData():
      for i in range(100):
          async with websockets.connect(SOCKET_URL, extra_headers=extraHeaders) as websocket:
              for i an range(100):
                  await websocket.send("get data")
                  reply = await websocket.recv()
                  print(reply)
  
  asyncio.get_event_loop().run_until_complete(getData())
  </code></pre>
  
  <p>I am running multiple instance of the client.<br>
  The server is running good but its able to handle only 25 connections. After 25 connections the delay for the reply from the server increases. I want server to reply to be very fast. How do I decrease the delay for the response? So is there any problem in the code?</p>