Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache WSGI IPC

I have a Django app running behind an Apache/ModWSGI server with multiple processes.

I'd like to implement a feature where settings, such as model field labels, are stored in the database and dynamically updated in the UI.

To avoid this from slowing down each Django request, I don't want to pull all model field names from the database in each request. I just want to pull them from the Django instance first loads, and then update them once if they're changed.

It's pretty trivial to create a Django signal to hook onto my field name model, and dynamically update the field's "verbose name" value in memory. However, that only updates the process for that request. The other N-1 processes being run by Apache will still be using the old value.

How would I tell the other processes to update a specific setting?

Ideally, I want a very light-weight interprocess communication method to push a "field name changed" event to the other processes, which they would then consume and do that lightweight task of updating the value in their memory.

There are a ton of multiprocessing tools for Python, but are there any specific ones for a task like this, especially for Django+Apache?

I find it hard to believe no one's ever had to make their ModWSGI processes talk to each other, but when I search for Django/Python IPC tools, I either get the tutorials for the standard multiprocessing package, or message consuming services like Celery, which aren't quite what I'm looking for.

I could bake something myself using a custom thread in the WSGIHandler that reads/writes from a shared queue, but I don't want to reinvent the wheel.

like image 452
Cerin Avatar asked Jun 15 '26 04:06

Cerin


1 Answers

We have the same problem for github.com/digitalfabrik/integreat-cms. We need a mutex across the different processes. Our approach is to use the Django Cache with a Redis Back End. While not as good as the native Python MP functionality, it is a valid approach.

Better ideas are welcome though.

like image 91
Sven Avatar answered Jun 16 '26 17:06

Sven



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!