# Apache22 + FreeBSD 9.0  - slow performance in compare with Fedora 16



## nimnull (Feb 6, 2012)

Dear all,

I decided to migrate my small web server, it uses heavy mod_perl scripts + mysql + snmp + rrdtool. Kind of a network analyzing server.

Everything works on FreeBSD, but Apache server response is twice slower then on linux. I did not make any special changes. I just installed *pkg_add* apache, mod_perl, mysql. The same thing I did on linux.

First problem is that httpd uses about 2,5% CPU on freebsd FreeBSD, when I just refresh the page. It is normally never exceeding 0.5% on linux. Yes, I use a lot of mod_perl scripts and generate SVG graphics, rrd_graphs - but it is normal job. I enabled LogLevel debug for Apache and did not get anything.

Second - apache makes too many child processes - about 8 or 9. Even then I put the same config to MPM section. Apache on linux makes only 3 additional process, apache on freebsd FreeBSD makes 8. Why?

Can someone explain my what I did wrong? I can't migrate in that conditions - freebsd FreeBSD works slower then linux.

Thanks in advance.


----------



## Anonymous (Feb 6, 2012)

nimnull said:
			
		

> ...
> Second - apache makes too many child processes - about 8 or 9. Even then I put the same config to MPM section. Apache on linux makes only 3 additional process, apache on freebsd FreeBSD makes 8. Why?



The "plain" apache port installs apache with the prefork MPM, and this forks a new child process for any new connection. You might want to install the  www/apache-worker-mpm. This is the Apache port with a threaded MPM, and it should give you the experience as you described for "Apache on linux".


----------



## jhunter1 (Feb 7, 2012)

nimnull said:
			
		

> Everything works on FreeBSD, but Apache server response is twice slower then on linux.


Your post is not clear if you used the same config for Apache as on Linux. If not, you may want to copy it and compare, otherwise the compare is misleading.
As rolfheinrich mentioned, a different worker model could make a big difference.

There are other tweaks which were probably done in respect to MySQL as well, so you may want to copy its config too.

P.S.: I assume MySQL, rrdtool, mod_perl and Apache versions are the same as Linux.


----------



## nimnull (Feb 7, 2012)

To rolfheinrich:

Both apache has the same config:

```
FreeBSD 172.16.248.140:
Server Settings

Server Version: Apache/2.2.21 (FreeBSD) DAV/2 mod_perl/2.0.5 Perl/v5.12.4
Server Built: Dec 5 2011 17:10:45
Server loaded APR Version: 1.4.5
Compiled with APR Version: 1.4.5
Server loaded APU Version: 1.3.12
Compiled with APU Version: 1.3.12
Module Magic Number: 20051115:30
Hostname/port: 172.16.248.140:80
Timeouts: connection: 60    keep-alive: 5
MPM Name: Prefork
MPM Information: Max Daemons: 256 Threaded: no Forked: yes
Server Architecture: 64-bit
Server Root: /usr/local
Config File: /usr/local/etc/apache22/httpd.conf
Server Built With: -D APACHE_MPM_DIR="server/mpm/prefork" -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_FLOCK_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D
 HTTPD_ROOT="/usr/local" -D SUEXEC_BIN="/usr/local/bin/suexec" -D DEFAULT_ERRORLOG="logs/error_log" -D
 AP_TYPES_CONFIG_FILE="etc/apache22/mime.types" -D SERVER_CONFIG_FILE="etc/apache22/httpd.conf"
```




```
Linux 172.16.248.139:
Server Settings

Server Version: Apache/2.2.17 (Unix) DAV/2 mod_apreq2-20090110/2.8.0 mod_perl/2.0.4 Perl/v5.12.2
Server Built: Oct 27 2010 10:04:08
Server loaded APR Version: 1.3.9
Compiled with APR Version: 1.3.9
Server loaded APU Version: 1.3.10
Compiled with APU Version: 1.3.9
Module Magic Number: 20051115:25
Hostname/port: 172.16.248.139:80
Timeouts: connection: 60    keep-alive: 5
MPM Name: Prefork
MPM Information: Max Daemons: 256 Threaded: no Forked: yes
Server Architecture: 32-bit
Server Root: /etc/httpd
Config File: /etc/httpd/conf/httpd.conf
Server Built With: -D APACHE_MPM_DIR="server/mpm/prefork" -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D
 HTTPD_ROOT="/etc/httpd" -D SUEXEC_BIN="/usr/sbin/suexec" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="conf/mime.types" -D
 SERVER_CONFIG_FILE="conf/httpd.conf"
```

As you can see all of them have the same config. Actually, I did it for the investigation.


I also have to say sorry, because I forgot to stated here yesterday, that both Linux and FreeBSD works on vmware:

```
Guest OS:        Red Hat Enterprise Linux 6 (32-bit)
VM Version:      7
CPU:             4 vCPU
Memory:          2048 MB
Memory Overhead: 49.86 MB
```


```
Guest OS:        FreeBSD (64-bit)
VM Version:      8
CPU:             16 vCPU
Memory:          2048 MB
Memory Overhead: 540.26 MB
```




To: jhunter1
Firefox with web console:

On Linux:

```
[11:26:27.503] GET [url]http://172.16.248.139/perl-pages/248.2-248.3[/url] [HTTP/1.1 200 OK 375ms]
```
On FreeBSD

