Website randomly loads slowly every once in a while - laravel

I have a laravel website which is running on apache2 and it's running on multiple servers for multiple clients. There is only one web server where the website loads slowly. Now it's not loading slowly on every page load, it randomly loads slowly. Also after loading a page, that has loaded quickly, if you leave the site for say 5 minutes and begin to navigate to another page, the page loads slowly yet again.
Not sure if in fact it's apache that causes the slowness of the site, or if it's a third party plugin because as the page is loading it mentions m.stripe.com is loading and then on another page load, it could be another plugin loading.
Are there any tools that I can use to decipher this issue.

It is very difficult to answer why a Laravel website is slower. There are many reasons behind a slower Laravel application. You have to debug and take decisions where you need to improve in your application. Here a list I focus on when I develop an application.
Database
How may database query load on each page? you have to ensure any recursive query not exist. Make efficient data cache. Check queries takes a little time to execute.
Network Connection
If you are using different network connections with your Redis, database, queue then make sure those connections are well optimized and taking a little time to connect and serve data.
Cache Files
Make Cache you blade HTML files, routers, config files, and optimize those cache. Also, reduct autoloads services as much as possible.
Optimize your Images
Optimize your images. I recommend not to use local files. try to use a cloud service.
Minify CSS and JS file
You should minify your CSS and js files. and try to use libraries from CDN.
Use Queue
Use queue where possible like email send, PDF Generate...

Found that there where 2 A name records with different IP adresses for the same domain. I would have thought some error would have been raised by apache because of this, but it randomly selected the ip to serve the site and of course long load times for the ip that does not exist.

Minify your HTML, CSS, and Javascript. it's a great way to increase page spread. Depending on the IDE you use, you could install a minifier extension, use webpack to bundle your code, or use an online minifier like https://fixcode.org/minify
Use a CDN to load static files like scripts, images, and style sheet. you could also load all of your site via a CDN
you could also consider lazy loading parts of your script. especially in cases where you compile scripts with webpack

Related

Server response time - Drupal on Bluehost

In the past, when I checked the site speed in google page speed or many similar tools, the site got very high scores (good css & js optimize). I installed the Advanced CSS/JS Aggregation module and boost module to get high score.
Then, suddenly, I started to get message on the google page speed (and other tools), saying my server response time is slow - around 3 seconds.
My site built with Drupal 7 and hosted on Bluehost Shared hosting.
Bluehost technical support says that the problem is not in their side
What do you think causing the server to be slow?
How can I fix it?
Or at least, what should I check (images, caching, something else)?
The first thing to figure out is what's a desirable response time. For example, if you have lots of modules and pretty heavy site/homepage then maybe 3 seconds is ok unless something is done to change the processing time(caching, using less modules etc).
Back to your case of where should i check:
Check, your homepage and what views and other things are loading for your homepage to be rendered. Then make a list and go one by one to ask:
Is it optimal/can it be improved? maybe something is throwing the caching out(dynamic parameters be injected by each request for the item etc).
If you're using views, enable the sql view to see what sql statements its using and you can use tools to analyze/improve it(this could be a question by itself)
Look at the modules that load/being used to make sure you need them.
Check on the drupal caching(/admin/config/development/performance) and make sure the correct checkboxes are checked.
This could as well be blue host's problem because if they're hosting so many sites on the server, the server will start kicking some sites out of memory and load them back as they're requested by the visitors hence the slow load(server requests the site, drupal loads it from database etc).
You can ask specific questions after you check those.

product list page of magento incredibily slow

I am new with Magento and have developed a website using CE 1.7.0.2. Now its ready to go live but I have issues with slow page load.
My website product home, list and detail page initially takes time to 10-13 sec to page load but after that first load it only takes 1-2 second to page load.
Also I have installed APC, Memcache and CDN on server and full page cache extension for website but yet it is slow. I am so frustrated why this happening with my website?
If anybody knows how can we resolve speed up issues that will be helpful for me.
Thanks!
You can go through the below steps for Magento Optimization:
High Performance Dedicated Server. Ex: Amazon EC2 cloud
Swap Apache for NGINX
Minimize Javascript use
Minify and Compressed CSS files
‘Combine CSS’ seeks to reduce the number of HTTP requests made by a
browser
Optimize images
Use lazyload for images
Specify Image dimensions
Combine images into CSS sprites
Use a Content Delivery Network (CDN) for delivering static files
like JS, CSS and Images to offload your server
Disable modules/extension which are not required
Enable all Magento Caches
Use a Full Page Cache / Varnish Cache / Memcache / RedisCache
Don’t use layered navigation if you don’t really need it, it needs
a lot of resources
Enable Compilation
Limit the number of products on a product overview page.
Set only those attribute frontend properties to ‘Yes’ that you’re
actually going to use. Set all other to ‘No’.
Don’t use in quick search, advanced search compare, etc. : Catalog
-> Attributes -> Manage Atributes -> Frontend Properties.
Install Google Page Speed Module
Minimize redirects – Minimizing HTTP redirects from one URL to
another cuts out wait time for users.
Prefer asynchronous resources – Fetching resources asynchronously
prevents those resources from blocking the page load.
This list may help you for Magento performance improvement:
Enable Magento caching
This is ofcourse the first step in optimization: Enable all the available caches in the Magento Admin Panel.
Compress images
Many people forget that images (PNG, JPG) can be compressed, which lowers the bandwidth between the browser and the webserver. Not only the images used by the Magento skin need optimizing, but catalog images as well. Various tools allow you to compress batches of images, for instance the online tool Smush.It.
Disable unneeded Magento modules
By disabling Magento modules that you do not need, less resources are needed – as simple as that. Modules could be disabled through the configuration in the Magento Admin Panel, or by editing XML-files in app/etc/modules. For instance, disable Mage_Log which performs queries on every request, but is not needed if you gather site statistics using external programs.
Enable flat catalogs for smaller webshops
For smaller webshops switching from the complex EAV-structure to a flat catalog could save time. This optimization is dubious and depends on many parameters, so do not take this step lightly.
W3C compliance
While it could be argued that this is less important with the coming of HTML5, it is still a fact that if your webpages are filled with ugly errors, the browser will have a harder time interpreting it. If you stick to W3C compliance, it is made sure the browser engine has an easy job parsing your HTML-code.
Compress output in general
By enabling the PHP-setting zlib.output_compression the output generated by PHP is compressed when sent to the browser. This saves bandwidth. Instead of using this, you could use the Apache mod_deflate module as well, which allows also for compression of non-PHP output (CSS, JavaScript, other plain text-files).
Configure PHP options
Most PHP settings actually do not influence the performance of Magento, but just set certain limits. For instance, settings like memory_limit and max_execution_time do not increase the page load but just make sure that certain actions do not timeout or run into memory problems.
Session storage
With Magento, sessions could be stored in files or in the database (by configuring app/etc/local.xml). Which option performs best, really depends on how the hosting environment is setup. If MySQL databases perform well, session storage in the database could benefit your site. But if MySQL is not setup correctly, the best choice might be files.
Use a PHP accelerator
By opcode caching, PHP-execution could be fastened. There are various PHP accelerators doing this job (APC, ZendOptimizer+, eAccelerator, XCache). Both APC and ZendOptimizer+ are working flawless with Magento.
Tune PHP realpath_cache
By tuning the PHP realpath_cache_size to for instance 128K (default is 16K) and the realpath_cache_ttl to 86400, things might be speeding up. Make sure you don’t run out of memory, because every Apache child will consume the configured caching size.
Use Apache mod_expires
By telling the browser which files to keep in cache for how long, you can optimize the browser cache. For instance, JavaScript files tend to change much less then CSS files (at least in the first stages of the site), but perhaps after the site is running smooth for some months you can maximize the expiration date.
Beware 404 errors
Every time a file (like a stylesheet or image) is not found, this generates a 404 error. Because the default 404 of Magento is caught by the application of Magento itself, this causes the Magento application to start for every 404 encountered. Check your Apache logs to make sure all 404 errors are solved.
Disable Magento logging
Within the Magento configuration, you can enable logging under the Developers-tab. Depending on the Magento modules this could lead to more logs needed to be written to the filesystem, slowing down your shop. Because the logging-abilities are only needed to debug something, in daily usage, it’s best to disable logging altogether.
MySQL table optimization
Through phpMyAdmin, you can perform the command OPTIMIZE TABLE on specific Magento database-tables. When a table is cluttered, this could lead to improved performance. This does not only count for the complex EAV-tables, but also for regular MySQL tables that are used frequently (for instance, core_config_data).
Merge CSS and JavaScript
By merging all CSS and JavaScript files together as one big file, only one single HTTP-request is needed by the browser to fetch this content. This saves bandwidth. For this merging, the FooMan Speedster module could be used. Magento 1.4 contains an option to merge CSS, while JavaScript-files are merged by default.
Besides merging, crunching is also an option offered by FooMan Speedster: It removes whitespaces from the output, but when compression is already applied to CSS, this option is less needed.
Use Magento Compiler module
The Magento Compiler module limits the number of directories that PHP has to search through when looking for PHP-files. This decreases the PHP execution-time, which speeds up the Magento application in general.
Be warned that you need to be careful when making changes to your Magento system, while the Magento Compiler is enabled. Upgrades should only be undertaken when the compiler is (temporarily) disabled.
One very neat trick that speeds up things tremenduously is to create a tmpfs-mount specifically for the includes/src folder. Note that this tmpfs-mount needs to be at least 100Mb – preferably 200Mb.
MySQL server tuning
The default MySQL setup is a lot of times sufficient to run a general hosting environment, but not all optimized for Magento. Tuning settings like query_cache_size could dramatically increase performance, but is also dangerous because it hugely depends on other variables (number of databases, number of tables per database, number of queries, peak usage).
Serve static content through a CDN
Static content like images, CSS-stylesheets or JavaScript-files, could be served through other servers that are more optimized for static content. For instance, a CDN could be used so that the static content is always served from a location that is closest to the visitor. This is vital for webshops serving customers worldwide.
Disable local Magento modules
If your site does not need local Magento modules, you could choose to skip the search for local modules alltogether. Within the app/etc/local.xml file, you will find an XML-tag allowing you to do so.
Be carefull with HTTPS
Every time you use SSL between webserver and browser, the process of encrypting and decrypting is added on both sides. Also there is a slight overhead in bandwidth. The Magento site runs slightly faster if you disable SSL for all or just a few pages. However, this “win” is so small compared to the other wins on this page, that it should only be handled with caution. The gained bandwidth is non-vital, while almost all computers nowadays have CPU-power with which the encryption/decryption process takes place in microseconds.
Magento in the cloud
While CDNs could be used to optimize the bandwidth for static content, the Magento application could also be optimized in the same way by using cloud computing.
Memory-based filesystem for dynamic data
By storing dynamic data (var/cache, var/session) on a memory-based filesystem like RAMdisk or tmpfs, the disk I/O is decreased.
Disable Apache htaccess-files
When allowing the usage of htaccess-files, Apache needs to inspect every directory in its path to see if an htaccess-file is present. By moving the Apache configuration-directives from the htaccess-file to the VirtualHost configuration-file, and disabling htaccess-files all together, the Apache execution-time is decreased. This tip probably applies in most cases only to dedicated servers.
Use Nginx or Litespeed
While the Apache webserver is very flexible in its configurations, there are other webservers that are better optimized regarding memory usage: By replacing Apache with either Nginx or Litespeed, you could speed up the Magento scripts even more. Both webservers require manual configuration to allow for SEF URLs.
Use lazyload for images
When a page is loading, a visitor is often waiting for images on that page to load. Depending on the number and size of these images, this can take some time. Instead of loading images at once when the page is loaded, you can also add the LazyLoad JavaScript effect that makes sure only visible images (within the browser screen) are loaded, while remaining images are only loaded once the visitor scrolls down.
Minimize Apache logging
If Apache logging is minimized, less file operations are needed for every incoming request. Ofcourse less logging also means less insight when something goes wrong. An alternative is to optimize the filesystem on which Apache logs are stored. By default, Apache logs to the /var filesystem – but there’s no need to enable things like journalling for that filesystem.
ref: http://magentotutorialbeginners.blogspot.in/2014/05/magento-performance-improvement.html
If you have done all kind of server and caching optimization.Go to code level.
1) See are you loading a collection with in a foreach loop.
2) Try to optimize the code.
3) If you are loading a collection, filter the collection for the required attributes only.
4) Check for your product images.Use png images and try to keep images size under 500 KB.
5) Try commenting the custom functionality that you are providing on that page.And check with some tool like GTMetrix. How much time you achieve to load the page.Try to find out the code which is taking long time to load.
6) Keep only necessary attributes used for filter purpose in Layered navigation.
7) Try disabling unnecessary modules.
8) Try after enabling the compilation.
Hope these suggestions will work for you.

