Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic numproc change #177

Open
ivan1986 opened this issue Nov 30, 2012 · 59 comments
Open

Dynamic numproc change #177

ivan1986 opened this issue Nov 30, 2012 · 59 comments

Comments

@ivan1986
Copy link

This would be a great feature - command to dynamically set the numprocs variable and span or kill procrocs when it change

@wodow
Copy link

wodow commented May 10, 2014

+1!

@alphatok
Copy link

+1

1 similar comment
@krowinski
Copy link

+1

@LeoCavaille
Copy link

+1

@borfast
Copy link

borfast commented Feb 4, 2015

Do the authors have any intention of implementing this? I'm evaluating similar tools and would like to know what to count on.

@mnaberez
Copy link
Member

mnaberez commented Feb 4, 2015

No one is currently working on it but this feature could also be implemented as a plugin.

@hasbrettholt
Copy link

+1

3 similar comments
@blaskojan
Copy link

+1

@footplus
Copy link

👍

@jmspring
Copy link

+1

@mfrlin
Copy link

mfrlin commented Jun 1, 2015

How would plugin for this look like?
From what I can tell there is no way you can dynamically add processes into configuration. The only thing I can do is set up the [program:x] with numproces set to a large number. Then I can start and stop workers via XMLRPC, but I can not start more workers than what was configured.
Is this the idea of a plugin? It would be nice to have an option to increase numproces dynamically so you would not be limited by what you set in config file.

@mnaberez
Copy link
Member

mnaberez commented Jun 1, 2015

How would plugin for this look like?
From what I can tell there is no way you can dynamically add processes into configuration.

The supervisor_twiddler plugin does not adjust numprocs but it does dynamically add and remove programs. The same techniques it uses could be applied to make a plugin that adjusts numprocs.

@ralberto
Copy link

ralberto commented Feb 1, 2016

+1

4 similar comments
@tfe2012
Copy link

tfe2012 commented May 6, 2016

+1

@tautrimas
Copy link

+1

@bradcis
Copy link

bradcis commented Jun 8, 2016

+1

@axsapronov
Copy link

+1

@GameCharmer
Copy link

+1

1 similar comment
@roadrunner
Copy link

+1

@wgjak47
Copy link

wgjak47 commented Dec 18, 2016

I write a plugin supervisor_grace to solve this program forked from supervisor_twiddler. It's need to change the config file right now. I found it is complex to change the numproc online.

@FractalizeR
Copy link

Is this now done? Or can this be done via changing config file only now?

@fpetkovski
Copy link

+1

2 similar comments
@vahid-amintabar
Copy link

+1

@TheAliAbbasi
Copy link

+1

@nektru
Copy link

nektru commented Apr 29, 2018

+1

@ChqThomas
Copy link

+1

20 similar comments
@SlytherinCz
Copy link

+1

@ColaMint
Copy link

+1

@pretty
Copy link

pretty commented Dec 8, 2018

+1

@mightydok
Copy link

+1

@rogervila
Copy link

+1

@nexhub
Copy link

nexhub commented Jun 25, 2019

+1

@HattabbI4
Copy link

+1

@XMoon
Copy link

XMoon commented Oct 8, 2019

+1

@makukha
Copy link

makukha commented Nov 6, 2019

+1

@mmarynich
Copy link

+1

@yakiza
Copy link

yakiza commented Apr 20, 2020

+1

@remusnegrota
Copy link

+1

@dilip-grexit
Copy link

+1

@vladshut
Copy link

+1

@daymien
Copy link

daymien commented Feb 25, 2021

+1

@trajche
Copy link

trajche commented Feb 25, 2021

+1

@planetchili
Copy link

+1

@Qanah
Copy link

Qanah commented Jul 1, 2021

+1

@sobwoofer
Copy link

+1

@planetchili
Copy link

+1

@michaelarnauts
Copy link

Please stop this +1'ing. You're spamming 51 people every time.

