Re: condvar for win32?
- From: "Chris M. Thomasson" <no@xxxxxxxxxxxx>
- Date: Thu, 18 Sep 2008 09:25:37 -0700
"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...
;^)
.
- Follow-Ups:
- Re: condvar for win32?
- From: David Schwartz
- Re: condvar for win32?
- References:
- condvar for win32?
- From: Scott McPhillips [MVP]
- Re: condvar for win32?
- From: David Schwartz
- Re: condvar for win32?
- From: Chris M. Thomasson
- Re: condvar for win32?
- From: David Schwartz
- Re: condvar for win32?
- From: Dmitriy V'jukov
- Re: condvar for win32?
- From: David Schwartz
- Re: condvar for win32?
- From: Chris M. Thomasson
- Re: condvar for win32?
- From: David Schwartz
- condvar for win32?
- Prev by Date: Re: Parallel shift and threads and locks as a programming model
- Next by Date: Re: Parallel shift and threads and locks as a programming model
- Previous by thread: Re: condvar for win32?
- Next by thread: Re: condvar for win32?
- Index(es):
Relevant Pages
|