one-to-many queue strategies with slow connections
Hi all,
what about queue strategies/data structures to get a packet from a connection and then copy it to n other connections?
The goal is to have a thread that sends data to users without blocking on slow connections. In pseudo-code:
// write thread
foreach (Connection c : connections) {
Queue q = c.queue
Packet p = q.firstPacket
send as much data of p as it is a non-blocking operation
if (p.bytesToSend == 0) {
q.removeFirstPacket
}
}
// read thread
Packet p = c.readPacket()
foreach (Connection c : connections) { c.queue.addLast(p) }
If I use multiple queues (1 Queue object for Connection) I risk to go "out of memory" really quick...
p.s.: I''m using Java
Thanks in advance for suggestions
A
If you''re trying to send more data than will fit on the wire, you will block (with TCP) or possibly drop the data (with UDP). There''s no way around that. So don''t send more data than the connection can handle!
Also, when you call write/send to send out the data, that call will put it in a buffer and tell the kernel to queue it to the network device -- those calls do not wait until the data is on the other end. If the buffer is full, they''ll wait for space in the buffer, but that''s not the same thing.
Also, when you call write/send to send out the data, that call will put it in a buffer and tell the kernel to queue it to the network device -- those calls do not wait until the data is on the other end. If the buffer is full, they''ll wait for space in the buffer, but that''s not the same thing.
enum Bool { True, False, FileNotFound };
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement