LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 08-05-2004, 05:36 PM   #1
manofwax
LQ Newbie
 
Registered: Jul 2004
Location: Davis, Ca
Distribution: red hat
Posts: 13

Rep: Reputation: 0
How to make sense out of "top" command


Hi there,

I was using command "top", and tried to see how my php scripts perform when i was running the MS stress tool with stress tool. Those php scripts are just some simple scripts, which take inputs and store them into mysql.
but i got like around 40% total cpu usage, isn't it too much for just three php scripts?

And one other thing, is there any better command or tool that i can use to monitor the system resources, instead of command "top"
coz, i had to manually recorded the values from "top" command", and then average up those values. But those values vary a lot, so the result isn't quite revelent. many thanks
 
Old 08-06-2004, 09:48 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
The CPU usage for each thread is controlled by part of the kernel called the schedular. The schedular's job is mainly to make sure the CPU is running code as much as possible (rather than “context-switching” between processes or waiting for hardware).

So 40% is actually quite low unless you're running other software at the same time. You can change the distribution between processes by using the “nice” and “renice” commands, that help the schedular decide which processes to run if it has a choice (effectively throttling back your PHP scripts to let something else run instead).

To analyse the performance of a single program, I would normally use gprof, but I'm not too sure if that works with scripts.

Hope that's of some help,

— Robert J. Lee
 
Old 08-06-2004, 01:42 PM   #3
manofwax
LQ Newbie
 
Registered: Jul 2004
Location: Davis, Ca
Distribution: red hat
Posts: 13

Original Poster
Rep: Reputation: 0
Why "rather than “context-switching” between processes or waiting for hardware" is a reason for "So 40% is actually quite low"??


40% is reasonable? i set 50 concurrent connections. But they are just very basic scripts, storing value into datebase...

My biggest concern is how much cpu usage will be if there are many users visiting those pages at the same time. Does anyone know what i can check?? thanks a lot
 
Old 08-09-2004, 02:54 PM   #4
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
Perhaps I explained that badly.

The CPU is split out unevenly between all running processes. At any single instant of time, only one process is running on the CPU, and it switches between which one is running about once every 0.00005 seconds (very roughly). A process won't run only if it has nothing to do.

So, if you only had two processes running, and they both did something simple (like adding two numbers together repeatedly) they would both get a CPU time of around 50%. If they were both doing something really slow and complicated (like computing PI to the two-millionth decimal place), they would still both get 50% of the CPU time.

The only case where a process will get a lower percentage of CPU time is if it's doing lots of writing to or reading from hardware, or lots of sleeping (being idle) — then, the schedular tries to run another process while it's waiting to stop the CPU from being idle. Thus, one process gets less CPU time while another process gets mode. Only if all processes are waiting will the total CPU load actually go below 100%.

The fact that your process is achieving 40% CPU load is more of a tribute to how well the database is caching your data than anything else (you're not waiting for the database very much).

If you really want to, you can reduce the CPU load by using something like usleep(1) every so often in your code. All this will do is have the script pause for a while (0.000001 seconds) and thus get another process to run during that time. It won't make anything more efficient at all, but it'll recude the CPU load (if that really is what you're worried about).

Also, remember that scripts tend to have a much longer start-up/shutdown phase than other programs, so you'll be taking a CPU hit there.
 
Old 08-09-2004, 04:20 PM   #5
manofwax
LQ Newbie
 
Registered: Jul 2004
Location: Davis, Ca
Distribution: red hat
Posts: 13

Original Poster
Rep: Reputation: 0
thanks, rjlee

but, hm... when those php script were spending me 40% of my cpu usage, i still see about 50% of cpu usage being idle, it's not used by other application.

From what i understand, those 50% of cpu should be used by other application, is that true??? =/

And cpu is always 100% used, if there aren't much write and read??? is that what you are saying???


THANK you so much, rjlee =)
weeeeeee
 
Old 08-10-2004, 06:46 AM   #6
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
The other thing that can cause the CPU to be idle is not having any code to run.

If every process in the system is, at a given point in time, either sleeping or waiting for I/O then the schedular doesn't have anything to run, and so the CPU will remain idle.

If there isn't any I/O then the CPU will be 100% used ideally, except for “context-switching”, i.e. the time taken to switch between different running processes. This generally accounts for anything up to around 1% of CPU time (roughly). The more context switching you do, the less the CPU is used but the more responsive individual processes are (because they get to run more often). You have some indirect control over this through the processes “nice” value.

In order to know what kind of hit your system will take if you get lots of voters, you will need to actually stress-test it and kick off several dozen/hundred/thousand PHP processes at once, and time how long they take. You can't just assume how well it will scale up, because there are a lot of tricks that the software employs to make these things run efficiently with lots of processes that aren't necessarily efficient with just a few. Also, if you're using a decent database like MySQL or PostgreSQL, then as you use them they'll start to learn what kind of queries you tend to make on them and start to optimise themselves for those queries.

Hope that helps,

— Robert J. Lee
 
Old 08-10-2004, 11:59 AM   #7
manofwax
LQ Newbie
 
Registered: Jul 2004
Location: Davis, Ca
Distribution: red hat
Posts: 13

Original Poster
Rep: Reputation: 0
That helps, Thank Robert.

But one more question, my main question is how to test how well the unix machine is performing comparing to MS window.

For unix, i'm using php, and mysql
for window, i'm using asp and sql

And i want to compare their performance (cpu usage%, memory...) Any idea of what i can do? THanks a lot. Here is my aim screen name, manofwax21, if you don't mind, i'd like to discuss with you. thanks A LOT =)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
So many errors when I typed the "make" and "make install" command Niceman2005 Linux - Software 23 07-22-2009 02:33 PM
Starting an xterm window that is "always on top" on command line azilkie Fedora 1 10-07-2005 09:17 PM
Chkrootkit "make sense" problem jmr0311 Linux - Security 1 08-26-2004 04:12 AM
How to make a SDL-window "Always on top"? ZX_SA Programming 1 06-01-2004 07:35 AM
"top" command memory question chanys Linux - General 4 03-14-2003 08:01 PM


All times are GMT -5. The time now is 05:16 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration