How about Threads and IOCP Efficient Design,other IOCP per thread?
- From: Misoullee <Misoullee@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 May 2008 07:30:07 -0700
i have developed a server to do I/O for video/audio from remote peers.
the server works based on IOCP(IO Completion Port) and Overlapped async for
all I/O s and TCP socket.
Recently I have a dead problem in my test.
the problem is followed on the last of this writtings.
First i would say about the design for my server application.
the server have five worker threads associated with each IOCPs(not global
single IOCP)
that threads are one for connections, one for I/O, one for processing packets,
one for I/O to Database, and last for report logs to Central Manager Server.
in this case, the important thing is that threads work on each other IOCPs.
that is, the server has five IOCPs.
What i worry is while a worker thread is busy how safe and fast the each
IOCP can control the own thread when a I/O Bound
Completion occurs?
I have known that IOCP manages good itself a thread pool for threads
associated and can handle N concurrent threads by
allowing the Application to pass number to NumberOfConcurrentThreads
parameter in CreateIoCompletionPort API call.
so worker threads more than one can be run then it can handle fast without
delaying for another waiting I/O.
I can see following from MS KB Q192800 allocated on
http://support.microsoft.com/kb/192800
"You can decide to have a maximum of 2 concurrent threads used by the IOCP
and a pool of 10 worker threads. You have a pool of
worker threads greater than or equal to the number of concurrent threads
used by the IOCP so that a worker thread handling a
dequeued completion packet can call one of the Win32 "wait" functions
without delaying the handling of other queued I/O
packets.
If there are completion packets waiting to be dequeued, the system will wake
up another worker thread. Eventually, the first
thread satisfies it's Wait and it can be run again. When this happens, the
number of the threads that can be run is higher
than the concurrency allowed on the IOCP (for example,
NumberOfConcurrentThreads). However, when next worker thread calls
GetQueueCompletionStatus and enters wait status, the system does not wake it
up. In other words, the system tries to keep your
requested number of concurrent worker threads. " --Q192800--
Now I say the first issue.
My server well works on almost I/O transaction in slack term.
But the server is shutdowned on a lot of video data in speed.
the socket to client on server side is closed.
a packet contains video data has size of 3500 ~ 5000 bytes several time.
the error codes i can get when returned are 64(ERROR_NETNAME_DELETED) by
GetQueuedCompletionStatus
then after 183(ERROR_ALREADY_EXISTS) by WSAGetLastError.
In the client application too, socket is closed with code 0 returned.
here is two doubt points, the one is why the TCP socket is closed? another
is why the application is shutdowned only after
socket is closed?
i would say simple that process flow.
A is Connection(accept call) thread.
it post a IOCP packet with the socket handle accepted to B by
PostQueueCompletionStatus call.
B is thread to associate the socket returned from A to IOCP and I/O
start(receive/send call)
it post a IOCP packet with a I/O buffer handler completed to C by
PostQueueCompletionStatus call.
if a socket is closed, it post a IOCP packet to A then A cleanup all
information for a socket.
C is thread to handle packets from I/O packets is completed from B
it post a IOCP packet with new a I/O buffer to B to start I/O by
PostQueueCompletionStatus call.
or post a IOCP packet with new Database work to D
D is thread to handle I/O to Database Server.
E is thread to report server status to Central Manager Server.
where is the cause from?
there seems to be some problem for me to get a IOCP and Thread Design.
i think there are the problem that worker threads can't be safe to wait and
resume by IOCP
because the each IOCP handle only a thread so it does not get a real thread
pool.
All of the woker threads share a single IOCP is good way to get a higher
performance from IOCP? and what is the great design?
Thanks in Anybody, Any answer
.
- Prev by Date: How to Find Reg Key for the particular N/W Adapter in a Machine
- Next by Date: Re: How to Find Reg Key for the particular N/W Adapter in a Machine
- Previous by thread: How to Find Reg Key for the particular N/W Adapter in a Machine
- Next by thread: Reidrect stderr of child process
- Index(es):
Relevant Pages
|