Drupal Site Crashing Constantly - Help Debugging - php

So we have a site running Drupal 7.41 on apache and it crashes constantly (multiple times a week). When it crashes we just restart the VM and the page start working again until the next crash. I installed New Relic in hope that it will help pin point what are some of the reasons why the site is crashing but I'm new to Drupal and maintaining it that I'm not sure where to start.
I've went to the 'Recent logs messages' section in Drupal but that doesn't seem to help. The last has been offline for some time since the last time I restarted it and the log messages don't show anything critical... just 'Notices':
On New Relic I can see that the CPU and Memory are maxed out precisely when the site crashes which gives the impression that this might be the error. Initially the site had 1GB of RAM and that was increased to 2GB when we thought this might be the problem. However, we see that it keeps maxing out so we're not sure if there really needs to be more RAM installed to avoid these crashes or if its just Apache (httpd) that tends to use that much RAM even if its not needed?
As you can see, as I restart the server, everything seems to go back to normal.
Can anyone recommend a way to help me understand what might be the problem? Is it just that 2GB is not enough RAM? If so, how do I know how much RAM might be needed?
Thanks in advance!
UPDATE#1:
I was reading this article: http://fuseinteractive.ca/blog/drupal-performance-tuning-0 on some performing techniques on Apache specifically. The first thing they mentioned was to disable modules that you might not need in order to save memory and improve performance. Upon checking the Apache configuration directory (/etc/httpd/conf.d for CentOS) I found only a few modules enabled:
Should I disable any of those?
The second point they mentioned was to update some of Apache's Default Configuration Settings. I've set mines to these:
Timeout 30
MaxKeepAliveRequests 100
KeepAliveTimeout 5
UPDATE#2: MPM Settings Updated to these values:
StartServers 5
MinSpareServers 10
MaxSpareServers 20
ServerLimit 256
MaxClients 200
MaxRequestsPerChild 0
UPDATE#3: I increased the RAM to 4GB last night and so far the physical memory usage has been steady at ~2GB for the last 12 hours. It's a weekend so there's not much traffic to the site so let's see how this behaves in the next couple of days.

First of all, I would duplicate the environment to try several things in a non-production environment. Here are some ideas of what I would do:
Install the latest version of the Drupal core
Have a look at the contributed modules you are using. Make sure you have the latest version installed.
One by one, uninstall the contributed modules and verify whether the error keeps appearing. Try to do the same with the installed themes.
I have had some problems with cron tasks. You can use the Cron Debug module to isolate the cron tasks running from each module and try to identify the problem.
Just to discard an attack, use the Hacked! module to confirm that the code you have installed in your server matches the code of the core and contributes modules available on Internet.

There are two potential problems here:
Your traffic/complexity of your site are not match for your hardware
Your drupal core using more resources than should
Your hardware looks good for average drupal site so i would go for other option. Also in your graphic you can see that CPU is 100% used before crash which means either your site is under spam attack or some module causing the problem.
Go on admin/config/system/statistics and enable access log
Go on /admin/reports/pages and /admin/reports/visitors and check number of hits per page/user on crash time.
Go on admin/config/system/cron and disable cron to see if the problem
is on some of the cron tasks.
Also it is the best practice to use latest module releases. You can easily see that on admin/reports/updates/update (you should have update manager module enabled for this). Make sure you backup potential customization on current modules before you update them.

Related

Neither load front end nor back-end in Magento 2.2.3

I have installed Magento-2.2.3 in windows personal computer and after the installation it loaded first time well but after that it is not responding since an hour. Actually, I am new to Magento and anybody can tell about this problem?
Follow the below points this may help you.
enable all cache may help you. Full page cache .
MySQL 5.6 has some memory issues where a defaul config will use
about 500mb of ram, to fix set performance_schema = off in your
my.cnf and restart MySQL. Also make sure you have opcache turned on
and set to at least 64mb of ram and 10000 files cached, preferable
128mb. If you tune your config you can run on a 512mb vps but it's
tricky and you won't have enough ram for fpc on varnish and reddis
sessions. 1 gb vps with the above MySQL fix should work like a champ
out of the box on a vps.
There are lots of potential reasons why, but the most common is
around file system performance. In non-production mode especially,
we hit the disk pretty hard (lots of different files). E.g. in
developer mode we generate files on the fly (CSS etc). But without
more details (PHP version? using Vagrant? VM? Docker? OS? Memory? is
machine thrashing? etc), it is pretty hard to suggest something. Its
certainly not taking any where near that long on my laptop. Can you
provide any information about your setup? (But my first
investigation would be around I/O performance - for example using
Docker/VirtualBox with file syncing back to Windows is a dog -
because the file syncing is very slow.)

TYPO3 6.2 suddenly extreme slow (only frontend!)

We run several TYPO3 websites on Apache (Linux 3.16, mysql 5.6, PHP 5.6). One of our websites (TYPO3 6.2.19) is suddenly extremely slowly but only the frontend. Loading time is always more than 60s but maximum 1.8 min. Site did always run smooth and fast. No changes in server settings were made since the past days.
I already tried to restart apache and sql server, cleared all TYPO3 caches... no changes in frontend.
Any ideas what could cause this error?
Can you activate the scheduler extension and execute garbage collection tasks?
Then see, if that helps
Do you have access to the server and can you restart services?
Then try restarting apache
I had a similar situation once, the issue was based on wrong permissions and php session files that could not be deleted. Switching to memcache session handling for php solved the issue.

My long running laravel 4 command keeps being killed

I have a laravel 4 web project that implements a laravel command.
When running in the development homestead vm, it runs to completion (about 40 seconds total time).
However when running it on the production server, it quits with a 'killed' output on the command line.
At first i thought it was the max_execution_time in cli php.ini, so I set it to 0 (for unlimited time).
How can I find out what is killing my command?
I run it on ssh terminal using the standard artisan invokation:
php artisan commandarea:commandname
Does laravel 4 have a command time limit somewhere?
The vps is a Ubuntu 4.10 machine with mysql, nginx and php-fpm
So, firstly, thank you everyone who has pointed me in the right direction regarding PHP and laravel memory usage tracking.
I have answered my own question hoping that it will benefit laravel devs in the future, as my solution was hard to find.
After typing 'dmesg' to show system messages. I found that the php script was being killed by Linux.
So, I added memory logging calls into my script before and after each of the key areas of my script:
Log::Info('Memory now at: ' . memory_get_peak_usage());
Then I ran the script while watching the log output and also the output of the 'top' command.
I found that even though my methods were ending and the variables were going out of scope, the memory was not being freed.
Things that I tried, that DIDNT make any difference in my case:
unset($varname) on variables after I have finished with them - hoping to get GC to kick off
adding gc_enable() at beginning of script and then adding gc_collect_cycle() calls after a significant number of vars are unset.
Disabling mysql transactions - thinking maybe that is memory intensive - it wasnt.
Now, the odd thing was that none of the above made any difference. My script was still using 150mb or ram by time it killed!
The solution that actually worked:
Now this is definitely a laravel specific solution.
But my scripts purpose is basically to parse a large xml feed and then insert thousands of rows into mysql using Elequent ORM.
It turns out that Laravel creates logging information and objects to help you see the query performance.
By turning this off with the following 'magic' call, I got my script down from 150mb to around 20mb!
This is the 'magic;' call:
DB::connection()->disableQueryLog();
I can tell you by the time I found this call, I was grasping at straws ;-(
A process may be killed for several reasons:
Out of Memory
There are two ways to trigger this error: Exceed the amount of memory allocated to PHP script in php.ini, or exceed the available system memory. Check the PHP error log and php.ini file to rule out the first possibility, and use dmesg output to check for the second possibility.
Exceeded the execution time-out limit
In your post you indicate that you disabled the timeout via the max_execution_time setting, but I have included it here for completeness. Be sure that the setting in php.ini is correct and (for those using a web server instead of a CLI script) restart the web server to ensure that the new configuration is active.
An error in the stack
If your script is error-free and not encountering either of the above errors, ensure that your system is running as expected. When using a web server, restart the web server software. Check the error logs for unexpected output, and stop or upgrade related daemons and needed.
Had this issue on a Laravel/Spark project. just wanted to share if others have this issue.
Try a refresh/restart of your dev server if running Vagrant or Ubuntu before more aggressive approaches.
I accidentally ran install of dependency packages on a Vagrant server. I also removed and replaced a mirrored folder repeatedly during install errors. My error was on Laravel/Spark 4.~. I was able to run migrations on other projects; I was getting 'killed' very quickly, 300ms timeframe, on a particular project for nearly all commands. Reading other users, I was dreading trying to find the issue or corruption. In my case, a quick Vagrant reload did the trick. killed issue was resolved.

FuelPHP site using 10x more memory on remote server

I'm building a website using the FuelPHP framework, which by default prints the execution time and memory usage at the bottom of the page. Now I just noticed that on my local machine, I have a pretty small memory footprint:
Page rendered in 0.0304s using 0.721mb of memory.
I deployed exactly this site (including a snapshot of the database) to my remote test server and suddenly memory usage increases by a factor of 10:
Page rendered in 0.0963s using 7.099mb of memory.
I cannot explain such a big difference from the details of execution alone, so I think the deviation must be in the environment.
Unfortunately I'm mainly a programmer, not really a server admin, so I don't really know where to start looking. So I'm going to ask a bit of a general question, which will hopefully give me some useful pointers: where should I start looking? The code is exactly the same and as far as I am aware both machines (local laptop and remote server) are fairly standard Apache installations with PHP5. Any answers suggesting specific Apache or PHP settings that might cause this, or specific lines to search for in the logs, are welcome.
I realise this is a pretty general question that might get me some downvotes, any constructive critisism is welcomed instead. Basically, I'm at a loss where to even start looking, at the moment.
Update: I decided to first exclude the framework as the culprit, so I ran the following one-line script on both machines:
Locally I get a value of about 115, while the remote server reports about 600.
Update 2: Just noticed I'm running PHP5.5 locally but server is only at 5.3. Maybe some bug that got fixed later - will upgrade that first.
Thanks for the suggestions guys, I fixed the problem.
As noted in the update to the original post, I realised I was running PHP5.5 locally but server was only at 5.3. After some ppa-magic with apt and some help from other questions on SO I managed to install Apache 2.4 with PHP 5.5.x. Now I actually see
Page rendered in 0.0261s using 0.582mb of memory.
locally and remotely
Page rendered in 2.3184s using 1.238mb of memory.
Assuming that a factor 2 is caused by the server being 64-bit and not my development machine, I can live with the remaining difference.
Use Xdebug to find out what functions are using all your memory.
Most likely it's a bug or design flaw in the framework.
It can be difficult or even impossible to get Xdebug working depending on your server. But sometimes it's pre-installed and simple.

Windows 7 php + Symfony2 terribly slow

This is an issue I've been having for a long time. I want to run PHP applications on my windows computer and it has a terribly high load time, around 10-25 seconds. I have tried many things:
First I tried a simple XAMPP installation
I read WAMP might be faster, so I tried WAMP, too. It gave me the same results
Then I installed an nginx server with PHP, but it did not help either
Finally, I installed an Ubuntu 11.10 in VirtualBox and I shared my windows files containing my project, but the result was even worse: over 22 second load time each time.
UPDATE: I have even tried APC - it improved a bit but still 6-8 sec/page
I uploaded my files to a linux server(shared hosting), on which it runs in around 300-500 ms. On the XAMPP installation I tried to run other (i.e. not Symfony2) applications as well(e.g. phpmyadmin), which too were slower than on the shared hosting, but not extremely slow, with 2-3 sec load time. Until I change to Linux as the main OS, how could I improve performance? I have a laptop with i7 CPU, 4 GB RAM, 5400RPM HDD, Win7 x64.
Thank you for your help!
UPDATE2: For some mysterious reason my Symfony routing didn't work with fcgid (it gave me a 404 error for everything) so I went back for using PHP as a module. Now, it has become the worst ever (worse than it used to be as a module): app mode 20-25 sec, and in dev mode, over 30s every time, so I get a timeout error, and it's the same with or without APC enabled.
Here you can see this error. This is reproduceable: each time it reaches a different point of execution within 30s:
Update:
Since PHP 5.5 has now integrated the PHP OPCache, this speeds up the execution time. In my setup a full request with database access takes 180ms now.
Steps:
Update to the latest php version
Enable OPCache
Disable xdebug
Set realpath_cache_size = 2M as DemonTPx mentioned
php.ini settings:
realpath_cache_size = 2M
[XDebug]
xdebug.profiler_enable = 0
xdebug.remote_enable = 0
[opcache]
zend_extension = "C:\xampp18\php\ext\php_opcache.dll"
opcache.enable = 1
opcache.enable_cli = 0
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 4000
Why is Windows slower than Unix?
As discussed here, PHP is very slow in file_exists, and filemtime() on Windows. since Symfony2 is using these functions in dev mode a lot. we won't get under 700ms (in <= 5.4) on Windows. PHP 5.5 allows now 180ms.
A solution could be WinCache which was developed by microsoft to solve this problem on IIS. But as it only works on several Windows versions and also only with IIS it's no solution for me.
Alternative
Also a nice solution I can recommend is to have a Linux Virtual Machine on Virtualbox. This is easy to setup and is also more like the production environment.
I have the exact same problem. Setting the following in php.ini increased the performance for me from ~800ms to ~300ms:
php.ini:
realpath_cache_size = 2M
Still not the ~100ms I get from a unix machine, but it makes a difference at least
I had a similar problem with symfony 1 for a time on XP and Server 2003. The solution was to install a PHP accelerator (eAccelerator for us, APC might be a better bet these days) plus FastCGI/fcgid.
Addendum: it's been ages since I've used Apache on Windows. I have generally been of the view that its performance has been getting steadily better, rather than worse; however as with most unusual set-ups, good results are not guaranteed. As per my earlier comment, I recommend asking your question at Apache Lounge, where I previously have received some great expert advice.
If memory serves correctly, they can offer you a free Apache binary compiled with better tools than the standard one offered on the Apache website.
Wow, After trying many different things, I've finally succeeded to move from a 15s execution time to a 3s exec time on windows7 with wamp.
How to install wincache extension :
http://us2.php.net/manual/en/wincache.installation.php
Where to download the wincache dll:
http://sourceforge.net/projects/wincache/
My php.ini config change:
[PHP]
realpath_cache_size = 2M
extension=php_wincache.dll
; XDEBUG Extension
;zend_extension = "C:/Net Generation/wamp/bin/php/php5.5.12/zend_ext/php_xdebug-2.2.5-5.5-vc11.dll"
;
[xdebug]
xdebug.remote_enable = off
xdebug.profiler_enable = Off
xdebug.profiler_enable_trigger = off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = "C:/Net Generation/wamp/tmp"
xdebug.show_local_vars=0
xdebug.max_nesting_level=200
[opcache]
zend_extension = "C:/Net Generation/wamp/bin/php/php5.5.12/ext/php_opcache.dll"
opcache.enable = 1
opcache.enable_cli = 0
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 4000
i think you have a problem with caching mechanism.
check app\cache directory.
there has to be a folder named dev.
if it does not exist or if it is empty check folder permissions.
when i delete dev and prod directories under app\cache directory it takes 18 seconds to load the page but after that it takes only 500 ms.
Some years ago i had the same problem. Which antivirus software do you run in the background?
Try to deactivate it for dev purposes or change it. It also could be some indexing services running in the background. Symfony 2 consists of >15000 files with vendors :)
Also try to do it the classic way by reinstalling Windows from the scratch.
My sites takes usually from 100-500ms and my laptop is slower than yours. (Intel C2D P8600)
Just a guess (and probably not the right one), but it could be MySQL related. Seeing how you mentioned PhpMyAdmin and Symfony 2 as PHP applications you tested, both rely on MySQL (assuming you have MySQL set up in Symfony 2). You did not mention this in your post, but in your VirtualBox setup, did you by any chance let the script running on Ubuntu connect to the MySQL server on your Windows host machine?
You could check out PHP Benchmark for some performance testing scripts, and see if these scripts perform better timewise.
Another thing you could try is use Xdebug and see if you find (a) certain (group of) function(s) that are taking up too much time.
I'm definately gonna keep this question as a favorite, because I am too curious to see what it was now :) good luck !
Check your computer random access memory, RAM using http://oca.microsoft.com/en/windiag.asp or run the memory test application shipped with your Ubuntu CD booting option.
In both cases choose what know as extra or deep test - I don't remember exactly- How ever, choose the test with more longtime these kind of tests has no end, you just wait till the test finish two phases and any problems with your RAM, commonly, shown.
Also, Check your hard drive with any mean of checking. after that try to perform disk defragmentation
I bit, your problem is hardware related problem.
My pages were taking 20 seconds to execute. I installed fast cgi, increased memory limits, everything, not working. Then started looking at timeline and noticed symfony firewall module was taking up most of it time. Turns out having "localhost" in my config for doctrine is what was causing issues. Changing it to 127.0.0.1 fixed the problem. Not sure why, but it's described here:
http://12wiki.blogspot.ca/2012/11/why-does-symfony-2-firewall-take-so.html
Page loading time is depends on the CSS + JS + Image loading time also. I had the same problem in CakePHP and solved the problem by using mod_expires in htaccess.
Have you tried "ExpiresByType" in your server htaccess file for CSS, JS and images? Check this page.

Categories