Local testing - intentionally slowing down loading to test page behaviour

I am developing my websites locally with MAMP. But I would like to know how they will act in the 'real world'.
Is there a way how I can intentionally slow down page load to a more common internet connection speed? I am mostly concerned on how well my websites perform looking at HTML requests (scripts, images, sprites, etc.) and lacy loading.
The only thing I found by googling was this: Intentionally Slow Down HTML/PHP Page Load to Test.
I don't want to stop page load though, I just want to make it slower.
Thanks!
EDIT
For googlers - one of the answers at linked question recommended Deeelay.me service, which is exactly what I was looking for at the time.
set up local proxy and set transfer rate as desired. it may be apache but for sure you can find something simpler with google

Site is very slow only the first request

When browsing "http://dev.bindsolution.com/" the site takes too long to begin processing. Why this?
Are using "CSS Sprites", "css" and "JavaScript" minify although I do not think the problem is this.
Why the first request the site is extremely slow?
PS: I'm visiting from Brazil
When you first request the site after publishing, ASP.Net needs to compile and load the application.
It depends on what do you mean by first request.. Is it first request after an application (or app pool) has been redeployed/restarted, the very first request to your application is slow could be that IIS has to start the asp.net worker process.
also this link should provide you with more details: http://msdn.microsoft.com/en-us/library/ms366723.aspx
if you mean first request by any user well then there is an overhead on the files that needs to be downloaded by the user, also the site might be doing some process intensive stuff in Session_start, I would check all these..
Also if you have access to the code you could probably run some performance analysis on the same. I would highly recommend dotTrace by JetBrains.
FYI, I am no way associated with JetBrains. Just love their sw/tools
It could be that the first load is slow and subsequent loads are quicker because assets (js, css, images ) are cached for subsequent views and don't need to be loaded.
The firefox plugin yslow will give you a detailed breakdown on the sizes and loading speeds.
Also run smush.it ( part of yslow ) to shrink your image sizes. It will make the images smaller but there will be no noticeable difference.
IIS may have shut down some worker threads which need to be started, your appDomain will be starting and loading all classes from your dlls and JITing these to machine code, ASP.Net will also be doing it's own warmup (initialising all things required in the pipeline, possibly pre-compiling some views etc).
Update
The first request is slow because of the number of resources that the page has to load, once loaded, the browser will cache them do they will not need to be requested again (which is why there's the speed improvement).
Consider aggregating (and possibly compressing) all required resources on your own site, and referencing those in your pages.

How to Increase page loading speed in Zend Framework Application

I have developed application using ZF.The app is little big with a lots of features.
I use Zend_Application(already using autoloader in constructor),Zend_Layout,Zend_view,Zend_form,etc. My current issue is, the page loading is very slow and that too in localhost with XAMP.
I have enabled xdebug, to investigate the issue, got a cachegrind file in "tmp" folder and tried to view it with WinCachegrind software. There i can a see a lot of processes and functions being run for each and every request or page load.
Also, i have installed YSlow add-on for firefox and observed the speed of page loads in seconds...I have compare the speed with ZF and non ZF applications. And from the comparison, the pages for non zf app takes less than 1 sec to load and for the ZF app, it takes atleast 6-7 seconds. What a huge difference.
Main Things happen in the app are :
1) Database connection happens for each request.
2) Im not adding the view to layout explicitly,ZF just appends it automatically, to layout.phtml, based on the action name.
3) Some windows have forms with few drop down boxes which fetches data from the database.
4) Have menus with ACL implimented, before it was loading the privilges from DB for each and every request, but now i have optimized it, so that it will work only duiring the login and rest of the time it will take from the Zend_Registry.
I would like to attach the cachegrind file so that some one can see whats happening in the background, but i cant see an option here for attaching.
Someone please help me to find a solution for this. Any kind of help is really appreciated. Thanks a lot
Let's try to give some hints.
First database connection should happen only once (except if you use several privileges access on the database or several databases). So check that you use Singleton patterns with you Zend_Db_Tables object
Then you do not use Zend_Cache. You should really start to use Zend_Cache and build several cache objects. Let's say for example a File cach, with long term storage, and a memcache or Apc Cache, storing objects. Then use these cache in several layers:
gives the FileCache to Zend_Db_Table (defaultMetaDataCache), this way you will avoid a loot of metadata queries, queries that ask for description of each columns of the tables you use.
Store one or more Acl object (depends on how you use Acl, if you have one big Acl with all rules or several with subsets). And store them in mid-duration caches when they are built.
Think of other usages, detect heavy loops, semi-static contents (like you select lists, how many time should they be considered static?)
Finally, get a whole mental image of how your application engine works, and how your data will grow and be used.You will need that step to use application levels caches in the very best way (for example should some elements be cached for groups of users?, should Acl objects be build for groups, for each user, for everybody, is ther some blocks in the layout that should be rendered the same for everybody?).

Resources