我在我的python项目中使用App Engine模块.(https://developers.google.com/appengine/docs/python/modules/#Python_Background_threads)
我也在m项目中使用频道:https://developers.google.com/appengine/docs/python/channel/
我想将连接/断开的帖子消息('/ _ah/channel/connected /','/ _ah/channel/disconnected /')指向我的api模块.现在我无法让它们显示在任何模块中(默认或api)
的app.yaml
api_version: 1
application: integrate
version: 1-0-0
runtime: python27
threadsafe: true
builtins:
- deferred: on
libraries:
- name: pycrypto
version: "2.6"
handlers:
- url: /favicon\.ico
static_files: static/favicon.ico
upload: static/favicon\.ico
- url: /admin/.+
script: src.default.main.app
login: admin
- url: /.*
script: src.default.main.app
Run Code Online (Sandbox Code Playgroud)
api.yaml
api_version: 1
application: integrate
module: api
version: 1-0-0
runtime: python27
threadsafe: true
inbound_services:
- channel_presence
builtins:
- deferred: on
libraries:
- name: pycrypto
version: "2.6" …Run Code Online (Sandbox Code Playgroud) 我在我的python项目中使用App Engine模块.(https://developers.google.com/appengine/docs/python/modules/#Python_Background_threads)
我也在m项目中收到电子邮件:https: //developers.google.com/appengine/docs/python/mail/receivingmail
我想将电子邮件定向到我的工作模块而不是默认模块.为此,我的worker.yaml具有以下设置
worker.yaml
api_version: 1
application: integrate
module: worker
version: 1-0-0
runtime: python27
threadsafe: true
inbound_services:
- mail
builtins:
- deferred: on
handlers:
- url: /admin/.+
script: src.worker.main.app
login: admin
- url: /_ah/mail/.+
script: src.worker.main.app
login: admin
- url: /.*
script: src.worker.main.app
Run Code Online (Sandbox Code Playgroud)
的app.yaml
api_version: 1
application: integrate
version: 1-0-0
runtime: python27
threadsafe: true
builtins:
- deferred: on
handlers:
- url: /admin/.+
script: src.default.main.app
login: admin
- url: /.*
script: src.default.main.app
Run Code Online (Sandbox Code Playgroud)
我甚至尝试添加dispatch.yaml
application: integrate …Run Code Online (Sandbox Code Playgroud) 我正在使用Google App Engine(Python)实时处理一些事件消息.总之,我有100多个任务,我需要在消息进入时快速运行.我尝试了一些方法(延迟库,线程),我认为最好的解决方案是使用任务队列并异步将这些任务添加到队列中我想要.这是我正在做的一个例子.
tasks = []
task = Task(url=url_for('main.endpoints_worker'),params={'id': id})
tasks.append(task.add_async(queue_name='event-message'))
for task in tasks:
task.get_result()
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我的大部分时间都花在将这些任务添加到队列中.有没有办法加快速度?有更好的方法吗?
说实话,每次运行时都会遇到很多不同的时间.有时我大约100ms(这可能会很好),但有时我大约1s.
我本以为扩展工作会更快,但批量添加到任务队列执行.以下是我所看到的建议方法:
tasks = [Task(url=url_for('main.endpoints_worker'),params={'id': id}) for id in id_list]
rpc = Queue('event-message').add_async(tasks)
rpc.get_result()
Run Code Online (Sandbox Code Playgroud)
更新:由于添加到队列时100任务限制,我需要再次检查此问题. 通过批量创建我的任务(100个组),我已经大大提高了代码的吞吐量,但我仍然不明白为什么将多组任务添加到队列这么快就会减慢速度.一个任务queue.add_async运行<40毫秒没问题.当我做2个或更多queue.add_async时,那个时间变慢了.我很想知道为什么?另外我怎么解决这个问题?
当我在没有异步的情况下添加批量任务时,每个任务都需要<40ms.为什么在使用异步时它们需要更长的时间?
另一个更新我认为问题可能与争用相关,但即使我将这些任务中的每一个添加到不同的队列,我也会得到相同的结果.