SlideShare a Scribd company logo
System Performance Tuning
What is Performance Tuning
• Performance tuning can involve configuration
changes to software components.
• Performance tuning can also include tuning SQL
queries and tuning an applications underlying code
to cater for concurrency and to improve efficiency.
Common Problems in SQL Queries
Pagination
• Fetching lots of records can cause slow down
the speed of system but its necessary because
database is systematically organized or
structure repository of indexed information.
Pagination
Example:
Without pagination fetching all data
SELECT * FROM cats
Pagination
Two things you must do:
• Decide on the maximum number of database
rows that can be included in each page. You
may hard code this value, or (my preferred
method) you can define it in a variable so that
the value may be changed at runtime.
Pagination
• You then need to inform the user that other
'pages' are available and provide a mechanism
whereby the user is able to select a different
'page' of details. I currently use a set of
hyperlinks in a separate pagination area which
looks like this:
Pagination
How to do it :
1. Obtain the required page number.
- if(isset($_GET[‘pageno’])) {
$pageno = $_GET[‘pageno’];
} else {
$pageno = 1;
}
Pagination
2. Identify how many database rows are
available:
-$query = “SELECT count(1) FROM table
WHERE…”;
$result = mysql_query($query, $db);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
Pagination
3. Calculate number of $lastpage:
- $rows_per_page = 15;
$lastpage = ceil($numrows/$rows_per_page);
4.Ensure that $pageno is within range:
-$pageno = (int)$pageno;
If ($pageno > $lastpage) {
$pageno = $lastpage;
}
If ($pageno < 1 ){
$pageno = 1;
}
Pagination
5. Construct LIMIT clause:
- $limit = ‘LIMIT’ .($pageno - 1) *
$rows_per_page.’,’.$rows_per_page;
6. Issue the database query:
- $query = “SELECT * FROM table $limit”
$result = mysql_query($query,$db);
Pagination
7. Construct pagination hyperlinks:
- If ($pageno == 1) {
echo “PREV”;
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
}
Pagination
if ($pageno == $lastpage) {
echo " NEXT";
} else {
$nextpage = $pageno+1;
echo " <a
href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT
</a> ";
echo " <a
href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST<
/a> ";
}
Performance: N+1 Query Problem
• Select N+1 is a data access anti-pattern
where the database is accessed in a
suboptimal way.
• Detecting Select N+1 problem usually means
that the data fetch strategy of the application
can be optimized.
Performance: N+1 Query Problem
Example:
$test = new test();
$hats = $test->getHats();
$cats = [];
foreach ($hats as $value) {
$cats[] = $test->getCats($value['id']);
}
Performance: N+1 Query Problem
Assuming $hats() has an implementation that boils
to:
SELECT * FROM hats WHERE …
.. And $cats($hats_id) has an implementation like
this:
SELECT * FROM cats WHERE hats_id = ..
Performance: N+1 Query Problem
.. You will issue “N+1” queries when the code executes, Where
N is the number of cats:
SELECT * FROM cats WHERE ..
SELECT * FROM cats WHERE hats_id = 1
SELECT * FROM cats WHERE hats_id = 2
SELECT * FROM cats WHERE hats_id = 3
SELECT * FROM cats WHERE hats_id = 4
….
Performance: N+1 Query Problem
Solution :
Batching Queries
$cats=getCats();
Performance: N+1 Query Problem
That is issue these queries:
SELECT * FROM cats WHERE …
SELECT cats.id, cats.name, cats.created
FROM cats INNER JOIN hats
ON hats.id = cats.hats_id
Performance: N+1 Query Problem
• It is much faster to issue 1 query which
returns thousands results than to issue t
queries which each thousands return 1
result.
Thank You

More Related Content

PPTX
Cake PHP 3 Presentaion
ODP
My sql
ODP
Database Connection With Mysql
PPT
MYSQL - PHP Database Connectivity
PDF
CakePHP 3
PDF
PHP and Mysql
PPT
PHP - Getting good with MySQL part II
Cake PHP 3 Presentaion
My sql
Database Connection With Mysql
MYSQL - PHP Database Connectivity
CakePHP 3
PHP and Mysql
PHP - Getting good with MySQL part II

What's hot (20)

PDF
Introduction to php database connectivity
PPT
Database presentation
PPTX
Php basics
PDF
REST API with CakePHP
PPTX
Message enricher in mule
PPT
Php with MYSQL Database
PPTX
Working with WP_Query in WordPress
PDF
4.3 MySQL + PHP
PPTX
Database Connectivity in PHP
PDF
lab56_db
PPT
Php MySql For Beginners
PPT
PHP - PDO Objects
PDF
PDO Basics - PHPMelb 2014
PPT
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PDF
Extending the WordPress REST API - Josh Pollock
PPTX
Php Training Workshop by Vtips
PPTX
Mysql
KEY
Cakephp2study tips集
PPT
Php classes in mumbai
PPT
PHP and MySQL
Introduction to php database connectivity
Database presentation
Php basics
REST API with CakePHP
Message enricher in mule
Php with MYSQL Database
Working with WP_Query in WordPress
4.3 MySQL + PHP
Database Connectivity in PHP
lab56_db
Php MySql For Beginners
PHP - PDO Objects
PDO Basics - PHPMelb 2014
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
Extending the WordPress REST API - Josh Pollock
Php Training Workshop by Vtips
Mysql
Cakephp2study tips集
Php classes in mumbai
PHP and MySQL
Ad

Viewers also liked (7)

PPTX
Software Testing
PPTX
Node js - Yns
PDF
Learning CakePHP2 from source code vol2
PPTX
Php 7 - YNS
PDF
How to create test data
PDF
Functional programming
PDF
WordPress APIで作るモバイルアプリ
Software Testing
Node js - Yns
Learning CakePHP2 from source code vol2
Php 7 - YNS
How to create test data
Functional programming
WordPress APIで作るモバイルアプリ
Ad

Similar to System performance tuning (20)

PDF
Php summary
PDF
Supercharging WordPress Development - Wordcamp Brighton 2019
PDF
ASP.NET Overview - Alvin Lau
PDF
Using php with my sql
PPTX
This slide show will brief about database handling
PPT
Php frameworks
PPTX
Advance Sql Server Store procedure Presentation
PPTX
Drupal II: The SQL
KEY
Unit testing zend framework apps
PPTX
Web Application Development using PHP Chapter 8
PDF
Workshop quality assurance for php projects - phpbelfast
PDF
Workshop quality assurance for php projects - ZendCon 2013
PPTX
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
PDF
PHP with MySQL
PPTX
CHAPTER six DataBase Driven Websites.pptx
PPTX
PowerShell: Through the SharePoint Looking Glass
KEY
Drupal as a web framework
KEY
Unit testing with zend framework PHPBenelux
PDF
Unit testing with zend framework tek11
ZIP
What's new in the Drupal 7 API?
Php summary
Supercharging WordPress Development - Wordcamp Brighton 2019
ASP.NET Overview - Alvin Lau
Using php with my sql
This slide show will brief about database handling
Php frameworks
Advance Sql Server Store procedure Presentation
Drupal II: The SQL
Unit testing zend framework apps
Web Application Development using PHP Chapter 8
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - ZendCon 2013
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
PHP with MySQL
CHAPTER six DataBase Driven Websites.pptx
PowerShell: Through the SharePoint Looking Glass
Drupal as a web framework
Unit testing with zend framework PHPBenelux
Unit testing with zend framework tek11
What's new in the Drupal 7 API?

Recently uploaded (20)

PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Online Work Permit System for Fast Permit Processing
PPT
Introduction Database Management System for Course Database
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
top salesforce developer skills in 2025.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
medical staffing services at VALiNTRY
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
System and Network Administraation Chapter 3
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
How Creative Agencies Leverage Project Management Software.pdf
Online Work Permit System for Fast Permit Processing
Introduction Database Management System for Course Database
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Odoo Companies in India – Driving Business Transformation.pdf
top salesforce developer skills in 2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
medical staffing services at VALiNTRY
Upgrade and Innovation Strategies for SAP ERP Customers
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Navsoft: AI-Powered Business Solutions & Custom Software Development
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Odoo POS Development Services by CandidRoot Solutions
How to Choose the Right IT Partner for Your Business in Malaysia
System and Network Administraation Chapter 3
ManageIQ - Sprint 268 Review - Slide Deck
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...

System performance tuning

  • 2. What is Performance Tuning • Performance tuning can involve configuration changes to software components. • Performance tuning can also include tuning SQL queries and tuning an applications underlying code to cater for concurrency and to improve efficiency.
  • 3. Common Problems in SQL Queries
  • 4. Pagination • Fetching lots of records can cause slow down the speed of system but its necessary because database is systematically organized or structure repository of indexed information.
  • 6. Pagination Two things you must do: • Decide on the maximum number of database rows that can be included in each page. You may hard code this value, or (my preferred method) you can define it in a variable so that the value may be changed at runtime.
  • 7. Pagination • You then need to inform the user that other 'pages' are available and provide a mechanism whereby the user is able to select a different 'page' of details. I currently use a set of hyperlinks in a separate pagination area which looks like this:
  • 8. Pagination How to do it : 1. Obtain the required page number. - if(isset($_GET[‘pageno’])) { $pageno = $_GET[‘pageno’]; } else { $pageno = 1; }
  • 9. Pagination 2. Identify how many database rows are available: -$query = “SELECT count(1) FROM table WHERE…”; $result = mysql_query($query, $db); $query_data = mysql_fetch_row($result); $numrows = $query_data[0];
  • 10. Pagination 3. Calculate number of $lastpage: - $rows_per_page = 15; $lastpage = ceil($numrows/$rows_per_page); 4.Ensure that $pageno is within range: -$pageno = (int)$pageno; If ($pageno > $lastpage) { $pageno = $lastpage; } If ($pageno < 1 ){ $pageno = 1; }
  • 11. Pagination 5. Construct LIMIT clause: - $limit = ‘LIMIT’ .($pageno - 1) * $rows_per_page.’,’.$rows_per_page; 6. Issue the database query: - $query = “SELECT * FROM table $limit” $result = mysql_query($query,$db);
  • 12. Pagination 7. Construct pagination hyperlinks: - If ($pageno == 1) { echo “PREV”; } else { echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> "; $prevpage = $pageno-1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> "; }
  • 13. Pagination if ($pageno == $lastpage) { echo " NEXT"; } else { $nextpage = $pageno+1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT </a> "; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST< /a> "; }
  • 14. Performance: N+1 Query Problem • Select N+1 is a data access anti-pattern where the database is accessed in a suboptimal way. • Detecting Select N+1 problem usually means that the data fetch strategy of the application can be optimized.
  • 15. Performance: N+1 Query Problem Example: $test = new test(); $hats = $test->getHats(); $cats = []; foreach ($hats as $value) { $cats[] = $test->getCats($value['id']); }
  • 16. Performance: N+1 Query Problem Assuming $hats() has an implementation that boils to: SELECT * FROM hats WHERE … .. And $cats($hats_id) has an implementation like this: SELECT * FROM cats WHERE hats_id = ..
  • 17. Performance: N+1 Query Problem .. You will issue “N+1” queries when the code executes, Where N is the number of cats: SELECT * FROM cats WHERE .. SELECT * FROM cats WHERE hats_id = 1 SELECT * FROM cats WHERE hats_id = 2 SELECT * FROM cats WHERE hats_id = 3 SELECT * FROM cats WHERE hats_id = 4 ….
  • 18. Performance: N+1 Query Problem Solution : Batching Queries $cats=getCats();
  • 19. Performance: N+1 Query Problem That is issue these queries: SELECT * FROM cats WHERE … SELECT cats.id, cats.name, cats.created FROM cats INNER JOIN hats ON hats.id = cats.hats_id
  • 20. Performance: N+1 Query Problem • It is much faster to issue 1 query which returns thousands results than to issue t queries which each thousands return 1 result.