php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10299 CPU and Memory Spike
Submitted: 2001-04-11 18:03 UTC Modified: 2002-08-13 22:50 UTC
From: goten at mylaptop dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 4.0.4pl1 OS: FreeBSD 4.2 Stable
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: goten at mylaptop dot com
New email:
PHP Version: OS:

 

 [2001-04-11 18:03 UTC] goten at mylaptop dot com
I am running on FreeBSD 4.2 Stable, Apache 1.3.19 + PHP 4.0.4pl1 + Modssl on a Dual P2 400mhz with 256mb ram.  From time to time, one of the httpd process will eat up all the CPU time and memory, and after around 5 to 10 seconds, it goes back to normal  Even a Very simple script like

<? 
echo "test";
?>

can make it happen. 1 out of 25 reload of the above script can make the spike happen.  But the web server do not crash though.  If I run on a script with heavy database access, it happen 1 out of 10 if I press reload button continously.

BTW, is that normal for Apache to take up 30% of the CPU time to excute one single PHP-database-driven page?

I search the bugs database and I found another user have the exact problem like what I am having right now.  His bug id is #9154.

This is how I configure PHP
./configure  --with-mysql=/usr/local/mysql --with-apxs=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/etc --enable-track-vars --enable-ftp  --with-gd=/usr/local --with-pcre-regex=/usr/local/ 
--with-jpeg-dir=/usr/local --with-xpm-dir=/usr/X11R6

With or Without modssl enable does not make a difference.  Both can cause the spike.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-14 07:59 UTC] goten at mylaptop dot com
This is vmstat show if I keep reloading the script

procs      memory     page                    disks     faults      cpu
 r b w     avm   fre  flt  re  pi  po  fr  sr da0 da1   in   sy  cs us sy id
 1 4 0   73860 13432    4   0   0   0   0   0   2   0  382 3804 258 16  1 83
 0 4 0   73860 13424    4   0   0   0   0   0   0   0  357 3789 245 15  4 81
 1 4 0   73860 13424    4   0   0   0   0   0   0   0  373 3763 263 14  3 83
 2 4 0   73860 13416  142   0   0   0 139   0   0   0  402 6155 285 26  4 70
 0 4 0   73860 13408    4   0   0   0   4   0  11   0  366 3179 220 11  2 87
 1 4 0   73860 13400    4   0   0   0   0   0   0   0  358 3943 257 15  3 82
 2 4 0   73860 13400    4   0   0   0   0   0   0   0  340 4201 240 12 42 45
 2 4 0   73860 13400    4   0   0   0   0   0   0   0  240 1842  90  0 100  0
 2 4 0   73116 13400    4   0   0   0   0   0  19   0  265 1802  98  0 100  0
 2 4 0   73116 13400    4   0   0   0   0   0   0   0  241 1753  93  0 100  0
 2 4 0   73116 13400    4   0   0   0   0   0   0   0  239 1729  96  0 100  0
 2 4 0   73116 13400    4   0   0   0   0   0   0   0  241 1612  94  0 100  0
 2 4 0   73116 13400    4   0   0   0   0   0   0   0  243 1576  97  0 100  0
 2 4 0   73116 13400    4   0   0   0   0   0   0   0  243 1541  98  0 100  0
 2 4 0   73116 13400    4   0   0   0   0   0   0   0  239 1487 102  0 100  0
 2 4 0   73116 13400    4   0   0   0   0   0   0   0  241 1401  93  0 100  0
 2 4 0   73116 13400    4   0   0   0   0   0   0   0  251 1405 100  0 100  0
 2 4 0   73116 13400    4   0   0   0   0   0   0   0  246 1338 101  0 100  0
 2 4 0   73116 13400    4   0   0   0   0   0   0   0  238 1297  94  0 100  0
 2 4 0   73860 13400    4   0   0   0   0   0   0   2  243 1282 100  0 100  0
 2 4 0   73860 13400    4   0   0   0   0   0   0   0  239 1223  89  0 100  0
 2 4 0   73860 13400    4   0   0   0   2   0   9  16  300 1180  92  0 100  0
 procs      memory     page                    disks     faults      cpu
 r b w     avm   fre  flt  re  pi  po  fr  sr da0 da1   in   sy  cs us sy id
 3 4 0   73860 13400    4   0   0   0   0   0   0   0  251 1156  90  0 100  0
 3 4 0   50296 13400    4   0   0   0   0   0   6   0  258 1116  93  0 100  0
 2 4 0   50296 13400    4   0   0   0   0   0   0   0  240 1108  83  0 100  0
 3 4 0   50296 13400    4   0   0   0   0   0   0   0  245 1064  92  0 100  0
 3 4 0   46988 13400    4   0   0   0   0   0   0   0  242 1031  83  0 100  0
 3 4 0   46988 13400    4   0   0   0   0   0   0   0  242  989  82  0 100  0
 2 4 0   46988 13400    4   0   0   0   0   0   0   0  243 1010  85  0 100  0
 2 4 0   46988 13400    4   0   0   0   0   0   1   0  241  985  81  0 100  0
 2 4 0   46988 13400    4   0   0   0   0   0   0   0  241  971  89  1 99  0
 2 4 0   46988 13400    4   0   0   0   0   0   0   0  243  940  74  0 100  0
 3 4 0   46988 13400    4   0   0   0   2   0   8   0  250  926  80  0 100  0
 2 4 0   46988 13400    4   0   0   0   0   0   1   0  245  930  88  0 100  0
 3 4 0   46988 13400    4   0   0   0   0   0   0   0  240  905  80  0 100  0
 2 4 0   46988 13400    4   0   0   0   0   0   7   0  253  920 100  0 98  2
 3 4 0   47332 13056   90   0   0   0   0   0   0   0  239 2113 116  3 97  0
 2 4 0   46588 13048    4   0   0   0   0   0   1   0  243 2334 103  1 99  0
 1 4 0   46244 13392    4   0   0   0  86   0   8   0  276 4383 140  7 19 74
 1 4 0   47896 13184   59   0   0   0   0   0   2   0  275  621  56  7  1 92
 0 4 0   47896 13152   20   0   0   0   0   0   1   0  253  471  46  6  1 93
 1 4 0   47492 13372   18   0   0   0  64   0   0   0  251  478  43  0  1 99
 0 4 0   47492 13372    4   0   0   0   0   0   0   0  235  440  40  0  0 100
 0 4 0   47492 13372    4   0   0   0   0   0   0   0  238  442  40  0  2 98