Sorry for one more spam mail...

@julien6387
Copy link
Contributor

I've just done this feature in my plugin:
https://supvisors.readthedocs.io/en/0.10/xml_rpc.html#supvisors.rpcinterface.RPCInterface.update_numprocs

supervisorctl update_numprocs <program_name> <value>

It works dynamically on programs and event listeners. I did not test with real FastCGI programs but it has been implemented.
if numprocs is greater than the current value, (numprocs - current) programs are added to Supervisor. If the autostart program option is set to true, the corresponding processes are then spawned.
if numprocs is lower than the current value, the processes in excess are eventually stopped and then removed from Supervisor.

Basic configuration and tests can be found here:
https://github.com/julien6387/supvisors/tree/master/supvisors/test/test_supervisor_177

It's quite more tricky than what Mike did in supervisor_twiddler and I don't believe that I have overcomplicated things.
The relevant information is not stored in the Supervisor internal options structure - unless I missed it - so I had to re-realize the ServerOptions to get it without reinventing the wheel.

The only drawback in doing this from a plugin is that an event listener cannot subscribe to the new events (PROCESS, PROCESS_ADDED, PROCESS_REMOVED) in its configuration file as these events won't be recognized by Supervisor. The listener has to subscribe to EVENT (yeah, sob).
It looks like adding new event types would require a - very simple - update of Supervisor itself. Unfortunately, I did not find a way to inject them from the plugin before the program sections are evaluated in the ServerOptions.

Mike, for future versions of Supervisors, what about adding a CUSTOM_EVENT_TYPE / PLUGIN_EVENT_TYPE (empty class CustomEventType / PluginEventType inheriting from Event) to support such feature ? Not perfect but that's a simple way to reduce the events. Ideally a plugin callback to be called before the program sections are evaluated would be nice.

@Dmytro-Shvetsov
Copy link

Hello, is anyone still working on this feature?
Or can you suggest the most appropriate workaround to provide numproc dynamically?

@GameCharmer
Copy link

@Dmytro-Shvetsov if you're running separate config files for each process, instead of using numprocs, just duplicate your configs with _1, _2, _3, etc at the end. Stop all processes that you don't need, give yourself some room for expansion. It's super poor, but if you're managing your processes outside of supervisor, it works.

@Dmytro-Shvetsov
Copy link

@GameCharmer yeah, it does sound like a hell of a workaround. However, I truly cannot estimate on what hardware I'll run my project so the number of processes need to be scaled dynamically. Can you maybe suggest alternatives to supervisor to do so, or is there like a plug-and-play plugin for supervisor?

@GameCharmer
Copy link

@Dmytro-Shvetsov You can give Twiddler a shot, but I've never tried it successfully: https://github.com/mnaberez/supervisor_twiddler

@Dmytro-Shvetsov
Copy link

Dmytro-Shvetsov commented Sep 6, 2023

@GameCharmer

Wow, the Twiddler works like a charm. I managed to get the processes spawned dynamically with the following code:

from xmlrpc import client
from supervisor.xmlrpc import SupervisorTransport

server = client.ServerProxy('http://localhost', SupervisorTransport('', '', 'unix:///home/dmytro/supervisor.sock'))

cmd = '...my-command.sh'

workers_group_name = 'worker'

for gpu_id in range(num_devices):
    proc_group_name = f'procs_{gpu_id}'
    server.twiddler.addProgramToGroup(
        workers_group_name, 
        proc_group_name, 
        {'command': cmd,
         'autostart':'false', 
         'autorestart': 'True', 
         'logfile': '%(ENV_HOME)s/logs/mlworker_%(process_num)s.log',
         'startsecs': '10', 
         'process_name': '%(host_node_name)s_%(process_num)s',
         'numprocs': '5',
        }
    )
    server.supervisor.startProcessGroup(workers_group_name)
    server.twiddler.log(f"Added process group: {proc_group_name}", "INFO")

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests