script-server icon indicating copy to clipboard operation
script-server copied to clipboard

Add seperate backend worker with queuing

Open enissay14 opened this issue 7 years ago • 2 comments

It would be good to separate the web app from the backend who runs the script. For example, having a Celery app with Redis for queuing scripts.

This would allow the update/restart the app without interrupting scripts and will also help scale without interruption (just add more workers and keep using the main web app as a master)

Some thoughts on what needs to be done to make it work:

  • A database needs to be added to keep tracking of the status of the jobs and where are they running.

  • The socket implementation needs to be changed also to keep the webview updated.

enissay14 avatar Apr 02 '19 23:04 enissay14

Hi @enissay14, thanks for the ticket and nice description. I was thinking about dedicated workers, but to run scripts on different machines (with different environments).

I like your idea with the benefit of a separate web server maintenance. However there are a couple of concerns:

  • scalability shouldn't be a great issue. All the scripts are run in separate processes anyway. The role of script server is to redirect output to UI and to log the output
  • I think that queuing doesn't fit Script server idea: users of a script should have quick and convenient way to interact with scripts. Queuing their requests will make them wait (without any good reason, as for me)
  • maintenance of the workers and the server will be complicated: the versions should be probably updated simultaneously, and additionally there should be secure communication layer between workers and the server (so nobody should ever be able to access the workers directly).

So for me, the main feature of dedicated workers would be their execution on different servers (with a different environment). It would also help to make it more Docker-friendly. Without this feature, I thing there are more drawbacks than benefits.

So, considering distributed workers feature, simple maintenance and other points from above, I would think about smth like this:

  1. All the workers should be managed (starting/stopping workers, starting a script, etc.) by Script server
  2. The only responsibility of the workers will be to run script processes and keep stdin/stdout
  3. Script server will "gather" stdin/stdout from the workers and redirect to the user + log them
  4. Communication the workers should be done via a secured socket, so workers wouldn't accept connections from any other sources.
  5. No queuing: workers should be able to run multiple script instances in parallel (as script server does).
  6. I think there should be a limit of 1 worker per host (don't see any reason to have more) to open only a single port for communications.
  7. UI communication to Script server stays untouched. It will always connect to the centralized server (which will still be web + backend)

I guess this differs quite a lot from your proposal, but I would really prefer to avoid unnecessary distribution (which always makes things much more complicated and unreliable). May be some of my ideas are wrong or not good enough. I'm open for discussions :)

bugy avatar Apr 03 '19 08:04 bugy

Hi @bugy I like your ideas actually. I think we can avoid Queuing the jobs you have a point there.

In terms of scalability, my concern is when you have parallel script executions that overload the server. Having the work done by separate workers will let us auto-scale without interruption of the server (by spawning a new worker instance for example)

And of course, I was thinking a docker-compose way of doing it where there would be 2 separate docker images of for the web app and another one for the worker. I don't necessarily see them on different servers, even if it can be done using this setup.

In terms of implementation few things came to my mind:

  • Maybe scripts need to be defined as docker image which runs the actual script to completion (with there params passed as env variables) - This will be good if you have multiple scripts that need different environments: just need 1 worker server. Otherwise, you will need 1 worker server per environment...
  • Worker server run those docker images and provide constant secure tunneling of stdin/stout
  • A way for new workers to be discovered (maybe the host can be manually added in admin screen of the web app)
  • A way of load balancing, workers must be able to provide a status of capacity left (CPU usage or something like that)

Please tell me if this advances the reflexion about this feature, it seems like quite the work. I am happy to help :)

enissay14 avatar Apr 05 '19 20:04 enissay14