I have an intense query, which is issued from a java/hibernate application, that is timing out after 3-4 minutes. Which my.cnf configurations control that behavior ? or alternatively, how can this be configured through hibernate ? Why the query takes so long is beyond the scope of this question. Thanks
You could be hitting a timeout on InnoDB locks and need to adjust the innodb_lock_wait_timeout parameter to ensure that queries don't get cut for holding locks too long.
It's also possible that the query is still running, but the web process that initiated it has timed out. If you can see your long-running query with SHOW PROCESSLIST after the fact, you will need to adjust your web server request time-out.
Related
I'm working on a node.js application that connects to a MySQL server. The following likely isn't node.js-specific, though.
Currently, my code initializes a MySQL connection at the application start-up, and then it uses that connection every time it needs to make a query.
The issue I'm facing with my approach is that the connection tends to close after a period of time. I'm not sure how long that period of time is, but it seems to be at least several hours. I'm also not sure whether it's caused by inactivity.
In any case, I'm wondering what would be a better approach for managing MySQL connections long-term. Of possible approaches, I've considered:
Simply checking before each query to see whether the connection is still valid. If not, reconnect before executing the query.
Pooling MySQL connections. Would this be overkill for a fairly small application?
Periodically (every hour or so), execute a query, in case this is occurring due to inactivity. However, this doesn't remedy the situation in possible cases not caused by inactivity.
Connect and disconnect before/after queries. Bad idea because of the overhead involved.
I'm leaning toward using one of the first two options, as you might imagine. Which of the options would be most reliable and efficient?
The best practice for Node.js seems to be to use a connection pool. See Node.js MySQL Needing Persistent Connection.
The default timeout for idle connections is 28800 seconds, and is configurable with the wait_timeout variable. See http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_wait_timeout
When I restart mysql, website becomes too slow for about 10 minutes.I think it is because innodb_buffer pool and query cache.
innodb buffer pool =8G and query cache = 2G.
I am changing my .cnf for optimizing but i have 200 online users and slowing down server for 10 minutes makes users angy.
Is there anyway I can change mysql variables without mysql restart?
Those aren't the variables making you slow after restart, those are the variables making you faster after a few minutes when everything is in memory again.
Some global variables may be changed with SET global varname=..., some can't. So, it all depends. Just a reminder: if you're satisfied with them... don't forget to add them in the config for when you DO need to restart. You wouldn't be the first to accidentally use a vital piece of configuration that way.
Having multiple mysql servers & taking one offline for a reload (the other one gets all the queries) can be blessing, but may be pricey of course.
I know SHOW PROCESSLIST can show me which processes are Locked, but how do I determine which process is blocking it? Is that info available? I know in SQLServer there's a column that tells you which process is blocking another process. Is there something similar here?
Usually it's a long running query in "sending data" state that is using tables needed by locked queries.
Usually, it is the longest running query on the same table that your query is running on. But, it depends on the storage engine that you are using. If you are using InnoDB, you won't have this issue.
my site started dragging lately, the queries taking exceptionally longer than I would expect with properly tuned indexes. I just restarted the mysql server after 31 days uptime and every query is now substantially faster and the whole site renders 3-4 times faster.
Would there be anything that jumps out at you as to why this may have been? Improper settings on my.cnf perhaps? Any ideas as to what I can start looking at to try and pinpoint why?
thanks
updated note: I have a 16GB dedicated db box and mysql runs at about 71% of memory after a week or so.
Try to execute show processlist;, maybe there are some long lasting threads that were not killed for some reason.
Similarly execute SHOW SESSION STATUS LIKE 'Created%'; to check if mysql hasn't created to many temporary tables.
Server restart automatically closes all open temp tables and kills threads, so the application might run quicker.
Do you have temporary table(s) that might not be getting cleared/collected?
I would suggest using MySQL Enterprise for analysis purposes. It comes with a 30 day trial. We just used it. We got alerts such as :
CRITICAL Alert - Table Scans Excessive
The target server does not appear to be using indexes efficiently.
CRITICAL Alert - Connection Usage Excessive
CRITICAL Alert - CPU Usage Excessive
WARNING Alert - MyISAM Key Cache Has Sub-Optimal Hit Rate
Just something to explore!
I have around 3 websites residing in a server which is being shared with other teams. I have been notified that there is a huge increase in CPU usage and we need to lower it down. I doubt my websites are causing this.
I have been using SHOW FULL PROCESSLIST in MySQL and 90% of the time shows queries from other databases. But I think executing multiple SHOW FULL PROCESSLIST commands is not enough proof. How can I verify that my databases aren't CPU hogs?
If you suspect that its a MySQL query, try inspecting the MySQL Slow Query Log. The log will help you identify queries that take long time to execute. You can then copy-paste the query text into a MySQL query session, execute it and observe the CPU usage.
You may also want to install different MySQL release, that allows to track exact user statistics and some other things:
http://www.mysqlperformanceblog.com/2008/07/16/mysql-releases-with-percona-patches/