Mysql – Do too many subquries create multiple sleeping processes in MySQL

javaMySQLsubquery

I am using java & MySQL to make an app.
When I check the process list. I see a lot of sleeping processes. It also reaches to a points when no further connection is allowed.

I have read many answers around which tell the command to masskill the process or some suggests checking the code for bug. I have checked that I'm closing the connections properly using the Apache Commons DbUtils.

        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(statement);
        DbUtils.closeQuietly(con);

I am not able to figure out why these processes don't get killed after closing the connection.

My question is

  1. Do too many subquries create multiple sleeping processes in MySQL? I don't see much relation though and didn't find anything on search.

  2. Does passing connection object through methods create extra/multiple processes?

Regards

Best Answer

One connection = one process (or thread). Period. Subqueries, UNIONs, and PARTITIONing do not create subprocesses.

What causes Sleeping processes:

  • Connections that are busy with non-SQL work. (Usually 'Time' is 0 or small.)
  • Connections that don't go away.
  • Connection pooling at the client.

Sleeping processes are relatively harmless. No need to kill them. All connections (sleeping or not) are capped at max_connections, after which, trying to get a new connection gets an error.

On the other hand, sometimes the client(s) have parameters that lead to an unreasonable number of connections. Apache has what used to be called MaxClients, which (in my opinion) should not be set higher than 20.