Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

Which thread structure is better?

pcompassion
Beginner
431 Views
Hi,

I am writing a network library and wondering which of the following two is more efficient. (assume tcp connection)
I have asked this question to Intel representatives at GDC, and they suggested me post the question here.

The two structures are..

A. accept() + read() in one thread and processData() in another
:shared data queue needs lock
B. accept() in one thread and read() + processData() in another
:shared fd queue needs lock

pros and cons i can think of are

A's pro: as long as polling(epoll/select/etc) mechanism is fair, each socket gets fair attention
A's con: lock for each push and pop of every reconstructured packet.


B's pro: lock for each connect/disconnect (less # of locks and easier to implement)
B's con: not sure if all connections will get fair treatments.

Thanks

0 Kudos
2 Replies
robert-reed
Valued Contributor II
431 Views

Not knowing the comparative processing times of the components you describe, nevertheless I'll take a stab at this.

General comments: this design is wired to two HW threads and may not scale when there are more threads available.

B offers the prospect that thebuffer(s) filled by read() might still be cache resident when processData() is invoked, possibly reducing some thrash in the memory hierarchy. This is of course subject to the network load and MTU supported.

Perhaps all three tasks should be in a single thread but you have a pool of threads which take turns doing the accept()?

0 Kudos
pcompassion
Beginner
431 Views
Hi,
thanks for the comment.
It's been more than a month after you posted, but i'm still not quite sure on this.

Let me make it clear.

In both senario, there will be one threads doing the accept(),

first one has one thread doing accept() and read(), and possibly multiple threads doing processData()

second one has one thread doing accept() only, and possibly multiple threads doing read() + processData()



Not knowing the comparative processing times of the components you describe, nevertheless I'll take a stab at this. :
You can assume that time for processData() is sufficiently larger than accept() or read()

General comments: this design is wired to two HW threads and may not scale when there are more threads available. :
I don't get it, which one of the two are you refering to?, and what do you mean by HW threads?
0 Kudos
Reply