Skip to content

Python - Each WebSocket connection as a separate process #91

Open

Description

@cleancoder7

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`

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions