当我在烧瓶中设置选项app.run(threaded=True))时,我的服务可以处理多个并发请求。但是,我的服务似乎会消耗尽可能多的CPU资源来处理多个并发请求。是否有限制或控制我的应用程序使用的资源?
发布于 2016-12-09 07:27:08
您可以尝试使用资源模块。取自这个职位。你会为CPU做这样的事情。这是在资源模块上的页面。
import resource
sec = 60 * 60 # this is one hour of time.
resource.setrlimit(resource.RLIMIT_CPU, sec)注意,这会改变CPU上进程允许的时间(以秒为单位)。如果要限制进程的堆栈/堆大小,则必须使用resource.RLIMIT_STACK和resource.RLIMIT_HEAP。这些都是以字节为单位的,所以代码看起来应该是这样的。
import resource
mem = 1024 * 1024 # this is one megabyte, you want much more than this normally
resource.setrlimit(resource.RLIMIT_STACK, mem)
resource.setrlimit(resource.RLIMIT_HEAP, mem)https://stackoverflow.com/questions/41054898
复制相似问题