# apache requests max out the cpu



## gremlin (Mar 5, 2010)

Running FBSD 7.0 apache22 php5

```
CPU: Intel(R) Celeron(R) CPU 2.40GHz (2391.15-MHz 686-class CPU)
  Origin = "GenuineIntel"  Id = 0xf29  Stepping = 9
real memory  = 2139029504 (2039 MB)
avail memory = 2083627008 (1987 MB)
```

Whenever a request is made to apache the cpu runs to 58+% for a single request, hitting F5 3 times will run the cpu right up to 95%
However the swap only builds to 2%
It seems as tho everything is being funneled through the cpu and totally bypassing swaping. 
I've spent a couple days on the apache boards and cut everything back as far as I can. These changes had no effect on the cpu issue. 
I don't have any services turned on except apache, PHP, qmail.

Sure would appreciate any suggestions on what to look for with this. 
Thanks


----------



## gilinko (Mar 5, 2010)

It's has probably nothing to do with the apache process itself, but for what you are requesting from the apache server(ie the web page) there probably is some sort of race condition. As the swap is used for memory, not cpu cycles  Try to access a page that doesn't use php and see if the problem persists. 

If it disappears, then the problem is with the php code.


----------



## gremlin (Mar 5, 2010)

PHP dosen't seem to be the problem, I checked this earlier and rechecked it again this morning in case of any changes I made worked. I get the same response for cgi, jpg, gif. 
I've been through each log a few times looking for something, but everything is working good it just takes all the cpu I have to get it to work. 
I have 2 identical systems- one is live and the other is our test system, both run identical problems. My test system dosen't have bind, qmail, running apache and php only. 
An earlier version of FBSD 4.8? I was using always used mostly swap when running our cgi scripts, I had to build more swap space onto one of the drives it only had a 486 cpu in it.


----------



## gilinko (Mar 5, 2010)

The swap has nothing to do with this. It's only used by the system if the RAM is getting full and it need to free some of it up.

It usually is a race condition(like a for() loop of enternity) that has gone haywire somewhere. None here can help you if you don't supply more information. Like _uname -a_, how did you install the software(ports/packages), your configuration files etc.


----------



## gremlin (Mar 5, 2010)

I didn't want to flood the board with a bunch of non-required information so I only post what I am asked for  
FBSD 7 was installed from the image files, it's not an upgrade from any previous versions.
Everything else except for qmail was installed from the ports. 

