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

Python - Each WebSocket connection as a separate process #91

Open
cleancoder7 opened this issue Oct 4, 2021 · 0 comments
Open

Python - Each WebSocket connection as a separate process #91

cleancoder7 opened this issue Oct 4, 2021 · 0 comments

Comments

@cleancoder7
Copy link

cleancoder7 commented Oct 4, 2021

Suppose if the system has 4 CPU's, I need to run eight workers on It. On starting the server, I want to initialize the eight workers. I want to forward the data to available workers on the new WebSocket connection and change that worker's status to occupied. If all of the workers are occupied, then the server should not accept any new connections.

I don't want to exchange data between the processes. But I need to send data to the correct Process when new data is received in the WebSocket. Whenever the WebSocket connection drops, then I need to change the status of the worker to available.

`# Something like this, 
# FYI : The following is not a python code, just a representation of the requirement


process_manager = ProcessManager()

WebSocket 

    onNewConnection:
        available_process = process_manager.get_available_process()
        if available_process:
            available_process.set_state(state.Occupied)
        else:
            ws.write("Server is on full load")

    

    onNewMessage(_data):
        available_process.sendData(_data)

    OnSocketClose:
        available_process.set_state(state.Available)




__main__
    process_pool = ProcessPool (8)
    for loop 0 to 7 as i
        process_manager.put(i,Process)
    #-- start all process
    #-- join all process`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant