High CPU usage on server by MySQL on AWS ubuntu server











up vote
-1
down vote

favorite












MySQL showing very high CPU usage. like over 200% sometime.
I had slow query log on. and slow query time set to 1s.
there is not any slow query.
I am using code igniter PHP.



my my.cnf file :



[mysqld]
innodb_io_capacity=2000
innodb_read_io_threads=32
innodb_write_io_threads=32
innodb_log_buffer_size=250M
innodb_thread_concurrency=0
innodb_buffer_pool_size=1000M
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
##
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
#
# * Fine Tuning
#
innodb_buffer_pool_size = 12G
key_buffer_size = 1G
max_allowed_packet = 256M
thread_stack = 192K
thread_cache_size = 100
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
max_connections = 300


#innodb_buffer_pool_instances=8
#innodb_read_io_threads=8
#innodb_write_io_threads=8

#open_files_limit = 1024
#table_open_cache = 400
server_id = 2
bind-address = 0.0.0.0
log_bin = /var/log/mysql/mysql-bin.log
log_bin_index = /var/log/mysql/mysql-bin.log.index
relay_log = /var/log/mysql/mysql-relay-bin
relay_log_index = /var/log/mysql/mysql-relay-bin.index
expire_logs_days = 10
max_binlog_size = 100M
log_slave_updates = 1
auto-increment-increment = 2
auto-increment-offset = 2
replicate-ignore-db=phpmyadmin
replicate-ignore-db=mysql
skip-name-resolve
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit=0
query_cache_size=0

sort_buffer_size = 2M
join_buffer_size = 128K
read_buffer_size = 128K
read_rnd_buffer_size=256K


what can I do to reduce CPU usage?
Is there any way to find which queryes are causing high cpu usage o










share|improve this question






















  • Are the PHP & CI tags relevant?
    – Nigel Ren
    2 days ago










  • I do not know if something on CI side may causing this or not I try everything I can find on internet on MySQL site so I think may be someone with good knowledge of CI may help me if they had faced this issue before
    – Desi Mulga
    2 days ago















up vote
-1
down vote

favorite












MySQL showing very high CPU usage. like over 200% sometime.
I had slow query log on. and slow query time set to 1s.
there is not any slow query.
I am using code igniter PHP.



my my.cnf file :



[mysqld]
innodb_io_capacity=2000
innodb_read_io_threads=32
innodb_write_io_threads=32
innodb_log_buffer_size=250M
innodb_thread_concurrency=0
innodb_buffer_pool_size=1000M
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
##
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
#
# * Fine Tuning
#
innodb_buffer_pool_size = 12G
key_buffer_size = 1G
max_allowed_packet = 256M
thread_stack = 192K
thread_cache_size = 100
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
max_connections = 300


#innodb_buffer_pool_instances=8
#innodb_read_io_threads=8
#innodb_write_io_threads=8

#open_files_limit = 1024
#table_open_cache = 400
server_id = 2
bind-address = 0.0.0.0
log_bin = /var/log/mysql/mysql-bin.log
log_bin_index = /var/log/mysql/mysql-bin.log.index
relay_log = /var/log/mysql/mysql-relay-bin
relay_log_index = /var/log/mysql/mysql-relay-bin.index
expire_logs_days = 10
max_binlog_size = 100M
log_slave_updates = 1
auto-increment-increment = 2
auto-increment-offset = 2
replicate-ignore-db=phpmyadmin
replicate-ignore-db=mysql
skip-name-resolve
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit=0
query_cache_size=0

sort_buffer_size = 2M
join_buffer_size = 128K
read_buffer_size = 128K
read_rnd_buffer_size=256K


what can I do to reduce CPU usage?
Is there any way to find which queryes are causing high cpu usage o










share|improve this question






















  • Are the PHP & CI tags relevant?
    – Nigel Ren
    2 days ago










  • I do not know if something on CI side may causing this or not I try everything I can find on internet on MySQL site so I think may be someone with good knowledge of CI may help me if they had faced this issue before
    – Desi Mulga
    2 days ago













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











MySQL showing very high CPU usage. like over 200% sometime.
I had slow query log on. and slow query time set to 1s.
there is not any slow query.
I am using code igniter PHP.



my my.cnf file :



[mysqld]
innodb_io_capacity=2000
innodb_read_io_threads=32
innodb_write_io_threads=32
innodb_log_buffer_size=250M
innodb_thread_concurrency=0
innodb_buffer_pool_size=1000M
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
##
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
#
# * Fine Tuning
#
innodb_buffer_pool_size = 12G
key_buffer_size = 1G
max_allowed_packet = 256M
thread_stack = 192K
thread_cache_size = 100
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
max_connections = 300


#innodb_buffer_pool_instances=8
#innodb_read_io_threads=8
#innodb_write_io_threads=8

#open_files_limit = 1024
#table_open_cache = 400
server_id = 2
bind-address = 0.0.0.0
log_bin = /var/log/mysql/mysql-bin.log
log_bin_index = /var/log/mysql/mysql-bin.log.index
relay_log = /var/log/mysql/mysql-relay-bin
relay_log_index = /var/log/mysql/mysql-relay-bin.index
expire_logs_days = 10
max_binlog_size = 100M
log_slave_updates = 1
auto-increment-increment = 2
auto-increment-offset = 2
replicate-ignore-db=phpmyadmin
replicate-ignore-db=mysql
skip-name-resolve
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit=0
query_cache_size=0

sort_buffer_size = 2M
join_buffer_size = 128K
read_buffer_size = 128K
read_rnd_buffer_size=256K


what can I do to reduce CPU usage?
Is there any way to find which queryes are causing high cpu usage o










share|improve this question













MySQL showing very high CPU usage. like over 200% sometime.
I had slow query log on. and slow query time set to 1s.
there is not any slow query.
I am using code igniter PHP.



my my.cnf file :



[mysqld]
innodb_io_capacity=2000
innodb_read_io_threads=32
innodb_write_io_threads=32
innodb_log_buffer_size=250M
innodb_thread_concurrency=0
innodb_buffer_pool_size=1000M
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
##
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
#
# * Fine Tuning
#
innodb_buffer_pool_size = 12G
key_buffer_size = 1G
max_allowed_packet = 256M
thread_stack = 192K
thread_cache_size = 100
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
max_connections = 300


#innodb_buffer_pool_instances=8
#innodb_read_io_threads=8
#innodb_write_io_threads=8

#open_files_limit = 1024
#table_open_cache = 400
server_id = 2
bind-address = 0.0.0.0
log_bin = /var/log/mysql/mysql-bin.log
log_bin_index = /var/log/mysql/mysql-bin.log.index
relay_log = /var/log/mysql/mysql-relay-bin
relay_log_index = /var/log/mysql/mysql-relay-bin.index
expire_logs_days = 10
max_binlog_size = 100M
log_slave_updates = 1
auto-increment-increment = 2
auto-increment-offset = 2
replicate-ignore-db=phpmyadmin
replicate-ignore-db=mysql
skip-name-resolve
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit=0
query_cache_size=0

sort_buffer_size = 2M
join_buffer_size = 128K
read_buffer_size = 128K
read_rnd_buffer_size=256K


what can I do to reduce CPU usage?
Is there any way to find which queryes are causing high cpu usage o







php mysql amazon-ec2 codeigniter-3






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









Desi Mulga

237




237












  • Are the PHP & CI tags relevant?
    – Nigel Ren
    2 days ago










  • I do not know if something on CI side may causing this or not I try everything I can find on internet on MySQL site so I think may be someone with good knowledge of CI may help me if they had faced this issue before
    – Desi Mulga
    2 days ago


















  • Are the PHP & CI tags relevant?
    – Nigel Ren
    2 days ago










  • I do not know if something on CI side may causing this or not I try everything I can find on internet on MySQL site so I think may be someone with good knowledge of CI may help me if they had faced this issue before
    – Desi Mulga
    2 days ago
















Are the PHP & CI tags relevant?
– Nigel Ren
2 days ago




Are the PHP & CI tags relevant?
– Nigel Ren
2 days ago












I do not know if something on CI side may causing this or not I try everything I can find on internet on MySQL site so I think may be someone with good knowledge of CI may help me if they had faced this issue before
– Desi Mulga
2 days ago




I do not know if something on CI side may causing this or not I try everything I can find on internet on MySQL site so I think may be someone with good knowledge of CI may help me if they had faced this issue before
– Desi Mulga
2 days ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted











there is not any slow query




There aren't any slow queries, or there aren't any slow queries showing in the log? I think your first prt of call would be to check if the query logging is working as you expect. This can be done easily using discretionary locks without adding additional load on the system.



Assuming that there really are no queries taking over 1 second, then the load arises fro lots of queries taking less than 1 second. You need to capture them all to identify and prioritize your tuning efforts. But you might start by enabling the query cache (which you have disabled for some reason).






share|improve this answer























  • yes I am sure that slow query log is working.
    – Desi Mulga
    2 days ago










  • I test it by running SELECT SLEEP(2); and that query is logged in
    – Desi Mulga
    2 days ago










  • yes you were right. there is one function in my PHP for loop code which firing query. so if there are 1000 players active this loop fires same query 1000 times. i convert my code and now no query runs in for loop and now my sql cpu usage is under 5%
    – Desi Mulga
    2 days ago











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372786%2fhigh-cpu-usage-on-server-by-mysql-on-aws-ubuntu-server%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted











