Re:Functools – The Power of Higher-Order Functions in Python
by matsemann on Friday July 09, 2021 @02:47AM
(#27781068)
Because of the GIL the cache is often pretty useless on a webserver anyway, as each and every request gets a different process not sharing that cache. So then one has to deploy Redis in addition and complicate the stack. Makes sense with a shared cache when there's multiple instances, but often it's overkill. Having to go "external" to fetch the data I might as well not cache anything.
[ Parent
| on HN ]
Re:Functools – The Power of Higher-Order Functions in Python
by judofyr on Friday July 09, 2021 @04:39AM
(#27781633)
> each and every request gets a different process not sharing that cache
What web server is this? I’ve never heard about this behavior before.
Re:Functools – The Power of Higher-Order Functions in Python
by matsemann on Friday July 09, 2021 @06:17AM
(#27782207)
I might have been a bit unclear. Not every request gets a new process, but there are a pool of processes. For instance gunicorn will maybe have ~20 processes ready to serve requests, with a main process sending work to the workers. Since it's different processes, there is very little communication or shared resources between them. It's almost as if you're running your main entry point multiple times in different terminals, just with gunicorn managing it for you.
This is different than for instance java, which there is one process and then multiple threads. But because of the GIL in python, only one thread can ever run at the same time (in the same process), therefore one has to launch multiple instances/processes of the application.
Re:Functools – The Power of Higher-Order Functions in Python
by zbentley on Friday July 09, 2021 @09:25AM
(#27783427)
That's true, cache utilization declines as a function of your processing parallel (and in gunicorn/celery, your max-requests-per-process-before-suicide setting). Cached properties still can help a good deal though, especially when coupled with a) careful prefork initialization of cached data and b) even more careful use of multiprocessing's little-known shared memory interface which really does allow caches to be shared, without read locks, between multiple processes.
Re:Functools – The Power of Higher-Order Functions in Python
by sreeramb93 on Friday July 09, 2021 @05:43AM
(#27782012)
Exactly. How do these caches behave when python is used as a webservice in a multi-process multi-thread setting.
What if we have multiple containers running the same service and load balanced using an ingress controller?
Local Caches are a headache in such a scenario.
Best pattern I have read is use a cache as a sidecar in a pod. I feel that scales very well.