Shared memory between requests #124
Replies: 2 comments 1 reply
-
Not sure about the purpose of the design in your demo code. Workers don't share the memory. You should take a look about how it works in Swoole: |
Beta Was this translation helpful? Give feedback.
-
Hi @albertcht, Thanks for the reply. In short: I need to cache properties in a high performance local cache or memory cache using a Redis pub/sub connection. With the cache being in memory. I guess I could use swoole tables cache for this. I'm working on a high traffic queue. I will receive about 100.000 requests tot my store in a few seconds. I need to assign them an incremental id (or timestamp) while keeping count of how many people are trying to get in my store. It's not important that the incremental id's are shared across multiple pods, but it would be very nice if they were incremental across workers within the same pod. In the background I want to sync statistics, settings and the state of the queue between multiple kubernetes pods using redis pub/sub, but only one connection for each pod and not one connection for each worker. This connection could then update the necessary static counters or using a singleton or array cache. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Check List
not enough info
will be ignored and closed after 3 days.Content
For a high performance application I need shared memory between workers, and between multiple instances.
In my example I'm using a simple counter.
After a quick test I notice that (within requests), both the array cache driver and static properties are a working method of achieving this.
I need to update this counter regularly using a Redis pub/sub connection.
I setup a Listener object, registered it in the listener.php config and update the field using cache, updating a static variable, but both do not work.
Controller:
Inside listener with
Hyperf\Framework\Event\OnStart
event:The redis process can keep track of the counter. But the requests can't.
It looks like all the requests across the workers have shared memory, but the OnStart event is triggered in another process with it's own memory.
What's the best way to insert this counter property in the memory of the worker processes?
Beta Was this translation helpful? Give feedback.
All reactions