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

Multi threading in click #499

Open
AqsaKashaf opened this issue Nov 5, 2021 · 2 comments
Open

Multi threading in click #499

AqsaKashaf opened this issue Nov 5, 2021 · 2 comments

Comments

@AqsaKashaf
Copy link

AqsaKashaf commented Nov 5, 2021

Hi, I want to write a module which looks something like:
in :: FromDevice(eth1)
q :: Queue
uq :: Unqueue

// do some processing here
out :: ToDevice(eth2)
in -> q -> uq -> processing here -> out

However, I want to do this in a mult-threaded way, assuming I have multiple processing threads. A packet comes on eth1, it is queued. Then I want it to be dequeued by whichever thread is currently not busy and so on. And then finally all threads push the packets out to eth2. I came across ThreadSafeQueue but I am not sure about the Unqueue part.

@p4pe
Copy link

p4pe commented Dec 19, 2022

Hello @AqsaKashaf, did you manage to do this;
I am starting to use click again after a long time and I am trying to figure out how can I do the same thing.

@tbarbette
Copy link
Collaborator

element class Pipeline { $thread |
    input[0] 
    -> Stuff 
   -> uq :: Unqueue
    -> [0]output;
    StaticThreadSched(uq $thread);
}

inq :: ThreadSafeQueue;
outq :: ThreadSafeQueue;

inq -> p0 :: Pipeline(0) -> outq;
inq -> p1 :: Pipeline(1) -> outq;

THis solution duplicates the processing pipeline because nearly no processing elements in "normal" Click is thread-safe, but you can have :

inq-> Stuff -> Stuff2 -> f :: Stuff3;
f -> p0;
f -> p1;

In that case Stuff and Stuff2 will be traversed by multiple threads which is fine for state-less elements.

My own thought : pipelining is a thing of the past when CPU had 4 cores... In no ways it scales with many-cores CPUs and high-speed links where a single core cannot act as the RX or TX core anyway. Use sharding instead, properly supported in FastClick. Or in Click duplicating the pipeline N times and handling manually the state reconcilation.

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

3 participants