|
Boost Users : |
Subject: Re: [Boost-users] [ASIO] Async TCP/UDP server design help
From: U.Mutlu (for-gmane_at_[hidden])
Date: 2013-12-30 01:41:08
Terry Lazoki wrote, On 12/29/2013 03:43 AM:
> I'm having hard time understanding the boost asio design and how i can use
> it to tackle my problem.
>
> My problem:
> Designing a tcp/udp server that is time efficient.
>
> 1. User sends packet through tcp
> 2. Server receives packet and processes it to build a large tree (n > 20000)
> 3. Server then parses the new tree and sends a summary packet through udp
> to another client
>
> Conditions/Limitations:
> - Has to be time efficient, receiving, processing and sending has to be
> done as fast as possible.
> - Processing the packet is heavy and can cause delays if its done in the
> same thread
> - Parsing the tree is also a little heavy when sending it through udp, can
> cause delays too
>
> Design 1 (2 threads):
> Thread 1: ASIO TCP and UDP. TCP receives packets and adds it to a circular
> buffer. While at the same time, processes the shared tree and sends packet
> through udp.
> Thread 2: Server grabs packet from circular buffer and processes it
>
> Some problems here:
> - I dont understand the async part here. What happens when tcp receives a
> packet, if the current thread is continuously parsing the tree and sending
> packets through udp. Do i need to separate the udp part to another thread?
> - I have 3 parts of the program that i need to run concurrently, well its
> really 2 parts and receiving packets through tcp.
>
>
> Any help is appreciated.
>
> Thanks,
I would use a modular approach using an acceptor, a shared job queue,
and multiple worker threads (at least 2 workers; depends on the job
characteristics, duration etc.). Of course a synchronisation/locking
is needed for shared resource access/usage,
see for example https://en.wikipedia.org/wiki/Producer%e2%80%93consumer_problem
-- U.Mutlu DACOS Notdienstanlagen GmbH, Germany, www.dacos.de
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net