[Boost-users] [ASIO] Async TCP/UDP server design help

95 views
Skip to first unread message

Terry Lazoki

unread,
Dec 28, 2013, 9:43:25 PM12/28/13
to boost...@lists.boost.org
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,

U.Mutlu

unread,
Dec 30, 2013, 1:41:08 AM12/30/13
to boost...@lists.boost.org


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–consumer_problem

--
U.Mutlu
DACOS Notdienstanlagen GmbH, Germany, www.dacos.de

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Dirk Botha

unread,
Jan 2, 2014, 5:33:41 AM1/2/14
to boost...@lists.boost.org
Hi Terry,

I might have solved your problem for you already.


Documentations, such as it is, is available here: http://thelastcylon.github.io/kisscpp/index.html

Currently, there is no UDP support, but I'm sure it won't take much to get that in.
Feel free to ask questions, if you want.

--
Regards,
Dirk J. Botha
http://www.djb.co.za
~*~ Registered Linux User #379726 ~*~

"If people concentrated on the really important things of life, there'd be a shortage of fishing poles." ~ Doug Larson
Reply all
Reply to author
Forward
0 new messages