Coder Social home page Coder Social logo

Comments (4)

bdarnell avatar bdarnell commented on September 25, 2024

I don't think this is related to the 100% cpu, but you should use asyncio.sleep instead of time.sleep (https://www.tornadoweb.org/en/stable/faq.html#id2).

Which version of python are you using?

How exactly are you setting up multi-process mode? I assume both of these profiles are from a child process?

from tornado.

zhubijia avatar zhubijia commented on September 25, 2024

I don't think this is related to the 100% cpu, but you should use asyncio.sleep instead of time.sleep (https://www.tornadoweb.org/en/stable/faq.html#id2).

I just use time.sleep to simply represent my real logic, which is actually a slow query of MySQL. If the user feels it is slow and closes the page, the CPU will rise to 100%. If the user is willing to continue waiting, it is normal. I shielded a machine and used requests to set different timeouts of 5s and 40s to simulate request verification, which was consistent with the above performance. When I set the timeout to 5 seconds, the CPU was abnormal while the server continued to execute, and there were no other requests at this time. When the timeout was set to 40s, the CPU was normal, and there were no other requests.

Which version of python are you using?

Python 3.6, in docker environment.

How exactly are you setting up multi-process mode? I assume both of these profiles are from a child process?

app = tornado.web.Application(APP_URLS)
http_server = tornado.httpserver.HTTPServer(app, xheaders=True)
http_server.listen(8080)
http_server.start(num_processes=2)

from tornado.

bdarnell avatar bdarnell commented on September 25, 2024

http_server.start is used with http_server.bind, not listen. listen is only for single-process mode and I think it might be able to cause problems like this when used in multi-process mode. Look at the docs for add_sockets multi-process mode in the HTTPServer docs: https://www.tornadoweb.org/en/stable/httpserver.html#tornado.httpserver.HTTPServer (use add_sockets instead of bind/start because bind/start is deprecated for future versions of python)

from tornado.

zhubijia avatar zhubijia commented on September 25, 2024

Thanks, I tried the above method and it works fine now!

from tornado.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.