Click here to get back home

Processing workload distribution

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Processing workload distribution Ted 02-25-2008
Get Chitika Premium
Posted by Ted on February 25, 2008, 11:23 am
Please log in for more thread options
The machine is a single processor/quad core server running the latest
Windows Server.

The Perl we're using is the 64 bit build of 5.8.8 from Activestate.

I created a script that uses threads to launch a series of standalone
SQL scripts (I use system to invoke mysql to run my SQL scripts). I
had thought that system was spawning child processes, but it seems
that the script that launches them waits on each child before
launching the next. It is looking like the threads launches all
without wating for the next, which is closer to what I want.

However, regardless of what I have tried so far, all the hard work is
being done by one core, with the other three mostly sitting idle.

What can I do to distribute the workload evenly over all the cores in
the machine? The whole purpose of this machine was to serve as a
compute server for my colleagues and I, and in fact only two of us
have a need to access it, and this is so we can run heavy duty DB
analysis programs on it. The code works adequately, but it seems a
shame to have invested in a quad core processor based machine only to
have all the work done on only one core. I don't care if I have to
launch threads or child processes, as long as I can distribute the
work more evenly. Is what I am after possible?

Thanks

Ted

BTW: are there any 64 bit modules on CPAN? The repository for the 64
bit build that Activestate has provided seems to be empty.

Posted by Ben Morrow on February 25, 2008, 12:14 pm
Please log in for more thread options

> The machine is a single processor/quad core server running the latest
> Windows Server.
>
> The Perl we're using is the 64 bit build of 5.8.8 from Activestate.
>
> I created a script that uses threads to launch a series of standalone
> SQL scripts (I use system to invoke mysql to run my SQL scripts).

In general it is easier to talk to the database directly using DBI than
to launch external mysql processes. In this case, however, you may find
it easier to make things run in parallel with an external command.

> I had thought that system was spawning child processes, but it seems
> that the script that launches them waits on each child before
> launching the next.

Yes, this is how system works. As a special case, on Windows only,
calling

my $pid = system 1, "mysql ...";

(with a literal 1 as the first argument) will spawn a new process and
*not* wait for it. You can use the returned pid as an argument to wait
or waitpid. Alternatively, for more control, you can use Win32::Process
or IPC::Run.

> It is looking like the threads launches all without wating for the
> next, which is closer to what I want.

You would have to post your code for us to see what is happening here. I
think probably each thread is launching one child and waiting for it,
but since you have several threads you have several children.

> However, regardless of what I have tried so far, all the hard work is
> being done by one core, with the other three mostly sitting idle.

Are you *certain* you end up with more than one mysql process running at
a time? You should be able to check easily with Task Manager. If you
don't, then you need to fix that (or switch to using DBI to talk to the
database and Perl threads for parallelism). If you do, yet they are all
running on the same core, then something odd is happening: you will need
to show us a (minimal) script that runs two processes at the same time
that still end up on the same core.

> BTW: are there any 64 bit modules on CPAN? The repository for the 64
> bit build that Activestate has provided seems to be empty.

Modules on CPAN are (generally-speaking) architecture-neutral, given
that CPAN only holds C and Perl source. If ActiveState don't provide
64-bit ppms, then you can install pure-Perl modules directly from CPAN,
but XS modules will require a copy of the compiler used to build your
perl, probably a 64-bit version of MSVC. You may be able to get gcc
working (the 32-bit version of AS Perl has support for building modules
with gcc), but I don't know how well the 64-bit version is supported.

Ben


Posted by smallpond on February 25, 2008, 12:23 pm
Please log in for more thread options
> The machine is a single processor/quad core server running the latest
> Windows Server.
>
> The Perl we're using is the 64 bit build of 5.8.8 from Activestate.
>
> I created a script that uses threads to launch a series of standalone
> SQL scripts (I use system to invoke mysql to run my SQL scripts). I
> had thought that system was spawning child processes, but it seems
> that the script that launches them waits on each child before
> launching the next. It is looking like the threads launches all
> without wating for the next, which is closer to what I want.
>
> However, regardless of what I have tried so far, all the hard work is
> being done by one core, with the other three mostly sitting idle.
>
> What can I do to distribute the workload evenly over all the cores in
> the machine? The whole purpose of this machine was to serve as a
> compute server for my colleagues and I, and in fact only two of us
> have a need to access it, and this is so we can run heavy duty DB
> analysis programs on it. The code works adequately, but it seems a
> shame to have invested in a quad core processor based machine only to
> have all the work done on only one core. I don't care if I have to
> launch threads or child processes, as long as I can distribute the
> work more evenly. Is what I am after possible?
>
> Thanks
>
> Ted
>
> BTW: are there any 64 bit modules on CPAN? The repository for the 64
> bit build that Activestate has provided seems to be empty.


See perlthrtut and check your perl build with: perl -V
Look for a line like:

usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define

I believe that the last part indicates whether perl tries to use
multiple
CPUs.

Posted by Ben Morrow on February 25, 2008, 1:07 pm
Please log in for more thread options

>
> See perlthrtut and check your perl build with: perl -V
> Look for a line like:
>
> usethreads=define use5005threads=undef useithreads=define
> usemultiplicity=define
>
> I believe that the last part indicates whether perl tries to use
> multiple CPUs.

Please don't make things up and post them without verifying.
Multiplicity indicates whether it is possible to have several perl
interpreters in the same process: this is a requirement for ithreads (so
any perl with useithreads=define will also have usemultiplicity=define)
but is also used without ithreads for e.g. mod_perl. It has *nothing* to
do with use of multiple CPUs: this is determined by your OS's thread
scheduling policy.

Ben


Posted by smallpond on February 25, 2008, 2:32 pm
Please log in for more thread options
>
>
>
> > See perlthrtut and check your perl build with: perl -V
> > Look for a line like:
>
> > usethreads=define use5005threads=undef useithreads=define
> > usemultiplicity=define
>
> > I believe that the last part indicates whether perl tries to use
> > multiple CPUs.
>
> Please don't make things up and post them without verifying.
> Multiplicity indicates whether it is possible to have several perl
> interpreters in the same process: this is a requirement for ithreads (so
> any perl with useithreads=define will also have usemultiplicity=define)
> but is also used without ithreads for e.g. mod_perl. It has *nothing* to
> do with use of multiple CPUs: this is determined by your OS's thread
> scheduling policy.
>
> Ben

I didn't make it up, I looked at previous postings in this NG where
someone has ithreads=define and not usemultiplicity.
http://groups.google.com/group/comp.lang.perl.misc/browse_frm/thread/8f27b699aff8a37d/18a233467aaa72d8?hl=en&lnk=gst&q=usemultiplicity#18a233467aaa72d8

Similar ThreadsPosted
Perl Distribution January 13, 2005, 9:35 am
distribution error September 18, 2005, 5:47 am
Another distribution error October 6, 2005, 3:54 am
Hypergeometric Distribution May 5, 2006, 10:46 am
Cumulative distribution functions? November 13, 2004, 10:49 pm
Distribution of modules, historically March 25, 2005, 1:26 am
Distribution description on CPAN November 1, 2008, 1:31 pm
Module for random array distribution March 17, 2007, 8:11 pm
Broken links in Activestate Perl distribution February 22, 2008, 6:47 am
Integrating Inline-C-based module into a Perl distribution September 1, 2008, 11:49 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap