Python 中的延迟处理
我正在尝试以非阻塞方式编写事件,以免减慢我们现有的任何进程。似乎有两个可用选项:
还有其他选项吗?有人有这方面的经验吗?
背景:我们计划将事件写入 Amazon 的 CloudWatch 服务,我很担心关于执行 PUT 请求的延迟。如果这改变了答案,我实际上并不那么担心丢失一些 PUT(我们正在编写事件用于警报目的,无论如何它们都会在一周后被清除)。
I'm trying to write events in a non-blocking fashion so as not to slow down any of our existing processes. It seems like the two options available are:
Are there other options. Anybody have experience with this?
Background: We're planning to write events to Amazon's CloudWatch service and I'm concerned about latency from doing the PUT request. I'm not actually so concerned about losing a few PUTs if that changes the answer (we're writing the events for alerting purposes and they'll all be purged after a week anyway).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果日志记录适合您的应用程序(听起来如此),那么它应该比使用twisted更简单。您可以登录到内存中的线程安全队列,并有一个单独的线程(或多个)从中提取并推送到云。
也就是说,Twisted 可能更快,或者至少更具可扩展性,但是,特别是如果您不了解的话,学习曲线会更陡峭。
如果线程方法达到限制,您可以随时将日志处理程序切换为使用twisted,而无需更改应用程序的界面,这就是我将如何开始,并介绍一个简单的方法和基础。
If logging fits your application, and it sounds so, it should be simpler than using twisted. You could log to a thread safe queue in memory and have a separate thread (or several) pull from it and push to the cloud.
That said, twisted may be faster or at least more scalable, but, especially if you don't know it, with a steeper learning curve.
If the threads approach hits limits you can always switch your logging handler to use twisted, without changing your interface to the app, so that's how I would start, with a simple approach and bases covered.
这对于 gevent 来说是微不足道的(只需在单独的 greenlet 中执行 PUT 并修补套接字)。
This would be trivial with gevent (just do the PUT in a separate greenlet and have socket patched).