Jammy Posted October 9, 2019 Share Posted October 9, 2019 Hi all, I know that google may answer this question but actually it's not as straight forward, since so many people say so many different things. My question is, what is the maximum amount of web workers I SHOULD create for my game. I can see some posts saying that you should only create one worker per CPU core, but this just doesn't seem right. My webworkers do seem to increase throughput even after the count of them is higher than my CPU cores. My game may run on Phone/Tablet or Desktop so the maximum amount of webworkers I SHOULD create would probably vary depending on the device/client. Would really appreciate thoughts/tricks and any links to write-ups. I would REALLY appreciate any write-up on just how webworkers generate their threads in the OS and just how many are effective on a single core machine vs dual core machine+ For consideration, the webworkers I am using are for pathfinding and I have a fair few AI, so the more workers I can achieve, the more AI will all be moving at once. Thanks, Jam Quote Link to comment Share on other sites More sharing options...
bruno_ Posted October 9, 2019 Share Posted October 9, 2019 Its really hard to answer to that. All devices and browsers may have different behavior in performance. I think you should use the minimum resources you need. A web worker not always generate a new thread, its asynchronous execution, but multiple workers may be running on the same thread. Try first to make your game without any web workers and test it on the devices. If the game is too slow, and when optimizing the code is no longer an option, create your first web worker. After that, test again, if one is enough good - that's it, if not continue to test one by one until you reach the desired performance. 8Observer8 1 Quote Link to comment Share on other sites More sharing options...
Jammy Posted October 9, 2019 Author Share Posted October 9, 2019 1 hour ago, bruno_ said: Its really hard to answer to that. All devices and browsers may have different behavior in performance. I think you should use the minimum resources you need. A web worker not always generate a new thread, its asynchronous execution, but multiple workers may be running on the same thread. Try first to make your game without any web workers and test it on the devices. If the game is too slow, and when optimizing the code is no longer an option, create your first web worker. After that, test again, if one is enough good - that's it, if not continue to test one by one until you reach the desired performance. I know it's a difficult one ey... So as far as testing goes I've tried some stuff but what I find is, for example, 5 workers is great for say 20 AI, but past that I want say more like 10+ workers, otherwise the AI is waiting around for other AI to calculate its path, e.g. AI 1 is calculating a path, so AI 16 is waiting for that calculation to complete before making its calculation. That is kind of a big gameplay part of the game, just how many AI I can have, since its a business simulation. This is a video of some stress testing, at 20+ workers all most AI seems okay, but anything lower than that and loads seem to wait around (which is why I don't think max workers throughput is directly tied to CPU cores... probably more threads). You mention 2 or more webworkers may end up on the same thread, this may start to explain things more. Are you aware of any writeups or any experience with how it decides when a new thread is made, or when to share one? One thing I may just have to come up with is a way to identify the client/device and then launch an appropriate amount of workers for that.. and then tweak gameplay to match Cheers, jammy Quote Link to comment Share on other sites More sharing options...
bruno_ Posted October 10, 2019 Share Posted October 10, 2019 21 hours ago, Jammy said: Are you aware of any writeups or any experience with how it decides when a new thread is made, or when to share one? I don't know any link that explains this directly. But web workers are not part of javascript. Web workers are a browser feature that you can interact via javascript. This means that when you want to process your code in the background, you tell your browser using a javascript api to do your work and pass back the result in the end. This background process works the same way as any background thread your browser executes. If you execute 100 web workers, the browser will use its web worker pool to execute your workers, the pool may have 10, 20, ?? threads, but probably not 100. 8Observer8 and Jammy 2 Quote Link to comment Share on other sites More sharing options...
Jammy Posted October 10, 2019 Author Share Posted October 10, 2019 3 hours ago, bruno_ said: I don't know any link that explains this directly. But web workers are not part of javascript. Actually that really helped, I had completely ignored that fact... This is definitely a "per-browser" thing and already I've dug up some content from Chromium. Thanks for the help! https://docs.google.com/document/d/1i3IA3TG00rpQ7MKlpNFYUF6EfLcV01_Cv3IYG_DjF7M/edit#heading=h.7smox3ra3f6n bruno_ 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.