The CPU time drop from 80 all the way to zero and make the Apache hang for like 30 seconds and the resume back again.  It happens VERY often if I only have like 30 users surf the website at the same time.  It pretty much bring the web server down if I have around 50 users surft the site
 [2001-04-14 09:00 UTC] goten at mylaptop dot com
I found the problem.  since the script I use have a lot of include and require statement.  just a script include a bunch of files and keep reloading the page will kill the server in no time.  I attach a sample config file I usually include, just make a test.php and include this file like 10 times to simulate a lot of include files.  And then, just keep reloading test.php.  You should see the script take a lot of CPU time and eventually the httpd eat all the CPU time and the process hang.  From command "top", one of the httpd process keep eating up CPU time.

The following is the sample config file 

<?

/*Root directory */
$config[root_path] = "/usr2/home/business/test/www";
$config[w3b_path] = "/usr2/home/business/test/www/wwwthreads";
$config[data_path] = "/usr2/home/business/test/data";
$config[rdf_path] = "/usr2/home/business/test/www/rdf";


/* database */

include $config[root_path]."/db.php";

/* global */
$config[sitename] = "www.test.net"; 
$config[root_url] = "http://www.test.net/";


// Cookie Setting
$config[cookie_path]  = "/"; # web root directory 
$config[CookieURL] = ".test.net";
$config[cookieTTL] = 7200; // in seconds


$config[minpass] 	= 3;  # Minimum user password length in characters



/* language and locale */
$config[language]	= "english";	# [english] english, [big5] BIG5 code


$config[locale]		= "english";	# Used for translation of date-related stuff

/* story control */
$config[commentmax] 	= 4096;
$config[abstractlen]	= 4996; #length of abstract show on first page

$config[icon_width]	= 100;     # Topic icons width
$config[timezone] = "HKT";	#Time zone


$config[limitnews]	= 10;   # default number of stories per page
$config[older_story_num]	= 10;   # number of older stories to display

$config[anon_users]	= 0; # 1 to allow anonymous postings
						 # 0 to disable


/* theme control */

$config[def_theme]	= "Main"; # name of default theme (see themes/ directory for list)

/* mail settings */
$config[use_fake_email]	= 1; # Displays fake email addresses for users instead of the real ones

$config[notifyEmail] 	= "webmaster@test.net"; 	#address where you want to receive notice


//$config[CensorList]   = array('fuck','cunt','fucker','fucking','pussy','cock','c0ck','cum','bitch','shit');
$config[CensorList] = array("/fuck/s","/fuck/s","/fuck/s",
				"/[a-z]*fuck[a-z]*/is",
				"/[a-z]*cunt[a-z]*/is",
				"/[a-z]*pussy[a-z]*/is",
				"/[a-z]*cock[a-z]*/is",
				"/[a-z]*c0ck[a-z]*/is",
				"/[a-z]*shit[a-z]*/is",
				"/[a-z]*bitch[a-z]*/is",
				"/[a-z]*diu[a-z]*/is"
			);