there is not any slow query




There aren't any slow queries, or there aren't any slow queries showing in the log? I think your first prt of call would be to check if the query logging is working as you expect. This can be done easily using discretionary locks without adding additional load on the system.



Assuming that there really are no queries taking over 1 second, then the load arises fro lots of queries taking less than 1 second. You need to capture them all to identify and prioritize your tuning efforts. But you might start by enabling the query cache (which you have disabled for some reason).






share|improve this answer























  • yes I am sure that slow query log is working.
    – Desi Mulga
    2 days ago










  • I test it by running SELECT SLEEP(2); and that query is logged in
    – Desi Mulga
    2 days ago










  • yes you were right. there is one function in my PHP for loop code which firing query. so if there are 1000 players active this loop fires same query 1000 times. i convert my code and now no query runs in for loop and now my sql cpu usage is under 5%
    – Desi Mulga
    2 days ago















up vote
0
down vote



accepted











there is not any slow query




There aren't any slow queries, or there aren't any slow queries showing in the log? I think your first prt of call would be to check if the query logging is working as you expect. This can be done easily using discretionary locks without adding additional load on the system.



Assuming that there really are no queries taking over 1 second, then the load arises fro lots of queries taking less than 1 second. You need to capture them all to identify and prioritize your tuning efforts. But you might start by enabling the query cache (which you have disabled for some reason).






share|improve this answer























  • yes I am sure that slow query log is working.
    – Desi Mulga
    2 days ago










  • I test it by running SELECT SLEEP(2); and that query is logged in
    – Desi Mulga
    2 days ago










  • yes you were right. there is one function in my PHP for loop code which firing query. so if there are 1000 players active this loop fires same query 1000 times. i convert my code and now no query runs in for loop and now my sql cpu usage is under 5%
    – Desi Mulga
    2 days ago













up vote
0
down vote



accepted







up vote
0
down vote



accepted







there is not any slow query




There aren't any slow queries, or there aren't any slow queries showing in the log? I think your first prt of call would be to check if the query logging is working as you expect. This can be done easily using discretionary locks without adding additional load on the system.



Assuming that there really are no queries taking over 1 second, then the load arises fro lots of queries taking less than 1 second. You need to capture them all to identify and prioritize your tuning efforts. But you might start by enabling the query cache (which you have disabled for some reason).






share|improve this answer















there is not any slow query




There aren't any slow queries, or there aren't any slow queries showing in the log? I think your first prt of call would be to check if the query logging is working as you expect. This can be done easily using discretionary locks without adding additional load on the system.



Assuming that there really are no queries taking over 1 second, then the load arises fro lots of queries taking less than 1 second. You need to capture them all to identify and prioritize your tuning efforts. But you might start by enabling the query cache (which you have disabled for some reason).







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









symcbean

40.6k43976




40.6k43976












  • yes I am sure that slow query log is working.
    – Desi Mulga
    2 days ago










  • I test it by running SELECT SLEEP(2); and that query is logged in
    – Desi Mulga
    2 days ago










  • yes you were right. there is one function in my PHP for loop code which firing query. so if there are 1000 players active this loop fires same query 1000 times. i convert my code and now no query runs in for loop and now my sql cpu usage is under 5%
    – Desi Mulga
    2 days ago


















  • yes I am sure that slow query log is working.
    – Desi Mulga
    2 days ago










  • I test it by running SELECT SLEEP(2); and that query is logged in
    – Desi Mulga
    2 days ago










  • yes you were right. there is one function in my PHP for loop code which firing query. so if there are 1000 players active this loop fires same query 1000 times. i convert my code and now no query runs in for loop and now my sql cpu usage is under 5%
    – Desi Mulga
    2 days ago
















yes I am sure that slow query log is working.
– Desi Mulga
2 days ago




yes I am sure that slow query log is working.
– Desi Mulga
2 days ago












I test it by running SELECT SLEEP(2); and that query is logged in
– Desi Mulga
2 days ago




I test it by running SELECT SLEEP(2); and that query is logged in
– Desi Mulga
2 days ago












yes you were right. there is one function in my PHP for loop code which firing query. so if there are 1000 players active this loop fires same query 1000 times. i convert my code and now no query runs in for loop and now my sql cpu usage is under 5%
– Desi Mulga
2 days ago




yes you were right. there is one function in my PHP for loop code which firing query. so if there are 1000 players active this loop fires same query 1000 times. i convert my code and now no query runs in for loop and now my sql cpu usage is under 5%
– Desi Mulga
2 days ago


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372786%2fhigh-cpu-usage-on-server-by-mysql-on-aws-ubuntu-server%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Wiesbaden

To store a contact into the json file from server.js file using a class in NodeJS

Marschland