workerman
workerman copied to clipboard
How i can use shared memory in workerman?
Hi. Any suggestions about how i can organize shared memory between worker processes in workerman? What classes\abstractions should i use? Any analogue for std::mutex or std::lock_guard c++ mechanics?
I need to keep piece of data between workerman processes and write\read to it. Am i correct saying that this is not implemented?
As long as i understood each callback for onMessage, onConnect, e.t.c can and will be called in different worker sub process thus providing parallelism, this is correct?
Workerman does not provide a shared memory interface. These links may help you https://www.php.net/manual/zh/book.sem.php https://www.php.net/manual/zh/book.shmop.php
As long as i understood each callback for onMessage, onConnect, e.t.c can and will be called in different worker sub process thus providing parallelism, this is correct?
Each sub process will handle its own onMessage onConnect etc callback independently, and they will not communicate with each other.
@walkor thank you for information!
@mrAndersen I took a crack at this before trying out almost al possible techniques, and non was performing well and had a humongous overhead.
Using APCu was the fastest way of all already slow options. I ended up weighing the benefit of using multiple workers and ended up with a single worker.
@cayolblake Yeah, unfortunately after couple of days trying to implement clean solution, I was forced to abandon workerman in flavor of C++ application and "true" threads with "true" shared memory. Using single worker is basically the same if running single script by executing php my_script.php
and opening single socket connection inside.
Well, unless you're using Boost for your C++ development, my trials and benchmarking couldn't find a C++ web/http framework that outperforms workerman, they were always slower by %20 on average.
Just to be clear referring to my last reply, I was comparing single threaded mode C++ web frameworks implementations versus workerman/PHP when comparing and using wrk
and ab
for benchmarking.
Has there been any progress on resolving this issue? I am encountering the same difficulty and would prefer not to limit myself to using only one worker. I require a mechanism for shared objects that can be utilized across different worker processes with distinct PIDs. @mrAndersen did you tried https://www.php.net/manual/en/book.shmop.php ?