```
[11:27:09.427] GET [url]http://172.16.248.140/perl-pages/248.2-248.3[/url] [HTTP/1.1 200 OK 874ms]
```
Mysql has also the same configuration.



Thanks in advance


----------



## Anonymous (Feb 8, 2012)

nimnull said:
			
		

> To rolfheinrich



Well, I don't know whether responding to this message really results in anything, anyway, here it goes. In your first post, you claimed that you used pkg_add for installing Apache on an otherwise clean install of FreeBSD 9.

You said that the version information of that Apache installation is:


```
Server Version: Apache/2.2.21 (FreeBSD) DAV/2 mod_perl/2.0.5 Perl/v5.12.4
Server Built: Dec 5 2011 17:10:45
Server loaded APR Version: 1.4.5
Compiled with APR Version: 1.4.5
Server loaded APU Version: 1.3.12
Compiled with APU Version: 1.3.12
Module Magic Number: 20051115:30
Hostname/port: 172.16.248.140:80
Timeouts: connection: 60 keep-alive: 5
MPM Name: Prefork
MPM Information: Max Daemons: 256 Threaded: no Forked: yes
Server Architecture: 64-bit
Server Root: /usr/local
Config File: /usr/local/etc/apache22/httpd.conf
Server Built With:
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_FLOCK_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D HTTPD_ROOT="/usr/local"
 -D SUEXEC_BIN="/usr/local/bin/suexec"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="etc/apache22/mime.types"
 -D SERVER_CONFIG_FILE="etc/apache22/httpd.conf"
```

For me, on a fresh FreeBSD 9 install with a pkg_added Apache, the command *httpd -V* shows the following result:


```
Server version: Apache/2.2.21 (FreeBSD)
Server built:   Dec  5 2011 17:10:45
Server's Module Magic Number: 20051115:30
Server loaded:  APR 1.4.5, APR-Util 1.3.12
Compiled using: APR 1.4.5, APR-Util 1.3.12
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_FLOCK_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/usr/local"
 -D SUEXEC_BIN="/usr/local/bin/suexec"
 -D DEFAULT_PIDLOG="/var/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="/var/run/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="etc/apache22/mime.types"
 -D SERVER_CONFIG_FILE="etc/apache22/httpd.conf"
```

This does not look quite the same, so where exactly do your version and build parameters come from?

In your first post, you said that you are comparing FreeBSD 9 with Fedora 16, now suddenly Fedora 16 turns out to be  Red Hat Enterprise Linux 6 (32-bit) in a VMWare installation.

Finally, you installed a 64bit FreeBSD 9 Guest into a VMWare host having 16 virtual CPUs, and you compare this with a 32bit Linux Guest into a VMWare host having 4 virtual CPUs. I would expect FreeBSD 4 times more slower, because the real CPUs are divided into 4 times more vCPUs. As the said test setup is only 2 times slower, this would eventually mean that FreeBSD 9 (amd64) as such is 2 times faster than Red Hat Enterprise Linux 6 (32-bit) or is it now Fedora 16 again.

What else, if not this, did you want to prove?


----------



## throAU (Feb 8, 2012)

Also, the RAM overhead is higher with more CPUs, potentially leaving less RAM on the host for file caching, or even forcing swappng to happen earlier/more frequently.  What physical hardware are the VMs running on?  Same physical box?  Is it in workstation, or ESX(i)?

If it's on workstation, the host machine's load will also impact the VM(s), as there are no resource reservations for CPU.

The VM hardware version is also different.

Were the VM tools installed in both hosts?

What filesystem are both VMs running?

This "test" really is an apples to oranges comparison.


----------



## nimnull (Feb 8, 2012)

Thanks everyone for your answers.

I have to say sorry for asking wrong question in the wrong thread.

I had to check everything before blame on apache. Later I found out about truss and with strace for linux checked perl on both. Linux and FreeBSD did the same, but FreeBSD did it slower. Then I remembered about nasty behavior vmware to add its modules within installation without any prompt, and of course, vmware adds 3 kernel modules to linux. It did not happen for FreeBSD.
I am not sure that those 3 modules helped Linux to work quicker on vmware, I do think may be Linux is more compatible with vmware than FreeBSD. I will investigate it later. Also, as long I do not manage vmware by my self, I can't move FreeBSD to the same VM with Linux, but it will happen and then I compare them.

So, my right question should be: why Linux on vmware works quicker then Freebsd.

I also notice that command "find / -name ..." gives results (on second and third times) on Linux also quicker then on FreeBSD. So, I don't know what makes Linux works better - more flexible kernel or 3 vmware modules. I will try to install vmmemctl.ko and vmblock.ko, hope that it will help.


Thanks in advance.


----------



## throAU (Feb 9, 2012)

FreeBSD is fine in VMware.  You need to install the vmware tools for proper performance though.

However, irrespective of that, the fact that your VM virtual hardware platforms are totally different between the two instances invalidates any real performance comparison.  If you were to install identical copies of Linux in both VMs, the performance would be different.

Linux can use the enhanced vmxnet3 driver, FreeBSD can't.  This will improve network throughput in the Linux VM, however I would not expect the performance to be drastically different unless under heavy network throughput.


----------



## nimnull (Feb 10, 2012)

I installed open-vm-tools-nox11 and enabled only 3 modules:
vmblock
vmmemctl
vmxnet
And now Apache response time is the same like on Linux Fedora. I am happy.
Thank everyone for help.


----------