# See also specific LOCALE definitions

$config[CensorMode]   = 3;	# 0: no filtering
			# 1: exact match
			# 2: match word beginnings
			# 3: match string anywhere in words
$config[CensorReplace]   =  "[CENSORED]" ;

/* allowable HTML tags. Used by check_html()
   Happily lifted (with mods) from phpslash */
$config[AllowableHTML] = array("p"=>1,   # 2 means accept all qualifiers: <foo bar>
                      "b"=>1,    # 1 means accept the tag only: <foo>
                      "i"=>1,
                      "a"=>2,
                      "em"=>1,
                      "br"=>1,
                      "strong"=>1,
                      "blockquote"=>1,
					  "img"=>2,
                      "tt"=>1,
                      "hr"=>1,
                      "li"=>1,
                      "ol"=>1,
					  "div"=>1,
                      "ul"=>1);

$config[AllowableHTMLtag] = "<b>,<i>,<a>,<em>,<br>,<strong>,<blockquote>,<tt>,<hr>,<li>,<ol>,<div>,<ul>";


/* poll settings */

$config[maxOptions] 	= 12;	# maximal number of options allowed
$config[BarScale] 	= 1;	# scale of result bar (in multiples of 100 pixels)

$config[warnCheaters] 	= 1;	# 1 - a notice issued on vote second try
			# 0 - silently ignores the vote

$config[maxOptions] = 10;


/* story stuff */

$reasons = array('As is', 	# "Normal"
		'Offtopic', 	# Bad Responses
		'Flamebait',
		'Troll',
		'Redundant',
		'Insightful', 	# Good Responses
		'Interesting',
		'Informative',
		'Funny',
		'Overrated',		# Last two are "special"
		'Underrated');



if ($config[dateString] == "") {
	switch ($config[locale]) {
		// specifier specs can be found on http://www.php.net/manual/function.strftime.php  /menthos
		case "english":	$config[dateString] = "%a, %b %d,%Y @ %I:%M %p"; break;
		case "french":	$config[dateString] = "%a %d %B %Y &agrave; %H:%M"; break;
		case "german":	$config[dateString] = "%a, %d. %b %Y %H:%M"; break;
		case "italian":	$config[dateString] = "%a %d %b %Y %H:%M"; break;
		case "swedish":	$config[dateString] = "%a %d %b %Y, %H:%M"; break;
		case "dutch":	$config[dateString] = "%a, %d. %b %Y %H:%M"; break;
		case "spanish":	$config[dateString] = "%a %d %b %Y %H:%M"; break;
		default:	$config[dateString] = "%a %b %d @ %H:%M"; break;
	}
}

?>
 [2001-05-07 12:44 UTC] derick@php.net
marking critical for php 4.0.6
 [2001-05-08 19:26 UTC] zeev@php.net
Is this fairly reproducible?
If it is, any chance you could build Apache with debug information (--enable-debug in configure), attach to an offending process (gdb /path/to/httpd <PID>), and run a backtrace ('bt')?

 [2001-05-09 01:08 UTC] goten at mylaptop dot com
What I found out is that using a lot of include_once, require_once + session will trigger the CPU and memory spike.  Add database access to the script can speed up the frequency of the spike.  And I also found out require_once DO leak memory.  pstat -T show that file in use will always increase.  Somehow require_once forgot to close the file after use.  lsof can give you a clear picture when you use require_once()

I changed my code using cookie and require() statement now.  And I delete all sess_files in /tmp seems to correct the problem.  This is the only change I made to eliminate the problem.

I can't reproduce the error now because the code that have problems have been changed and I don't have the backup.  But the combination of A lot of include_once, require_once, and session will trigger the spike, I am pretty sure because after I changed all that, the problem disappear.  Old session file in /tmp also contribute to the problem as well. 

BTW, the last time I checked, CVS version 4.06 in late April still have the problem.
 [2001-05-17 09:05 UTC] zeev@php.net
I'm unable to reproduce a fd leak using require_once() or include_once().
Do you have any script that reproduces this problem?

We can't really replicate your problem in general, but if somehow there's a resource leak in your setup, lots of different weird things could end up happening.
 [2001-05-20 14:39 UTC] jmoore@php.net
We cant reproduce this so not really critical, reutnring to analysed.

- James
 [2002-08-13 22:50 UTC] kalowsky@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 05 02:01:30 2024 UTC