python - There is no improvement when changing from sync to async handler -


i compared sync , async version handler, , there no improvement on 'response time' etc metrics, how debug in situation?

handler

@gen.coroutine def get(self):     calendar = calendar()     response = yield (calendar.events())     self.write(response)     self.finish() 

model

class calendar(object):     @return_future     def events(self, callback=none):         result = # mysqldb operation         callback(result) 

basic information:

cpu: 1 core dababase: mysqldb 

@return_future doesn't make sense here. used adapt functions asynchronous (and use callbacks) can yielded coroutine. there little reason ever use in modern tornado application; use @gen.coroutine everywhere.

to run mysqldb operation without blocking ioloop, must run on separate thread. install futures package , create threadpoolexecutor:

executor = threadpoolexecutor(4)  class calendar:     @gen.coroutine     def events(self):         result = yield executor.submit(mysqldb_operation)         raise gen.return(result) 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -