App Engine 调度程序何时使用新线程与新实例? [英] When does the App Engine scheduler use a new thread vs. a new instance?

查看:13
本文介绍了App Engine 调度程序何时使用新线程与新实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在我的 app.yaml 文件中设置了 threadsafe: true,那么控制何时创建新实例来服务请求的规则是什么?将在现有实例上创建一个新线程?

If I set threadsafe: true in my app.yaml file, what are the rules that govern when a new instance will be created to serve a request, versus when a new thread will be created on an existing instance?

如果我有一个应用程序对每个请求执行一些计算密集型的事情,多线程会给我带来什么吗?也就是说,一个实例是多核实例还是单核实例?

If I have an app which performs something computationally intensive on each request, does multi-threading buy me anything? In other words, is an instance a multi-core instance or a single core?

或者,是否只有在现有线程等待 IO 时才会启动新线程?

Or, are new threads only spun up when existing threads are waiting on IO?

推荐答案

以下规则集当前用于确定给定实例是否可以接受新请求:

The following set of rules are currently used to determine if a given instance can accept a new request:

if processing more than N concurrent requests (today N=10): false
elif exceeding the soft memory limit: false
elif exceeding the instance class CPU limit: false
elif warming up: false
else true

以下总 CPU/核心限制当前适用于每个实例类:

The following of total CPU/core limits currently apply to each instance classes:

CLASS 1: 600MHz 1 core
CLASS 2: 1.2GHz 1 core
CLASS 4: 2.4GHz 1 core
CLASS 8: 4.8GHz 2 core

所以只有 B8 实例可以并行处理最多 2 个完全 CPU 绑定的请求.

So only a B8 instance can process up to 2 fully CPU bound requests in parallel.

为实例类

设置threadsafe: true (Python) 或true (Java)8 不允许在单个实例上并行处理多个 CPU 绑定请求.

Setting threadsafe: true (Python) or <threadsafe>true</threadsafe> (Java) for instances classes < 8 would not allow more than one CPU bound requests to be processed in parallel on a single instance.

如果您没有完全受 CPU 限制或执行 I/O,Python 和 Java 运行时将产生新线程来处理最多 10 个并发请求的新请求,threadsafe: true

If you are not fully CPU bound or doing I/O, the Python and Java runtime will spawn new threads for handling new request up to 10 concurrent requests with threadsafe: true

还要注意,尽管 Go 运行时是单线程的,但它确实支持并发请求:它将为每个请求生成 1 个 goroutine,并在执行 I/O 时在 goroutine 之间产生控制.

Also note that even though the Go runtime is single threaded, it does support concurrent requests: It will spawn 1 goroutine per requests and yield control between goroutines while they are performing I/O.

这篇关于App Engine 调度程序何时使用新线程与新实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