Re: condvar for win32?



"David Schwartz" <davids@xxxxxxxxxxxxx> wrote in message news:96300776-7dbb-41b7-8b99-28eb6c6cda0a@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Sep 15, 4:45 pm, "Chris M. Thomasson" <n...@xxxxxxxxxxxx> wrote:

> There is a disadvantage if your creating highly robust programs...

No.


> Back when
> I used to create server frameworks on Windows, I never used IOCP for
> anything but I/O. This is because, IIRC, PQCS uses a little non-paged
> memory, and I did not want to tie that up for anything but I/O.

If you have three-hundred tasks waiting for a thread, and you have far
less than three-hundred CPUs, there is no need to queue anything else
to the IOCP. You can use IOCP for job dispatch *when* *it* *matters*
without fear of non-paged pool exhaustion.


> The size of
> an IOCP queue is limited my the amount of non-paged memory...

Which is basically no longer an issue on modern versions of Windows.
But if you have so much queued up to an IOCP that memory is an issue,
there's no advantage to putting more stuff on the queue -- it won't
get done any quicker. You only need to keep jobs you actually need to
schedule to a thread on the IOCP queue.

http://www.microsoft.com/mspress/books/sampchap/5726a.aspx

I personally would not use IOCP for sending private messages between threads. I want to maximize the number of connections, and the number of pending I/O operations the server can handle. If you have 50,000 connections and each connection has multiple overlapped sends and recvs going, and perhaps multiple disk reads and writes, well, the non-paged memory becomes a major issue indeed. I don't want to waste that memory on private messages that have nothing to do with I/O.




> My framework
> needed to refrain from crashing in tight scenarios. It could handle > recourse
> exhaustion, and even recover from malloc returning NULL...

So if you don't have enough memory to queue something on the IOCP,
don't.

How do you reliably know that the non-paged memory is exhausted before you call into IOCP? I guess the best case scenario would be that Winsock calls fail with WSAENOBUFS. Worst cast, well, the system crashes. I have used several strategies to put my server into a "critical resource alert" mode which would do some fairly radical things in order to reduce or mellow out recourse usage. Some of the things involved limiting the number of pending io per-socket; deferring requests; partitioning connections into groups and pausing groups in round-robin fashion; drastic measures like disconnecting connections; lowering the timeout for io activity; destroying data-structure caches; shutting down other running processes that the admin allowed for; reducing per-socket buffer sizes; cutting down on pending AcceptEx's; denying connections; and on and on and on... I even did some special protocols which could offload connections and session state to other servers, and did heavy port concentration. Ahh, the good ol days...




That's just the most efficient way to dispatch it, not the only
way. If you want to write robust software, do so. But robust software,
as you noted, sanely handles malloc failure, it doesn't refrain from
calling malloc!

malloc returning NULL automatically swung the server into "critical resource alert" mode...

;^)

.



Relevant Pages

  • Re: Memory Manager Tests - using 512 Threads
    ... > non-blocking TCP server hits a limit of connections it can handle. ... I am handling the same number of connections with 16 as with 512 threads, ... with IOCP. ... compressed and encrypted before being sent to the Server. ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: condvar for win32?
    ... pending I/O operations the server can handle. ... If you have 50,000 connections ... Pending multiple overlapped sends and receives on 50,000 connections ... If the server has enough memory, I want to take advantage of it. ...
    (comp.programming.threads)
  • How about Threads and IOCP Efficient Design,other IOCP per thread?
    ... i have developed a server to do I/O for video/audio from remote peers. ... IOCP can control the own thread when a I/O Bound ... a packet contains video data has size of 3500 ~ 5000 bytes several time. ...
    (microsoft.public.win32.programmer.networks)
  • Re: condvar for win32?
    ... Yes, IOCP can be misused. ... if the environment allows me to have multiple pending overlapped operations ... at 50,000 connections I will do it. ... precious non-pages memory for anything else but I/O. ...
    (comp.programming.threads)
  • Re: networking problem
    ... thread for each newly connected client and within that cread create I/O ... the host pc the server is on. ... server socket accepts all the client connections, one at a time and you ...
    (comp.lang.java.programmer)