Skip to content

Basic clustering: M accepting threads #50

Description

@nobugs-hare

Depends on #23

We need a way to use mlultiple accepting threads for our "clustering". This will cause MxN communications so we need to rely on #23 for implementing it.

For all the M accepting threads, we want either (a) use the same socket across all the threads, or (b) SO_REUSEPORT (supposedly Linux-only; see http://man7.org/linux/man-pages/man7/socket.7.html for documentation, if proven necessary we may even use SO_ATTACH_REUSEPORT_CBPF / SO_ATTACH_REUSEPORT_EBPF to ensure round-robin behaviour).

In ANY of two cases above, we have to implement one single inter-thread data storage for decision-making on "where we should send accepted socket". Currently suggested way of implementing it:

  • all the data below is protected by one single mutex
    • we have a vector of items representing worker threads (with their respective communicating sockets per Streamline/unify inter-thread communications #23)
    • in each item, there is a counter current_thread_connections
    • outside of the vector (but still under the same mutex) there is uint current_total_connections
    • int next_item_to_consider
  • whenever a thread is done with processing any of the sockets, it decrements BOTH current_thread_connections AND current_total_connections
  • when a socket is accepted, the following happens (under the multex unless specified):
    • average (as current_total_connections/vector.size()) is calclulated
    • if necessary, next_item_to_consider is adjusted to fit within current size of vector
    • if(vector[next_item_to_consider].current_thread_connections <= average*1.25) (NB: all calcs should be done with integers ONLY) - then we
      • send current socket to vector[next_item_to_consider].socket
      • do NOT increment next_item_to_consider
      • finish processing
    • otherwise - increment next_item_to_consider and repeat previous step

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions