Performance differences between DEV and Production environment MYSQL server
up vote
0
down vote
favorite
I'm building an app with Laravel 5.6 and VueJS requesting data from an API on the Laravel backend. In my DEV environment the queries take no time at all, but in the Production environment the response on the API takes 85.7 seconds opposed to 0.1 seconds in the DEV environment. Data is in both environments the same.
Using the follwoing commands in my Controller I was able to get the exact queries that run and I can test them one by one:
DB::enableQueryLog();
// then my eloquent stuff
$query = Sportevent::whereHas('photos')->with('photos');
if($request->input('year')){
$year = $request->input('year');
$query = $query->where('date','like', $year.'%');
}
if($request->input('country')){
$country = $request->input('country');
$query = $query->where('country',$country);
}
$sportevents = $query->orderBy('date',"DESC")->paginate(10);
// then I display the queries:
dd(DB::getQueryLog());
Here are the queries that are produced, not having selected a year or a country, incl performance in both environments with time:
// --------------------------------------------------------------
// DEV: 0.0208 seconds | PROD: 73 seconds (had to use stopwatch)
// --------------------------------------------------------------
select count(*) as aggregate from `events` where exists
(select * from `photos` where `events`.`id` = `photos`.`eventID`
and `active` = 1)
// ------------------------------------------
// DEV: 0.025 seconds | PROD: 38.9721 seconds
// ------------------------------------------
select * from `events` where exists (select * from `photos` where
`events`.`id` = `photos`.`eventID` and `active` = 1)
order by `date` desc limit 10 offset 0
// ------------------------------------------
// DEV: 0.0112 seconds | PROD: 0.0141 seconds
// ------------------------------------------
select * from `photos` where `active` = 1 and `photos`.`eventID` in
(11194, 11087, 10506, 10797, 9910, 10118, 10212, 9655, 10047, 10049)
The table events contains about 6000 entries and photos less than 50000 entries. If you need further details when it comes to table structure, let me know before down voting in the comments section :-)
On the production server are many other applications running with Laravel or Wordpress using databases on the same MySQL installation and none of them have similar issues.
mysql laravel-5 phpmyadmin eloquent
|
show 2 more comments
up vote
0
down vote
favorite
I'm building an app with Laravel 5.6 and VueJS requesting data from an API on the Laravel backend. In my DEV environment the queries take no time at all, but in the Production environment the response on the API takes 85.7 seconds opposed to 0.1 seconds in the DEV environment. Data is in both environments the same.
Using the follwoing commands in my Controller I was able to get the exact queries that run and I can test them one by one:
DB::enableQueryLog();
// then my eloquent stuff
$query = Sportevent::whereHas('photos')->with('photos');
if($request->input('year')){
$year = $request->input('year');
$query = $query->where('date','like', $year.'%');
}
if($request->input('country')){
$country = $request->input('country');
$query = $query->where('country',$country);
}
$sportevents = $query->orderBy('date',"DESC")->paginate(10);
// then I display the queries:
dd(DB::getQueryLog());
Here are the queries that are produced, not having selected a year or a country, incl performance in both environments with time:
// --------------------------------------------------------------
// DEV: 0.0208 seconds | PROD: 73 seconds (had to use stopwatch)
// --------------------------------------------------------------
select count(*) as aggregate from `events` where exists
(select * from `photos` where `events`.`id` = `photos`.`eventID`
and `active` = 1)
// ------------------------------------------
// DEV: 0.025 seconds | PROD: 38.9721 seconds
// ------------------------------------------
select * from `events` where exists (select * from `photos` where
`events`.`id` = `photos`.`eventID` and `active` = 1)
order by `date` desc limit 10 offset 0
// ------------------------------------------
// DEV: 0.0112 seconds | PROD: 0.0141 seconds
// ------------------------------------------
select * from `photos` where `active` = 1 and `photos`.`eventID` in
(11194, 11087, 10506, 10797, 9910, 10118, 10212, 9655, 10047, 10049)
The table events contains about 6000 entries and photos less than 50000 entries. If you need further details when it comes to table structure, let me know before down voting in the comments section :-)
On the production server are many other applications running with Laravel or Wordpress using databases on the same MySQL installation and none of them have similar issues.
mysql laravel-5 phpmyadmin eloquent
dev and production db are different? If yes make sure indexes are present on production also.
– Web Artisan
Nov 20 at 7:21
It's all identical, there are no indexes apart from id as primary key defined on both tables.
– Edwin Krause
Nov 20 at 7:29
May be your production server db engine configuration is much lower than your dev environment. Try to contact your hosting provider.
– Web Artisan
Nov 20 at 7:34
It's on a VPS... So I should be the master of my MySQL server
– Edwin Krause
Nov 20 at 7:41
2
I just added an index on columnphotos.eventID
that seems to do the trick. Fast as a rocket now... : 0.4 seconds for the API to respond
– Edwin Krause
Nov 20 at 7:45
|
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm building an app with Laravel 5.6 and VueJS requesting data from an API on the Laravel backend. In my DEV environment the queries take no time at all, but in the Production environment the response on the API takes 85.7 seconds opposed to 0.1 seconds in the DEV environment. Data is in both environments the same.
Using the follwoing commands in my Controller I was able to get the exact queries that run and I can test them one by one:
DB::enableQueryLog();
// then my eloquent stuff
$query = Sportevent::whereHas('photos')->with('photos');
if($request->input('year')){
$year = $request->input('year');
$query = $query->where('date','like', $year.'%');
}
if($request->input('country')){
$country = $request->input('country');
$query = $query->where('country',$country);
}
$sportevents = $query->orderBy('date',"DESC")->paginate(10);
// then I display the queries:
dd(DB::getQueryLog());
Here are the queries that are produced, not having selected a year or a country, incl performance in both environments with time:
// --------------------------------------------------------------
// DEV: 0.0208 seconds | PROD: 73 seconds (had to use stopwatch)
// --------------------------------------------------------------
select count(*) as aggregate from `events` where exists
(select * from `photos` where `events`.`id` = `photos`.`eventID`
and `active` = 1)
// ------------------------------------------
// DEV: 0.025 seconds | PROD: 38.9721 seconds
// ------------------------------------------
select * from `events` where exists (select * from `photos` where
`events`.`id` = `photos`.`eventID` and `active` = 1)
order by `date` desc limit 10 offset 0
// ------------------------------------------
// DEV: 0.0112 seconds | PROD: 0.0141 seconds
// ------------------------------------------
select * from `photos` where `active` = 1 and `photos`.`eventID` in
(11194, 11087, 10506, 10797, 9910, 10118, 10212, 9655, 10047, 10049)
The table events contains about 6000 entries and photos less than 50000 entries. If you need further details when it comes to table structure, let me know before down voting in the comments section :-)
On the production server are many other applications running with Laravel or Wordpress using databases on the same MySQL installation and none of them have similar issues.
mysql laravel-5 phpmyadmin eloquent
I'm building an app with Laravel 5.6 and VueJS requesting data from an API on the Laravel backend. In my DEV environment the queries take no time at all, but in the Production environment the response on the API takes 85.7 seconds opposed to 0.1 seconds in the DEV environment. Data is in both environments the same.
Using the follwoing commands in my Controller I was able to get the exact queries that run and I can test them one by one:
DB::enableQueryLog();
// then my eloquent stuff
$query = Sportevent::whereHas('photos')->with('photos');
if($request->input('year')){
$year = $request->input('year');
$query = $query->where('date','like', $year.'%');
}
if($request->input('country')){
$country = $request->input('country');
$query = $query->where('country',$country);
}
$sportevents = $query->orderBy('date',"DESC")->paginate(10);
// then I display the queries:
dd(DB::getQueryLog());
Here are the queries that are produced, not having selected a year or a country, incl performance in both environments with time:
// --------------------------------------------------------------
// DEV: 0.0208 seconds | PROD: 73 seconds (had to use stopwatch)
// --------------------------------------------------------------
select count(*) as aggregate from `events` where exists
(select * from `photos` where `events`.`id` = `photos`.`eventID`
and `active` = 1)
// ------------------------------------------
// DEV: 0.025 seconds | PROD: 38.9721 seconds
// ------------------------------------------
select * from `events` where exists (select * from `photos` where
`events`.`id` = `photos`.`eventID` and `active` = 1)
order by `date` desc limit 10 offset 0
// ------------------------------------------
// DEV: 0.0112 seconds | PROD: 0.0141 seconds
// ------------------------------------------
select * from `photos` where `active` = 1 and `photos`.`eventID` in
(11194, 11087, 10506, 10797, 9910, 10118, 10212, 9655, 10047, 10049)
The table events contains about 6000 entries and photos less than 50000 entries. If you need further details when it comes to table structure, let me know before down voting in the comments section :-)
On the production server are many other applications running with Laravel or Wordpress using databases on the same MySQL installation and none of them have similar issues.
mysql laravel-5 phpmyadmin eloquent
mysql laravel-5 phpmyadmin eloquent
asked Nov 20 at 7:09
Edwin Krause
1,08311021
1,08311021
dev and production db are different? If yes make sure indexes are present on production also.
– Web Artisan
Nov 20 at 7:21
It's all identical, there are no indexes apart from id as primary key defined on both tables.
– Edwin Krause
Nov 20 at 7:29
May be your production server db engine configuration is much lower than your dev environment. Try to contact your hosting provider.
– Web Artisan
Nov 20 at 7:34
It's on a VPS... So I should be the master of my MySQL server
– Edwin Krause
Nov 20 at 7:41
2
I just added an index on columnphotos.eventID
that seems to do the trick. Fast as a rocket now... : 0.4 seconds for the API to respond
– Edwin Krause
Nov 20 at 7:45
|
show 2 more comments
dev and production db are different? If yes make sure indexes are present on production also.
– Web Artisan
Nov 20 at 7:21
It's all identical, there are no indexes apart from id as primary key defined on both tables.
– Edwin Krause
Nov 20 at 7:29
May be your production server db engine configuration is much lower than your dev environment. Try to contact your hosting provider.
– Web Artisan
Nov 20 at 7:34
It's on a VPS... So I should be the master of my MySQL server
– Edwin Krause
Nov 20 at 7:41
2
I just added an index on columnphotos.eventID
that seems to do the trick. Fast as a rocket now... : 0.4 seconds for the API to respond
– Edwin Krause
Nov 20 at 7:45
dev and production db are different? If yes make sure indexes are present on production also.
– Web Artisan
Nov 20 at 7:21
dev and production db are different? If yes make sure indexes are present on production also.
– Web Artisan
Nov 20 at 7:21
It's all identical, there are no indexes apart from id as primary key defined on both tables.
– Edwin Krause
Nov 20 at 7:29
It's all identical, there are no indexes apart from id as primary key defined on both tables.
– Edwin Krause
Nov 20 at 7:29
May be your production server db engine configuration is much lower than your dev environment. Try to contact your hosting provider.
– Web Artisan
Nov 20 at 7:34
May be your production server db engine configuration is much lower than your dev environment. Try to contact your hosting provider.
– Web Artisan
Nov 20 at 7:34
It's on a VPS... So I should be the master of my MySQL server
– Edwin Krause
Nov 20 at 7:41
It's on a VPS... So I should be the master of my MySQL server
– Edwin Krause
Nov 20 at 7:41
2
2
I just added an index on column
photos.eventID
that seems to do the trick. Fast as a rocket now... : 0.4 seconds for the API to respond– Edwin Krause
Nov 20 at 7:45
I just added an index on column
photos.eventID
that seems to do the trick. Fast as a rocket now... : 0.4 seconds for the API to respond– Edwin Krause
Nov 20 at 7:45
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Although the first two queries don't output much they have to go through the most data and therefore seem to be very memory and/or CPU intense queries.
It appears that my DEV environment has more power than my production environment and therefore I had this huge differences.
The solution at the end was simple: I added an INDEX of type INDEX to the column photos.eventID
which would have been a good idea anyway.
This little change made my API respond in 0.4 seconds instead of 85.7
Tip for the future, EXPLAIN on both DEV and PROD would have clearly identified the missing index on PROD.
– Wilson Hauck
Nov 24 at 20:33
Thanks, I just need to figure out how to use that command :-)
– Edwin Krause
Nov 26 at 7:20
@kevinkrause For initial research in Google search for 'mysql explain tutorial' You will find it is truly EASY, precede your SELECT xxxxx with EXPLAIN - give it a shot, learn how to interpret the results, you will be amazed.
– Wilson Hauck
Nov 26 at 8:25
Thanks, but sorry I don't use google anymore... I couldn't get around the documentation on dev.mysql.com/doc/refman/8.0/en/explain.html , that's why I was asking for a quick pointer....
– Edwin Krause
Nov 26 at 10:10
Alternatives to google include bing.com or yahoo.com - wherever you search for things on the web will work. This is the quickest pointer I know. Have you tried what I suggested? EXPLAIN before SELECT ..... for your introduction.
– Wilson Hauck
Nov 26 at 12:34
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Although the first two queries don't output much they have to go through the most data and therefore seem to be very memory and/or CPU intense queries.
It appears that my DEV environment has more power than my production environment and therefore I had this huge differences.
The solution at the end was simple: I added an INDEX of type INDEX to the column photos.eventID
which would have been a good idea anyway.
This little change made my API respond in 0.4 seconds instead of 85.7
Tip for the future, EXPLAIN on both DEV and PROD would have clearly identified the missing index on PROD.
– Wilson Hauck
Nov 24 at 20:33
Thanks, I just need to figure out how to use that command :-)
– Edwin Krause
Nov 26 at 7:20
@kevinkrause For initial research in Google search for 'mysql explain tutorial' You will find it is truly EASY, precede your SELECT xxxxx with EXPLAIN - give it a shot, learn how to interpret the results, you will be amazed.
– Wilson Hauck
Nov 26 at 8:25
Thanks, but sorry I don't use google anymore... I couldn't get around the documentation on dev.mysql.com/doc/refman/8.0/en/explain.html , that's why I was asking for a quick pointer....
– Edwin Krause
Nov 26 at 10:10
Alternatives to google include bing.com or yahoo.com - wherever you search for things on the web will work. This is the quickest pointer I know. Have you tried what I suggested? EXPLAIN before SELECT ..... for your introduction.
– Wilson Hauck
Nov 26 at 12:34
|
show 1 more comment
up vote
0
down vote
accepted
Although the first two queries don't output much they have to go through the most data and therefore seem to be very memory and/or CPU intense queries.
It appears that my DEV environment has more power than my production environment and therefore I had this huge differences.
The solution at the end was simple: I added an INDEX of type INDEX to the column photos.eventID
which would have been a good idea anyway.
This little change made my API respond in 0.4 seconds instead of 85.7
Tip for the future, EXPLAIN on both DEV and PROD would have clearly identified the missing index on PROD.
– Wilson Hauck
Nov 24 at 20:33
Thanks, I just need to figure out how to use that command :-)
– Edwin Krause
Nov 26 at 7:20
@kevinkrause For initial research in Google search for 'mysql explain tutorial' You will find it is truly EASY, precede your SELECT xxxxx with EXPLAIN - give it a shot, learn how to interpret the results, you will be amazed.
– Wilson Hauck
Nov 26 at 8:25
Thanks, but sorry I don't use google anymore... I couldn't get around the documentation on dev.mysql.com/doc/refman/8.0/en/explain.html , that's why I was asking for a quick pointer....
– Edwin Krause
Nov 26 at 10:10
Alternatives to google include bing.com or yahoo.com - wherever you search for things on the web will work. This is the quickest pointer I know. Have you tried what I suggested? EXPLAIN before SELECT ..... for your introduction.
– Wilson Hauck
Nov 26 at 12:34
|
show 1 more comment
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Although the first two queries don't output much they have to go through the most data and therefore seem to be very memory and/or CPU intense queries.
It appears that my DEV environment has more power than my production environment and therefore I had this huge differences.
The solution at the end was simple: I added an INDEX of type INDEX to the column photos.eventID
which would have been a good idea anyway.
This little change made my API respond in 0.4 seconds instead of 85.7
Although the first two queries don't output much they have to go through the most data and therefore seem to be very memory and/or CPU intense queries.
It appears that my DEV environment has more power than my production environment and therefore I had this huge differences.
The solution at the end was simple: I added an INDEX of type INDEX to the column photos.eventID
which would have been a good idea anyway.
This little change made my API respond in 0.4 seconds instead of 85.7
answered Nov 20 at 8:22
Edwin Krause
1,08311021
1,08311021
Tip for the future, EXPLAIN on both DEV and PROD would have clearly identified the missing index on PROD.
– Wilson Hauck
Nov 24 at 20:33
Thanks, I just need to figure out how to use that command :-)
– Edwin Krause
Nov 26 at 7:20
@kevinkrause For initial research in Google search for 'mysql explain tutorial' You will find it is truly EASY, precede your SELECT xxxxx with EXPLAIN - give it a shot, learn how to interpret the results, you will be amazed.
– Wilson Hauck
Nov 26 at 8:25
Thanks, but sorry I don't use google anymore... I couldn't get around the documentation on dev.mysql.com/doc/refman/8.0/en/explain.html , that's why I was asking for a quick pointer....
– Edwin Krause
Nov 26 at 10:10
Alternatives to google include bing.com or yahoo.com - wherever you search for things on the web will work. This is the quickest pointer I know. Have you tried what I suggested? EXPLAIN before SELECT ..... for your introduction.
– Wilson Hauck
Nov 26 at 12:34
|
show 1 more comment
Tip for the future, EXPLAIN on both DEV and PROD would have clearly identified the missing index on PROD.
– Wilson Hauck
Nov 24 at 20:33
Thanks, I just need to figure out how to use that command :-)
– Edwin Krause
Nov 26 at 7:20
@kevinkrause For initial research in Google search for 'mysql explain tutorial' You will find it is truly EASY, precede your SELECT xxxxx with EXPLAIN - give it a shot, learn how to interpret the results, you will be amazed.
– Wilson Hauck
Nov 26 at 8:25
Thanks, but sorry I don't use google anymore... I couldn't get around the documentation on dev.mysql.com/doc/refman/8.0/en/explain.html , that's why I was asking for a quick pointer....
– Edwin Krause
Nov 26 at 10:10
Alternatives to google include bing.com or yahoo.com - wherever you search for things on the web will work. This is the quickest pointer I know. Have you tried what I suggested? EXPLAIN before SELECT ..... for your introduction.
– Wilson Hauck
Nov 26 at 12:34
Tip for the future, EXPLAIN on both DEV and PROD would have clearly identified the missing index on PROD.
– Wilson Hauck
Nov 24 at 20:33
Tip for the future, EXPLAIN on both DEV and PROD would have clearly identified the missing index on PROD.
– Wilson Hauck
Nov 24 at 20:33
Thanks, I just need to figure out how to use that command :-)
– Edwin Krause
Nov 26 at 7:20
Thanks, I just need to figure out how to use that command :-)
– Edwin Krause
Nov 26 at 7:20
@kevinkrause For initial research in Google search for 'mysql explain tutorial' You will find it is truly EASY, precede your SELECT xxxxx with EXPLAIN - give it a shot, learn how to interpret the results, you will be amazed.
– Wilson Hauck
Nov 26 at 8:25
@kevinkrause For initial research in Google search for 'mysql explain tutorial' You will find it is truly EASY, precede your SELECT xxxxx with EXPLAIN - give it a shot, learn how to interpret the results, you will be amazed.
– Wilson Hauck
Nov 26 at 8:25
Thanks, but sorry I don't use google anymore... I couldn't get around the documentation on dev.mysql.com/doc/refman/8.0/en/explain.html , that's why I was asking for a quick pointer....
– Edwin Krause
Nov 26 at 10:10
Thanks, but sorry I don't use google anymore... I couldn't get around the documentation on dev.mysql.com/doc/refman/8.0/en/explain.html , that's why I was asking for a quick pointer....
– Edwin Krause
Nov 26 at 10:10
Alternatives to google include bing.com or yahoo.com - wherever you search for things on the web will work. This is the quickest pointer I know. Have you tried what I suggested? EXPLAIN before SELECT ..... for your introduction.
– Wilson Hauck
Nov 26 at 12:34
Alternatives to google include bing.com or yahoo.com - wherever you search for things on the web will work. This is the quickest pointer I know. Have you tried what I suggested? EXPLAIN before SELECT ..... for your introduction.
– Wilson Hauck
Nov 26 at 12:34
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387911%2fperformance-differences-between-dev-and-production-environment-mysql-server%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
dev and production db are different? If yes make sure indexes are present on production also.
– Web Artisan
Nov 20 at 7:21
It's all identical, there are no indexes apart from id as primary key defined on both tables.
– Edwin Krause
Nov 20 at 7:29
May be your production server db engine configuration is much lower than your dev environment. Try to contact your hosting provider.
– Web Artisan
Nov 20 at 7:34
It's on a VPS... So I should be the master of my MySQL server
– Edwin Krause
Nov 20 at 7:41
2
I just added an index on column
photos.eventID
that seems to do the trick. Fast as a rocket now... : 0.4 seconds for the API to respond– Edwin Krause
Nov 20 at 7:45