Showing posts with label Website Performance. Show all posts
Showing posts with label Website Performance. Show all posts

Monday, 22 February 2016

MySQL Query Optimization Tips and Techniques

MySQL Query Optimization Tips and Techniques

  1. Choosing Which Version of MySQL
  2. Don't join extra tables in MySQL Query.
  3. Only get N records which are going to used. Don't get extra records from table which you are not using.
  4. Don't fetch extra column from table which are not in use.
  5. Don't add spam records in tables
  6. Don't get it overload any table like 1GB Size, In this case shift data to another table.
  7. Get the understanding of normalization.
  8. Use Explain/DESCRIBE to know about table structure and Query. For Example:
  9. DESCRIBE SELECT * FROM `users` WHERE username='web-tech' 
  10. Partition your table (MySQL 5.1). Paritioning is a technique for splitting a large table into several smaller ones by a specific (aggregate) key.
  11. Partition can be achieve in three way 1. RANGE, HASH and List/Key.
  12. Build your indexes to match the queries running. For Example:
    ALTER TABLE `users` ADD INDEX `profile_id` (`profile_id`)
    Know about MySQL Indexing
  13. Use concatination indexing, if required (When searching like below).
    SELECT * FROM table_name  WHERE field_name1='text1' AND field_name2='text2';
  14. No indexing on column which not used in search.
  15. Sometime you need to use OPTIMIZE Table. For Example:
    OPTIMIZE TABLE `users`
    Used for defragment tables and update the InnoDB fulltext index
  16. Full Text Search can be used, if required.

Thursday, 16 April 2015

Why error 524 a timeout occurred

Why error 524 a timeout occurred

This error is CloudFlare error that denoting your web page is loading slow, due to any of below reason.
  • Website is Slow.
  • Temporary internet is slow.
  • Some function in website is talking long time to respond.
  • Any of mysql-query is talking more time to respond.

 In this case either you need to
increase the performance of website
increase the max_execution_time on website.

What is meaning of this Error.
A 524 error states that CloudFlare was able to make a TCP connection to the origin(your website server location), but the origin server did not reply with a HTTP response before the connection timed out.
It means that CloudFlare is able to make a network connection with origin server (your website), but the origin server(webiste) took too long time to respond to the request.

If you get this error first time, then you can refresh the page OR open the website in another browser.

As we know, Most of time website execution limit is 30 seconds but if website is takes more time (more than 30 seconds) to reply, then cloudFlare did not wait and through 524 error.
This error comes when server is on cloudFlare.

If this issue persistent in your website and comes very often then you have to work hard on your website..

If this issue is coming many times then it means your website is loading very slow.
you need to optimize.

How to increase the Performance of website?
1. Optimize the application Flow.

2. Optimize the MySQLI Query.

3 - Make Fewer HTTP Requests (means Less Ajax Call)

4 - Use a Content Delivery Network (CDN)

5 - Add an Expires Header

6 - Gzip Components

7 - Put Stylesheets at the Top (CSS Files in head tag)

8 - Put Scripts at the Bottom (Js files in footer)

9 - Avoid CSS Expressions (e.g 100/2)

See full articles

Thursday, 29 May 2014

Free Boost Web Application By 20% in Simple Steps

Simple Steps to Boost your appliction by 05 - 20%

  • echo is faster than print and use echo's for multiple parameters
  • Unset your large variables to free memory
  • use swtich case instead of if-else
  • Don't use @ because Error suppression with @ is very slow.
  • Turn on apache mod_deflate, mod_gzip which is available as an Apache module, compresses your data on the fly. It will boost your appliction and can reduce the data to transfer up to 80%
  • Incrementing/Decrementing a global variable is 2 times slower than a local variable
  • Incrementing/Decrementing an undefined local variable is 8 times slower than a initialized one.
  • use require instead of require_once
  • comment un-necessary code and remove the commented code
  • Avoid count(*) on entire tables, it can lock the entire table.
  • Use GROUP BY instead of DISTINCT when appropriate.
  • Use INSERT ON DUPLICATE KEY or INSERT IGNORE instead of UPDATE to avoid the SELECT prior to update.
  • Use Static Method, Speed improvement is by a factor of 4
  • Avoid necessary loops, because it may slow your application.

Friday, 14 March 2014

Improve Ajax Performance

Improve Ajax Performance

Following are few steps to Improve Ajax Performance
  1. First try to Reduce the Number of Ajax Call
  2. If same call send again, abort the previous call
  3. If ajax call is executing, and user go for another link, then cancel the previous one.
  4. Use GET Method, As its Fast but less secure
  5. Reduce the Amount of data transmitted
    a. Only Required parameter in Ajax Request
    b. Only Required Response in Ajax Request
  6. Optimize your Server  

Tuesday, 29 October 2013

Reduce the loading time of website

Following are IMP Rules to Reduce the loading time of website

1 - Make Fewer HTTP Requests (means Less Ajax Call)

2 - Use a Content Delivery Network (CDN)

3 - Add an Expires Header

4 - Gzip Components

5 - Put Stylesheets at the Top (CSS Files in head tag) 

6 - Put Scripts at the Bottom (Js files in footer)

7 - Avoid CSS Expressions (e.g 100/2)

8 - Make JavaScript and CSS External (Store the Css /Js in file and include them)

9 - Reduce DNS Lookups

10 - Minify JavaScript and css files (remove space, tab, indentation etc)

11 - Avoid Redirects (remove un-necessary redirect) 

12 - Remove Duplicate Scripts(Adding same javaScript / Css files two times)

13 - Configure ETags

14 - Make AJAX Cacheable

15 - Use Server side caching

16 - Use Client side caching

17 - Run time javaScript load must use cache
18- Add following code in .htaccess (Cache the JS/Image/Css & increase speed of website)

  ExpiresActive on
  ExpiresByType image/jpg "access 2 month"
  ExpiresByType image/gif "access 2 month"
  ExpiresByType image/jpeg "access 2 month"
  ExpiresByType image/png "access 2 month"
  ExpiresByType text/css "access 2 month"
  ExpiresByType application/x-javascript "access plus 2 month"
  ExpiresByType text/javascript "access plus 2 month"
  ExpiresByType application/javascript "access plus 2 month"
  ExpiresByType image/x-icon "access plus 12 month"
  ExpiresByType image/icon "access plus 12 month"
  ExpiresByType application/x-ico "access plus 12 month"
  ExpiresByType application/ico "access plus 12 month"

mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

You can check your website speed on