Re: RegNotifyChangeKeyValue and ipc?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



See below...
On Thu, 23 Oct 2008 06:38:31 -0600, "L.Allan" <lynn.d.allan@xxxxxxxxx> wrote:

I'm planning to implement a "master/parent" process that creates several
"child/slave" processes (from 1 to 10+ children).

Each process displays a different but similar document document. When the
parent process does a search for a certain word(s) with certain criteria
(case-sensitive, exact match, range, etc), I want all the child processes to
do the same search on their document and display "match hits". When a child
process does a search, I don't want the parent and other children to do that
search.

My experience is that processes are easier to get to multi-thread with a
multi-core cpu that having an MDI-like app with multiple threads. (or the
somewhat newer Multiple-Top-Level-Document architecture).
****
Threading is threading, and the scheduler does not care which process owns the threads.
However, it is effectively slower if you have multiple processes because the process swap
cost is more expensive, whereas if the thread about to be scheduled is in the same process
as the previous thread there is no process-swap cost.
****

I'm considering communicating from the parent to the children with
RegNotifyChangeKeyValue as the means of inter-process-communication (ipc).
I've tried a simple POC (proof of concept) and it seems to work well. Each
of the children are blocked "listening" for a registry key to change. The
contents of the registry key will have a string with the search criteria,
such as
1 0 0 0 1 12 65 "words to search"
****
Probably the worst possible way I could imagine to communicate; even worse than writing a
shared file. Don't even bother thinking any further about this as a way of communication.

It just doesn't make sense to block a process. Since you create the programs, you have
the handle to the process, you can trivially find the window from this, and you can
SendMessage(WM_COPYDATA) or use any other IPC mechanism that makes sense to handle this.
Consider a model that blocks waiting for a message (other than in the top-level message
loop) to be a Fundamentally Bad Design.
****

I've been able to get this to work with communication using defined
PostMessages and also with Events. However, for the intended purpose, using
RegNotifyChangeKeyValue seems simpler.
****
I don't see how. It involves a wait which can block indefinitely, and it also has
problems such as dealing with the Registry. I wouldn't waste five minutes trying to
implement such a solution.
****
Also, it seems to scale well, and
doesn't have to be concerned about child processes "coming and going" if one
or more are closed by the end-user, or "fresh/new" children are created.
****
The entire approach of using multiple processes seems to be the core of the problem; why
are you using multiple processes when a single process multithreaded would do the job much
more easily? The ability of the end user to close the processes seems a Really Bad Idea
anyway. Besides, as far as scaling, you rarely gain anything by scaling to more threads
than you have CPUs, and if you multithread within a single app, you have no problem
passing arbitrarily complex data structures between threads, because you are in the same
address space.

I'd create an I/O Completion Port, N search threads where N is the number of CPUs you
have, and queue up requests to the threads via the IOCP. This would take less effort than
trying to coordinate independent processes and use obscure and complex interprocess
communication such as waiting for a registry key to change. Let's see: using threads is
easier, runs faster, scales better, minimizes overheads, reduces complexity...what's not
to like about it?
****

It seems kind of the equivalent of a BroadCast, but limited only to the
child processes that are "listening" to a specific sub-hive. My impression
is that a PostMessage(BROADCAST) is inappropriate for several reasons,
including that many/all processes have to "wake up" to see if the broadcast
message is for them.
****
Don't waste time on this solution. It does NOT "scale well", because if you create more
processes than you have CPUs, you actually REDUCE performance.
****

I'd appreciate hearing information on the pro's and con's of this approach.
I haven't done high resolution timings to compare to the PostMessage
approach or Event approach. Each of the searches take from 15 to 50 ms per
cpu-core on a relatively modern computer, so I don't think the overhead is
too much of a factor (probably several microseconds).
****
PostMessage should be faster. Events should not be used at all. Process startup is
expensive. The communication mechanism is unnecessarily complex. I don't see anything
good about the proposed solution at all.
joe
****


Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: RSVP (and pinatas)
    ... I don't agree that it stands to reason they don't want communication - ... that why people put themselves on Do Not Call lists or have ... it's no big deal for a parent to ...
    (misc.kids)
  • Re: Accessing class members ...
    ... The problem here could arise if dialogs are modeless; ... I see when this question is asked is someone trying either to modify controls in a parent ... class or reach into child windows to manipulate data, both of which are really bad ideas. ... and usually there is no other communication. ...
    (microsoft.public.vc.mfc)
  • Re: SMS 2003 Hierarchy within W2k3 Federated Forests
    ... > trust is not required for site to site communication. ... > need to create all site address accounts in the parent forest. ... > site's sitetositeconnection group and grant the account used for child to ... >> ยท The forests are configured with a transitive trust. ...
    (microsoft.public.sms.setup)
  • Re: How can I...
    ... Communication, and many people out there who have children have absolutely ... The privacy of the child does not outweigh the right of the parent to know ... If I hear one more pansy-ass liberal parent tell their child they are going ... rules, laws and mores that must be respected is hurting not only the kids, ...
    (microsoft.public.windowsxp.general)
  • Re: Using fork() on XP to run processes in parallel
    ... >> to the parent and terminate. ... > successfully forking multiple processes by help of the CPAN module ... But that module doesn't facilitate communication back to the parent, ...
    (comp.lang.perl.misc)