Linux/Apache performance very slow even on local network
Solution 1
Apache is a complex beast and may be the problem here...or may not. I would start debugging the general network slowness before reaching into that dark hole. Specifically:
-
Try running netcat in server mode on a port, configured to hand out a local file's contents, and then connecting to it from the machine itself. For example:
while true ; do nc -l 80 < index.html ; done
That eliminates apache, the physical network, and DNS or IP link issues. Note that the file served is local - no NFS mounts for example.
- Same again, but connect over the local network from the same subnet
- Again, but from a different subnet
If you get this far, your server is good, and your network routing is OK too.
Now clean up DNS, and make quite sure that reverse lookups work. dig 4.3.2.1.in-addr.arpa for example to test the lookup of the 1.2.3.4 address. If it's slow, that's a problem and you'll need to noodle about with /etc/resolv.conf, dnsmasq or whatever you have. Don't proceed until this is rock solid. Worth trying SSH/SCP into the box at this point too - it should be fast.
Next, Apache. If you make it this far you know your network is good, DNS works and the box is OK. So that leaves your application (ie the www server). Try to strip down the config to the bare minimum and see how you get on. For example here is one.
Good luck!
Solution 2
Edit: Try these one at a time!
A couple of things jump out:
MaxRequestsPerChild 0
If you have no reason to use 0
(process never dies) then increase it by a little (default is 1000
) to say 100
and restart, and see if that gets you improvements. May prevent memory leaks.
MaxClients 150
Depending on how much memory your server has, and if all three modules are being called at at the same time, you may run out of memory. For e.g., if your apache process is 20MB in size, you will have 150 Clients x 20MB x 3 mods = 9000 MB ~ 8.8 GB. Even if only one of them is being called, then you are using up ~ 2.9 GB.
If you are not using all three mods, uninstall the unneeded ones from your apache instance.
Also, how about the output of top
and free -m
during this slow performance?
Solution 3
What happens when you attempt to access via lynx
or curl
from the local host or from a machine on the network?
Also, look at this block from Apache:
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
I would recommend getting rid of that whole block, restarting Apache & trying again. I have had odd hangs as well when Apache does some deny
actions against a localhost or a local IP address. Weird DNS lookup issues can hang Apache on a per request basis. And a delay of 12 seconds per page makes me think that is the cause. But it's not 100% clear from your config if the block I am pointing out is the culprit or not. But do some kind of search for DNS lookup related tasks connected to Apache.
Also, it's hard to say what settings should be on your server without observing your sites real traffic, but I suggest that your KeepAlive
settings seem resource heavy. I would recommend changing as so:
KeepAlive On
MaxKeepAliveRequests 50
KeepAliveTimeout 2
I would also recommend lowering MaxClients
and adding ServerLimit
adjusting MaxRequestsPerChild
as well in your main apache2.conf
like so:
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 90
MaxClients 90
MaxRequestsPerChild 2000
</IfModule>
<IfModule mpm_worker_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 64
ThreadLimit 64
ThreadsPerChild 25
ServerLimit 90
MaxClients 90
MaxRequestsPerChild 2000
</IfModule>
<IfModule mpm_event_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 64
ThreadLimit 64
ThreadsPerChild 25
ServerLimit 90
MaxClients 90
MaxRequestsPerChild 2000
</IfModule>
Also, I highly recommend installing Munin on your machine to get a grip on resource usage. Saves a lot of headaches & gives a good broad perspective on things.
Related videos on Youtube
ron653
Updated on September 18, 2022Comments
-
ron653 almost 2 years
I try to run this code:
#include <stdio.h> int main() { char str1[20], str2[30]; printf("Enter name: "); scanf("%s", str1); getc(stdin); printf("Enter your website name: "); scanf("%s", str2); getc(stdin); printf("Entered Name: %s\n", str1); printf("Entered Website:%s", str2); return(0); }
from http://www.tutorialspoint.com/c_standard_library/c_function_scanf.htm
so I expected to get this in the console:
Enter name: admin Enter your website name: admin.com Entered Name: admin Entered Website: admin.com
but actually I got this in my console:
admin admin.com Enter name: Enter your website name: Entered Name: admin Entered Website:admin.com
so I would like to know why the scanf executed before the print. maybe its related to using eclipse as IDE?
-
Admin over 12 yearsPost the output of diagnostic tools such
top
,free -m
during the slow performance ... maybe the system is swapping? running low on CPU? memory? Also, post relevant portions of your httpd.conf (particularly,StartServers, MinSpareServers, MaxSpareServers, ServerLimit, MaxClients, MaxRequestsPerChild
) and vhost configs. This should provide a good starting point for someone to assist you further. -
Admin over 12 yearsI did add some more information!
-
jsaji over 8 yearsYou might need to flush the stdout. printf will flush the stream on encountering '\n'.
-
Filkolev over 8 yearsTry to run the program from a terminal, it should be fine.
-
ebby94 over 8 yearsIt's working as intended in
gcc
compiler. Issue must be with your IDE. -
ron653 over 8 yearshow can I flush? I try to add '\n' on the printf and scanf but it didnt work.
-
-
Rishabh Kumar over 3 yearsLooks like this answer has already been answered. If you have something to add to that, edit your post accodingly.