PDA

View Full Version : Quick Dual Core Questions



webmastadj
16th May 2008, 09:06 PM
I am running a server with an Intel Core 2 Duo. The server is running fedora 8. The purpose of the server is a web server (running: ftp, mysql, apache, ssh). What I am wondering is if apache and mysql use both cores or are they limited to a single core?

THanks.

Erikina
17th May 2008, 03:49 AM
A web server is a highly parallelable task, as such you can bet they use multiply threads (Actually, I think Apache uses multiple processes). So yeah, it'll definitely be making use of your dual core (although, I doubt you'll be putting enough strain on it, that it'll matter). But the software will do its job.

webmastadj
17th May 2008, 04:50 AM
ok...well, I was wondering because I ran a php app and it only ever said it was using 50% of the CPU. the app was processing 300 photos, compressing them and saving them to certain folders.

That is why I was questioning it.

Erikina
17th May 2008, 05:24 AM
ok...well, I was wondering because I ran a php app and it only ever said it was using 50% of the CPU. the app was processing 300 photos, compressing them and saving them to certain folders.

That is why I was questioning it.

That is correct behaviour. There is no magic. Apache can't make a single threaded (php script) multi-threaded. If you want something more multi-threaded, use Perl .. and of course you'll need to hand-code multi-threaded support.

The multi-threadedness kicks in, when two people are both running the same (or a different) PHP script. Each will be in it's own process. That can happen. But there's no way to turn a single threaded app, into a multi-threaded one.

webmastadj
19th June 2008, 12:13 AM
I can see that now. If two users are executing the one script, then it will use both cores.

Thanks for the help.

marko
19th June 2008, 12:34 AM
You can see if a process is multithreaded by using pstack,
use any command that will tell you the process id of the process of interest:

ps aux | grep amarokapp

then take the pid and run it with pstack:

like this : pstack 20156

This is an example of what I get running pstack on amarokapp:


pstack 20156
Thread 6 (Thread 0x42458950 (LWP 20165)):
#0 0x0000003a8fe0b19d in pthread_cond_timedwait@@GLIBC_2.3.2 ()
#1 0x00000039ab0136e1 in ?? () from /usr/lib64/libxine.so.1
#2 0x0000003a8fe0729a in start_thread () from /lib64/libpthread.so.0
#3 0x0000003a8f2e42cd in clone () from /lib64/libc.so.6
Thread 5 (Thread 0x41a57950 (LWP 20166)):
#0 0x0000003a8f2da926 in poll () from /lib64/libc.so.6
#1 0x00007f3d5d8cdf6d in ?? () from /usr/lib64/libpulse.so.0
#2 0x00007f3d5d8c248a in pa_mainloop_poll () from /usr/lib64/libpulse.so.0
#3 0x00007f3d5d8c38e8 in pa_mainloop_iterate () from /usr/lib64/libpulse.so.0
#4 0x00007f3d5d8c39b0 in pa_mainloop_run () from /usr/lib64/libpulse.so.0
#5 0x00007f3d5d8cdd6d in ?? () from /usr/lib64/libpulse.so.0
#6 0x00007f3d5d8ea430 in ?? () from /usr/lib64/libpulse.so.0
#7 0x0000003a8fe0729a in start_thread () from /lib64/libpthread.so.0
#8 0x0000003a8f2e42cd in clone () from /lib64/libc.so.6
Thread 4 (Thread 0x42e59950 (LWP 20167)):
#0 0x0000003a8fe0af19 in pthread_cond_wait@@GLIBC_2.3.2 ()
#1 0x00000039ab0247c3 in ?? () from /usr/lib64/libxine.so.1
#2 0x0000003a8fe0729a in start_thread () from /lib64/libpthread.so.0
#3 0x0000003a8f2e42cd in clone () from /lib64/libc.so.6
Thread 3 (Thread 0x4385a950 (LWP 20168)):
#0 0x0000003a8fe0af19 in pthread_cond_wait@@GLIBC_2.3.2 ()
#1 0x00000039ab01713b in ?? () from /usr/lib64/libxine.so.1
#2 0x00000039ab01e06e in ?? () from /usr/lib64/libxine.so.1
#3 0x0000003a8fe0729a in start_thread () from /lib64/libpthread.so.0
#4 0x0000003a8f2e42cd in clone () from /lib64/libc.so.6
Thread 2 (Thread 0x4425b950 (LWP 20169)):
#0 0x0000003a8fe0af19 in pthread_cond_wait@@GLIBC_2.3.2 ()
#1 0x00000039ab0273eb in ?? () from /usr/lib64/libxine.so.1
#2 0x0000003a8fe0729a in start_thread () from /lib64/libpthread.so.0
#3 0x0000003a8f2e42cd in clone () from /lib64/libc.so.6
Thread 1 (Thread 0x7f3d6799a7f0 (LWP 20156)):
#0 0x0000003a8f2dcb32 in select () from /lib64/libc.so.6
#1 0x000000305fead38d in QEventLoop::processEvents ()
#2 0x000000305ff17691 in QEventLoop::enterLoop ()
#3 0x000000305ff17552 in QEventLoop::exec ()
#4 0x0000000000404703 in QGList::~QGList ()
#5 0x0000003a8f21e32a in __libc_start_main () from /lib64/libc.so.6
#6 0x0000000000404049 in QGList::~QGList ()
#7 0x00007fff6f9e1cb8 in ?? ()
#8 0x000000000000001c in ?? ()
#9 0x0000000000000001 in ?? ()
#10 0x00007fff6f9e32ab in ?? ()
#11 0x0000000000000000 in ?? ()

Now I can look at the processes(threads) themselves with ps -eLPc


ps -eLPc | grep amarokapp
20156 20156 0 TS 19 ? 00:01:13 amarokapp
20156 20165 0 TS 19 ? 00:00:00 amarokapp
20156 20166 0 TS 19 ? 00:00:06 amarokapp
20156 20167 0 TS 19 ? 00:00:02 amarokapp
20156 20168 0 TS 19 ? 00:00:17 amarokapp
20156 20169 0 TS 19 ? 00:00:00 amarokapp

we see that the main thread/process is the first one 20156,
its PID and LWP (lightweight process id)
is the same and its accumulated most of the cpu time,
the others just are helpers.

The other major kind of multiprocessing is making full processes
and running them separately (forking), httpd (apache) does that.


ps -eLPc | grep httpd
6619 6619 3 TS 19 ? 00:00:00 httpd
6621 6621 1 TS 19 ? 00:00:00 httpd
6622 6622 2 TS 19 ? 00:00:00 httpd
6623 6623 3 TS 19 ? 00:00:00 httpd
and you'll see the difference (the pid == LWP for all of them)
means there are multiple processes instead of one process with
multiple threads.