Celery workers and shared memory space

1,043 views
Skip to first unread message

alonn

unread,
Jun 23, 2014, 7:56:13 PM6/23/14
to pywe...@googlegroups.com
I'm not sure how celery workers share memory space - if they do at all. 

My problem: I have a system wide time. set by a Clock class.. and set from outside (another service is controlling it) and everything in the django process that uses time - is using it. But what about celery workers? I can pass a celery task to update the Clock in the worker process. But I don't have any guarantee what worker would consume that task and no way to force all workers to consume a "set_time" task. I'm not even sure the worker process is consistent and not being restarted from time to time by celeryd. 

Yes, I can probably share this kind of config through redis (or similar) but this is quite ugly, and won't address some more complex scenarios ahead.

And I know I can send workers a "remote control command" http://celery.readthedocs.org/en/latest/userguide/workers.html#remote-control. But that wouldn't solve the problem of new workers spawning without the "knowledge" of previous workers that received the command. 

Any ideas?  Thanks!

Yuval Adam

unread,
Jun 24, 2014, 1:45:52 AM6/24/14
to pywe...@googlegroups.com
Synchronous workers do not share memory space at all, they are completely separate processes.

Your requirement is to add state to each worker, and naturally that is something that isn't easy to do, neither is it scalable.
In your link you have a `broadcast()` function that seems to fit the bill, but again, why not enable workers to share the knowledge via a shared cache such as redis (which you might already be using as a broker)?

Of course, since workers (web or task) can always go up and down at any time, you should carefully choose how you implement statefullness in them, and make sure to handle all the edge cases.
--
You received this message because you are subscribed to the Google Groups "PyWeb-IL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyweb-il+u...@googlegroups.com.
To post to this group, send email to pywe...@googlegroups.com.
Visit this group at http://groups.google.com/group/pyweb-il.
For more options, visit https://groups.google.com/d/optout.

Evgeny Zislis

unread,
Jun 24, 2014, 1:53:49 AM6/24/14
to pywe...@googlegroups.com
To synchronize clocks, use ntp. To synchronize a certain offset (aka timezone) during a work pipeline, send the offset with your work messages and rely on the local synchronized clock as your correct clock.

If you think you can write a better clock synchronization than ntp - you are wrong, just don't do it.

Evgeny Zislis


We invite you to join Operations Israel and Atlassian Israel
Facebook groups on.fb.me/Ops-IL and on.fb.me/Atl-IL


--

alonn

unread,
Jun 24, 2014, 4:08:51 AM6/24/14
to pywe...@googlegroups.com
Hey Evgeny: Actually the clock was an example for a shared state. so ntp isn't a magic answer. only for time,.

But just fo the sake of it: I use a system clock, since I need to manipulate system time in integration and e2e tests. SInce I don't want to fiddle with system clock on developer machines. I abstract time into a Clock class . which has setters and getters, and thus becomes part of the app state

alonn

unread,
Jun 24, 2014, 4:09:21 AM6/24/14
to pywe...@googlegroups.com
Thanks yuval, looks like the path to take
Reply all
Reply to author
Forward
0 new messages