简体   繁体   English

Python / mod_wsgi服务器全局数据

[英]Python/mod_wsgi server global data

I have been looking into different systems for creating a fast cache in a web-farm running Python/mod_wsgi. 我一直在研究在运行Python / mod_wsgi的Web场中创建快速缓存的不同系统。 Memcache and others are options ... But I was wondering: Memcache和其他人都是选择...但我想知道:

Because I don't need to share data across machines, wanting each machine to maintain a local cache ... 因为我不需要跨机器共享数据,所以希望每台机器都维护本地缓存......

Does Python or WSGI provide a mechanism for Python native shared data in Apache such that the data persists and is available to all threads/processes until the server is restarted? Python或WSGI是否为Apache中的Python本机共享数据提供了一种机制,以便数据持续存在并且可供所有线程/进程使用,直到重新启动服务器为止? This way I could just keep a cache of objects with concurrency control in the memory space of all running application instances? 这样我就可以在所有正在运行的应用程序实例的内存空间中保留具有并发控制的对象缓存?

If not, it sure would be useful 如果没有,它肯定会有用

Thanks! 谢谢!

This is thoroughly covered by the Sharing and Global Data section of the mod_wsgi documentation. mod_wsgi文档的“ 共享和全局数据”部分对此进行了全面介绍。 The short answer is: No, not unless you run everything in one process, but that's not an ideal solution. 简短的回答是:不,除非你在一个过程中运行所有东西,但这不是一个理想的解决方案。

It should be noted that caching is ridiculously easy to do with Beaker middleware , which supports multiple backends including memcache. 应当指出的是, 缓存是可笑容易烧杯中间件做 ,它支持多个后端,包括内存缓存。

There's Django's thread-safe in-memory cache back-end, see here . 有Django的线程安全的内存缓存后端,请看这里 It's cPickle-based, and although it's designed for use with Django, it has minimal dependencies on the rest of Django and you could easily refactor it to remove these. 它是基于cPickle的,虽然它设计用于Django,但它对Django的其余部分的依赖性很小,你可以很容易地重构它来删除它们。 Obviously each process would get its own cache, shared between its threads; 显然,每个进程都会获得自己的缓存,在其线程之间共享; If you want a cache shared by all processes on the same machine, you could just use this cache in its own process with an IPC interface of your choice (domain sockets, say) or use memcached locally, or, if you might ever want persistence across restarts, something like Tokyo Cabinet with a Python interface like this . 如果您希望同一台计算机上的所有进程共享一个缓存,您可以在自己的进程中使用此缓存,使用您选择的IPC接口(例如域套接字)或在本地使用memcached ,或者,如果您可能想要持久化跨重启,像东京柜用像Python接口

I realize this is an old thread, but here's another option for a "server-wide dict": http://poshmodule.sourceforge.net/posh/html/posh.html (POSH, Python Shared Objects). 我意识到这是一个旧线程,但这是“服务器范围的dict”的另一个选项: http//poshmodule.sourceforge.net/posh/html/posh.html (POSH,Python共享对象)。 Disclaimer: haven't used it myself yet. 免责声明:我自己还没有用过它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM