walkor / walkor/workerman

Long-running tasks blocking the WebSocket process

Open
#1,058 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
11.6k
Forks
2.2k
Avg merge
11h 30m
Merged PRs (30d)
3

Description

Until recently, we had implemented our chess functionality on two different servers: The [WebSocket server](https://github.com/chesslablab/chess-server) and the [web server](https://github.com/chesslablab/chess-api). The former was intended to run real-time tasks while the latter hosted a REST-like API for long-running tasks like database queries, ad hoc reportings, and so on, which would take a few seconds to run.

This separation of concerns was perfeclty fine.

However, at some point it was decided to get rid of the web server and try out an implementation completely based on WebSockets. All functionality, which is to say real-time operations and long-running operations, was moved to the WebSocket server. The reason being was mainly because this setup looked simpler and cheaper.

The thing is, whether using Workerman or Ratchet, the staging server has demonstrated that there is something wrong with this setup.

If two users are playing chess online (real-time) while another user is generating an ad hoc report (long-running) the two users playing online will experience a bottleneck because the report generation seems to be blocking the WebScocket process for a few seconds.

The current WebSocket server is pretty much unusable if there are a few users connected at the same time:

- [Re: While loops blocking send?](https://groups.google.com/g/ratchet-php/c/Ry4VWh-xnts)
- [ratchet event loop getting blocked](https://stackoverflow.com/questions/38824506/ratchet-event-loop-getting-blocked)
- [Is Workerman appropriate for database queries?](https://github.com/walkor/workerman/discussions/1045)

Are we missing something?

Could you please provide some guidance on how to implement long-running tasks with WebSockets? Or should we get back to the previous API implementation for the long-running tasks?

🙏 Thank you for the help, it is very much appreciated!

Contributor guide

No contributing guide indexed for this repository

Research direction

No repository files or tests are named. Start by reviewing the current Workerman WebSocket handling alongside the linked Ratchet and Workerman event-loop discussions, then compare it with the previous web-server arrangement; done would require an agreed approach for long-running database queries and report generation without blocking real-time users.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, networking
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.