```
uname -a
FreeBSD gremlin.streichs.com 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Sun Feb 24 19:5
9:52 UTC 2008     [email]root@logan.cse.buffalo.edu[/email]:/usr/obj/usr/src/sys/GENERIC  i386
 dmesg.toady
Copyright (c) 1992-2008 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
	The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
FreeBSD 7.0-RELEASE #0: Sun Feb 24 19:59:52 UTC 2008
    [email]root@logan.cse.buffalo.edu[/email]:/usr/obj/usr/src/sys/GENERIC
Timecounter "i8254" frequency 1193182 Hz quality 0
CPU: Intel(R) Celeron(R) CPU 2.40GHz (2391.15-MHz 686-class CPU)
  Origin = "GenuineIntel"  Id = 0xf29  Stepping = 9
  Features=0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE>
  Features2=0x4400<CNXT-ID,xTPR>
real memory  = 2139029504 (2039 MB)
avail memory = 2083627008 (1987 MB)
ACPI APIC Table: <IntelR AWRDACPI>
ioapic0 <Version 2.0> irqs 0-23 on motherboard
kbd1 at kbdmux0
ath_hal: 0.9.20.3 (AR5210, AR5211, AR5212, RF5111, RF5112, RF2413, RF5413)
hptrr: HPT RocketRAID controller driver v1.1 (Feb 24 2008 19:59:27)
acpi0: <IntelR AWRDACPI> on motherboard
acpi0: [ITHREAD]
acpi0: Power Button (fixed)
Timecounter "ACPI-fast" frequency 3579545 Hz quality 1000
acpi_timer0: <24-bit timer at 3.579545MHz> port 0x408-0x40b on acpi0
cpu0: <ACPI CPU> on acpi0
p4tcc0: <CPU Frequency Thermal Control> on cpu0
acpi_button0: <Power Button> on acpi0
pcib0: <ACPI Host-PCI bridge> port 0xcf8-0xcff on acpi0
pci0: <ACPI PCI bus> on pcib0
vgapci0: <VGA-compatible display> mem 0xe0000000-0xe7ffffff,0xec100000-0xec17ffff irq 16 at device 2.0 on pci0
agp0: <Intel 82845M (845M GMCH) SVGA controller> on vgapci0
agp0: detected 8060k stolen memory
agp0: aperture size is 128M
uhci0: <Intel 82801DB (ICH4) USB controller USB-A> port 0xd800-0xd81f irq 16 at device 29.0 on pci0
uhci0: [GIANT-LOCKED]
uhci0: [ITHREAD]
usb0: <Intel 82801DB (ICH4) USB controller USB-A> on uhci0
usb0: USB revision 1.0
uhub0: <Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1> on usb0
uhub0: 2 ports with 2 removable, self powered
uhci1: <Intel 82801DB (ICH4) USB controller USB-B> port 0xd000-0xd01f irq 19 at device 29.1 on pci0
uhci1: [GIANT-LOCKED]
uhci1: [ITHREAD]
usb1: <Intel 82801DB (ICH4) USB controller USB-B> on uhci1
usb1: USB revision 1.0
uhub1: <Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1> on usb1
uhub1: 2 ports with 2 removable, self powered
uhci2: <Intel 82801DB (ICH4) USB controller USB-C> port 0xd400-0xd41f irq 18 at device 29.2 on pci0
uhci2: [GIANT-LOCKED]
uhci2: [ITHREAD]
usb2: <Intel 82801DB (ICH4) USB controller USB-C> on uhci2
usb2: USB revision 1.0
uhub2: <Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1> on usb2
uhub2: 2 ports with 2 removable, self powered
ehci0: <Intel 82801DB/L/M (ICH4) USB 2.0 controller> mem 0xec180000-0xec1803ff irq 23 at device 29.7 on pci0
ehci0: [GIANT-LOCKED]
ehci0: [ITHREAD]
usb3: EHCI version 1.0
usb3: companion controllers, 2 ports each: usb0 usb1 usb2
usb3: <Intel 82801DB/L/M (ICH4) USB 2.0 controller> on ehci0
usb3: USB revision 2.0
uhub3: <Intel EHCI root hub, class 9/0, rev 2.00/1.00, addr 1> on usb3
uhub3: 6 ports with 6 removable, self powered
pcib1: <ACPI PCI-PCI bridge> at device 30.0 on pci0
pci1: <ACPI PCI bus> on pcib1
fxp0: <Intel 82551 Pro/100 Ethernet> port 0xc000-0xc03f mem 0xec020000-0xec020fff,0xec000000-0xec01ffff irq 21 at device 6.0 on pci1
miibus0: <MII bus> on fxp0
inphy0: <i82555 10/100 media interface> PHY 1 on miibus0
inphy0:  10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
fxp0: Ethernet address: 00:e0:81:60:e0:37
fxp0: [ITHREAD]
isab0: <PCI-ISA bridge> at device 31.0 on pci0
isa0: <ISA bus> on isab0
atapci0: <Intel ICH4 UDMA100 controller> port 0x1f0-0x1f7,0x3f6,0x170-0x177,0x376,0xf000-0xf00f at device 31.1 on pci0
ata0: <ATA channel 0> on atapci0
ata0: [ITHREAD]
ata1: <ATA channel 1> on atapci0
ata1: [ITHREAD]
pci0: <serial bus, SMBus> at device 31.3 (no driver attached)
pci0: <multimedia, audio> at device 31.5 (no driver attached)
acpi_tz0: <Thermal Zone> on acpi0
fdc0: <floppy drive controller> port 0x3f0-0x3f5,0x3f7 irq 6 drq 2 on acpi0
fdc0: [FILTER]
sio0: <16550A-compatible COM port> port 0x3f8-0x3ff irq 4 flags 0x10 on acpi0
sio0: type 16550A
sio0: [FILTER]
sio1: <16550A-compatible COM port> port 0x2f8-0x2ff irq 3 on acpi0
sio1: type 16550A
sio1: [FILTER]
atkbdc0: <Keyboard controller (i8042)> port 0x60,0x64 irq 1 on acpi0
atkbd0: <AT Keyboard> irq 1 on atkbdc0
kbd0 at atkbd0
atkbd0: [GIANT-LOCKED]
atkbd0: [ITHREAD]
psm0: <PS/2 Mouse> irq 12 on atkbdc0
psm0: [GIANT-LOCKED]
psm0: [ITHREAD]
psm0: model IntelliMouse Explorer, device ID 4
pmtimer0 on isa0
orm0: <ISA Option ROMs> at iomem 0xc0000-0xcafff,0xcc000-0xcd7ff pnpid ORM0000 on isa0
ppc0: <Parallel port> at port 0x378-0x37f irq 7 on isa0
ppc0: Generic chipset (NIBBLE-only) in COMPATIBLE mode
ppbus0: <Parallel port bus> on ppc0
ppbus0: [ITHREAD]
plip0: <PLIP network interface> on ppbus0
lpt0: <Printer> on ppbus0
lpt0: Interrupt-driven port
ppi0: <Parallel I/O> on ppbus0
ppc0: [GIANT-LOCKED]
ppc0: [ITHREAD]
sc0: <System console> at flags 0x100 on isa0
sc0: VGA <16 virtual consoles, flags=0x300>
vga0: <Generic ISA VGA> at port 0x3c0-0x3df iomem 0xa0000-0xbffff on isa0
Timecounter "TSC" frequency 2391152504 Hz quality 800
Timecounters tick every 1.000 msec
hptrr: no controller detected.
ad0: 38166MB <WDC WD400BB-00JHC0 05.01C05> at ata0-master UDMA100
ad1: 38166MB <WDC WD400BB-00JHC0 05.01C05> at ata0-slave UDMA100
acd0: CDRW <LITE-ON LTR-24102B/5S0D> at ata1-master UDMA33
Trying to mount root from ufs:/dev/ad0s1a
IP Filter: v4.1.28 initialized.  Default = pass all, Logging = enabled
ipfw2 (+ipv6) initialized, divert loadable, rule-based forwarding disabled, default to deny, logging disabled
```


----------



## gilinko (Mar 5, 2010)

If it's only apache, I would start by disabling all but the absolute necessary modules(ie remove: mod_php, mod_cgi etc) and see if that helps. Just requesting static static content, like the "It works!" apache webpage that comes with the install.

But before that I would seriously patch and upgrade your base system, as you seem to be running a default install of 7.0 without any of the security patches at all to the kernel or base system. Do note that the 7.0-RELEASE reached it's _End of Life_ almost 1 year ago, and you have no patches installed for the last 2 years. Have a look at the freebsd-update tool and move your system at least to a 7.1-RELEASE which has an extended support for about one more year(Jan 31 2011).


----------



## gremlin (Apr 22, 2010)

Wanted to stop by and say thanks for your advice, went with a complete new build Freebsd 8 on an intel I3 board. Works like a charm.


----------

