locked
How would you use PPL in this scenario? RRS feed

  • Question

  • Hi,

    Suppose we have a socket server who needs to:

    1. wait for connections. Once a connection comes in,

    2. accept the connection, get the data from the client.

    3. process the data. This processing needs to be as fast as possible so I want to use PPL (some sort of parallel_for). The more cores on a server available to this process the better.

    4. Send back the data. Keep the socket open because the client may send more data. If no data arrives for say 20 seconds, close the connection.

     

    With this in mind I can think of a few implementation (overview no details):

    1. Every time the server gets a new connection from a client spawn a thread (CreateThread). Inside this thread do #3 from above. This scenario seems relative simple to implement but it has a few issues:

      a. If there are many clients connecting there will be a lot of threads created and that creates big issues on the server.

      b. the concurrent CRT (used at #3) does not 'know' about the threads created by CreateThread so there is no optimizations between them. There may be more issues with this implementation.

     

    2. Another approach is to use PPL to schedule every incoming connection on a thread pool. So after the connection is accepted, it is queued to the PPL thread pool. This will ensure that all threads are managed by concrcrt. If the socket connection will be closed after processing then this should be a good solution but that will require the client to ALWAYS connect for each send even when it has a queue messages to be send. If the socket is not closed and more data arrives, then I am not sure how and when the concrcrt will schedule it to run, etc. This gets into things I am not sure how the scheduler does?!

    3. ??

    Thanks,

    G.

    Friday, December 3, 2010 10:31 PM

Answers