Clarification regarding multiple workers and thread safety #801
Replies: 7 comments
-
Multiple processes cannot share the same database instance(or non_threadsafe_component), which may cause unpredictable problems. |
Beta Was this translation helpful? Give feedback.
-
@walkor so why is it working ? 🤔 I verified from logging inside db first entry point that it's being initialized only one time when having count set to note than 1. Is creating multiple workers similar to having multiple individual processes? |
Beta Was this translation helpful? Give feedback.
-
If multiple processes share a database connection, if one process closes the database connection, other processes will be affected. |
Beta Was this translation helpful? Give feedback.
-
Non of the worker processes have the power to close connection. Is that the only issue? |
Beta Was this translation helpful? Give feedback.
-
I don't think it's the only issue. There should be other issues I don't know |
Beta Was this translation helpful? Give feedback.
-
If you use only 1 db connection for all your worker processes (and child processes), you have a bottleneck. So performance will be a big issue. |
Beta Was this translation helpful? Give feedback.
-
@joanhey I did mention it's non-thread safe. |
Beta Was this translation helpful? Give feedback.
-
Hi @walkor
If I have the following pseduo code.
To my understanding, which might be wrong, $w->count should be 1, however, I did try setting the count to 2 or more, and couldn't observe any failures/issues however the performance definitely is much better.
My question is, given that I instantiate the non-thread-safe DB instance one time, is it OKAY/SAFE to increase Workerman's thread/child count without issues?
Beta Was this translation helpful? Give feedback.
All reactions