title: MySQL hanging in Writing to Net
body: <p>I have problem, when MySQL thread sometime stuck at status &quot;Writing to net&quot;.</p>
  <p>I have 4 Apache server (2.4) (requests are load-balanced on them) a 1 MySQL (MariaDB 10). Apache is executing php56. All Apache servers have same configuration. All servers runs on CentOS 7. SElinux is disabled on Apache servers for debug reasons. No problems in audit logs on DB server. All servers are virtual and located on same cluster (VMware).</p>
  <p>Problem appear only on specific pages and specific queries to DB.
  Usually there is around 100-200 separate queries on page and most of them takes 0.0001-0.0010 s. But then I have one query that takes around 1-2sec. The query itself take much lesser time (around 0.0045s).
  Problematic query returns around 8984 rows and when executed from CLI from debug script, it is executed fast as expected.</p>
  <p>Strange is that in time some Apache servers execute that page quickly, and some slowly. It changes (during day). Also I tried remove one Apache server from cluster and then send same request. If server is not under any load, it usually responds fast.</p>
  <p>All server have enough resources (CPU and RAM) so it is definitely not load issue. They usually have around 4-10 active Apache workers (prefork) and have capacity for 100 active workers.</p>
  <p>I tried debugging with tcpdump and when requesting page, I can see packet flow for fast queries and then it stops for a while and resumes. Not sure if the problem is on MySQL server or on Apache server.</p>
  <p>My guess is that I am hitting some kind of limit, but I have no idea which one.</p>