workerman icon indicating copy to clipboard operation
workerman copied to clipboard

How i can use shared memory in workerman?

Open mrAndersen opened this issue 2 years ago • 7 comments

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?

mrAndersen avatar Apr 29 '22 17:04 mrAndersen

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 avatar Apr 30 '22 14:04 walkor

@walkor thank you for information!

mrAndersen avatar Apr 30 '22 14:04 mrAndersen

@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 avatar May 02 '22 14:05 cayolblake

@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.

mrAndersen avatar May 02 '22 14:05 mrAndersen

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.

cayolblake avatar May 02 '22 14:05 cayolblake

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.

cayolblake avatar May 03 '22 02:05 cayolblake

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 ?

isayeter avatar Feb 25 '24 21:02 isayeter