Thread: Re: Process balancing on smp db server/apache web serve

Re: Process balancing on smp db server/apache web serve

From
Ron Snyder
Date:
What OS are you using that "assigns" a cpu to a process at start up?  I
believe that all of our multiprocessor machines (Linux, Sun, HP, AIX, IRIX,
Dec^Wcompaq^WHP) will run a ready process on whatever cpu is available.

-ron

> -----Original Message-----
> From: Peter Darley [mailto:pdarley@kinesis-cem.com]
> Sent: Thursday, May 23, 2002 6:56 AM
> To: Pgsql-General
> Subject: [GENERAL] Process balancing on smp db server/apache
> web server
>
>
> Friends,
>     I have been thinking about my smp db server and how it
> interacts with my
> web server.  I'm using mod_perl on Apache, which uses
> Apache::DBI to connect
> to the db server via a private network segment.  It occurs to
> me that since
> the web server is connecting early (on startup), when there
> is probably no
> load on the db server, the cpu that each backend is assigned
> to will be
> largely random, or, if there is a large syslogd operation or
> something right
> at that time, it might even put the majority of backends on the same
> processor.
>     When someone hits the web site it seems to me that
> there would be a greater
> than 50% chance that any two large queries from the web
> server would end up
> being run on the same processor.  Similarly, if I start a
> large processing
> script that uses the db, since the web associated backends are already
> assigned to a processor, there's a good (~50%?) chance that
> any big queries
> that come in through the web will be on the loaded cpu.
>     Does this make sense to anyone?  If this is true, are
> there any suggestions
> about how I can keep my persistent connections from Apache,
> while getting
> the db server to balance the load more efficiently?
> Thanks,
> Peter Darley
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>

Re: Process balancing on smp db server/apache web server

From
"Peter Darley"
Date:
Ron,
    I thought I was talking about Linux, but may I'm mistaken on how smp works.
I was told that a process is run on one and only one CPU, and that there was
no mechanism to move the process to another CPU during execution.  This
would mean that once a process was started on a CPU it would stay on that
CPU, even if it grew to a point that it would make since to switch it over
to another.
    It looks like I was hoodwinked tho, as some research has lead me to the SMP
FAQ item 7:

7. Does Linux SMP support processor affinity?
Standard kernel
    No and Yes. There is no way to force a process onto specific CPU's but the
linux scheduler has a processor bias for each process, which tends to keep
processes tied to a specific CPU.

    This seems to be saying that what I was told was wrong, so, I apologize for
wasting the lists time.

Thanks,
Peter Darley


-----Original Message-----
From: Ron Snyder [mailto:snyder@roguewave.com]
Sent: Thursday, May 23, 2002 7:41 AM
To: 'Peter Darley'; Pgsql-General
Subject: RE: [GENERAL] Process balancing on smp db server/apache web
server


What OS are you using that "assigns" a cpu to a process at start up?  I
believe that all of our multiprocessor machines (Linux, Sun, HP, AIX, IRIX,
Dec^Wcompaq^WHP) will run a ready process on whatever cpu is available.

-ron

> -----Original Message-----
> From: Peter Darley [mailto:pdarley@kinesis-cem.com]
> Sent: Thursday, May 23, 2002 6:56 AM
> To: Pgsql-General
> Subject: [GENERAL] Process balancing on smp db server/apache
> web server
>
>
> Friends,
>     I have been thinking about my smp db server and how it
> interacts with my
> web server.  I'm using mod_perl on Apache, which uses
> Apache::DBI to connect
> to the db server via a private network segment.  It occurs to
> me that since
> the web server is connecting early (on startup), when there
> is probably no
> load on the db server, the cpu that each backend is assigned
> to will be
> largely random, or, if there is a large syslogd operation or
> something right
> at that time, it might even put the majority of backends on the same
> processor.
>     When someone hits the web site it seems to me that
> there would be a greater
> than 50% chance that any two large queries from the web
> server would end up
> being run on the same processor.  Similarly, if I start a
> large processing
> script that uses the db, since the web associated backends are already
> assigned to a processor, there's a good (~50%?) chance that
> any big queries
> that come in through the web will be on the loaded cpu.
>     Does this make sense to anyone?  If this is true, are
> there any suggestions
> about how I can keep my persistent connections from Apache,
> while getting
> the db server to balance the load more efficiently?
> Thanks,
> Peter Darley
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>


Re: Process balancing on smp db server/apache web server

From
Bruce Momjian
Date:
Peter Darley wrote:
> Ron,
>     I thought I was talking about Linux, but may I'm mistaken on how smp works.
> I was told that a process is run on one and only one CPU, and that there was
> no mechanism to move the process to another CPU during execution.  This
> would mean that once a process was started on a CPU it would stay on that
> CPU, even if it grew to a point that it would make since to switch it over
> to another.
>     It looks like I was hoodwinked tho, as some research has lead me to the SMP
> FAQ item 7:
>
> 7. Does Linux SMP support processor affinity?
> Standard kernel
>     No and Yes. There is no way to force a process onto specific CPU's but the
> linux scheduler has a processor bias for each process, which tends to keep
> processes tied to a specific CPU.
>
>     This seems to be saying that what I was told was wrong, so, I apologize for
> wasting the lists time.

Let me explain processor affinity.  CPU's have instruction and data
caches on the chip, as well as virtual page mapping caches (TLB).  This
makes keeping a process on the same CPU desirable because returning to
the same CPU means the CPU cache may have information that will allow
that process to run faster.  However, there is no requirement that a
process remain on the same CPU, and it will often be moved to take
advantage of an idle CPU.

On a 2-cpu SMP system, try this.  Start three loops in separate terminal
sessions:

    echo $$;while : ;do :; done

Then, use 'ps' with the proper flags to see the CPU's for each process.
On my BSD/OS system, I use:

    ps -axl|egrep '29276|29404|29451'

with the numbers representing the process id's displayed in my three
terminal sessions.  What I see is that two are running on one CPU, and
one on another, but you should see that sometimes two are running on
CPU-0 and then two are running on CPU-1, as that the processes migrate
for load balancing purposes.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026