I use sphinx search engine and sometimes when I run
show threads;
I see one thread like picture below with "Net_Idle" state among threads that Its "Time" value goes up to 100 seconds and in some cases up to 500 seconds and then automatically disappears.
What is this thread and when and why it's running?
It means there's an open connection via sphinxql protocol. You can easily reproduce it if you just open 2 connections to your searchd at the same time, then in any of them you will see that the other one has a connection and if you don't do anything there the state will be net_idle. E.g.:
Tab 1:
[snikolaev@dev01 ~]$ mysql -P9314 -h0
mysql>
Tab 2:
[snikolaev@dev01 ~]$ mysql -P9314 -h0
mysql> show threads;
+-------+----------+----------+----------+--------------+
| Tid | Proto | State | Time | Info |
+-------+----------+----------+----------+--------------+
| 16626 | sphinxql | query | 0.000001 | show threads |
| 16598 | sphinxql | net_idle | 3.774544 | |
+-------+----------+----------+----------+--------------+
2 rows in set (0.00 sec)
If you don't know who keeps the connection open you can use lsof, netstat and ps or other tools that do the same to trace that down, e.g.:
[snikolaev@dev01 ~]$ lsof -p 14267|grep TCP
searchd_o 14267 snikolaev 6u IPv4 568694105 0t0 TCP *:9314 (LISTEN)
searchd_o 14267 snikolaev 13u IPv4 568804452 0t0 TCP localhost:9314->localhost:24228 (ESTABLISHED)
[snikolaev@dev01 ~]$ sudo netstat -apn|grep 24228
tcp 0 0 127.0.0.1:9314 127.0.0.1:24228 ESTABLISHED 14267/./searchd_old
tcp 0 0 127.0.0.1:24228 127.0.0.1:9314 ESTABLISHED 28949/mysql
[snikolaev@dev01 ~]$ ps aux|grep 28949
518 28949 0.0 0.0 234088 10596 pts/58 S+ 23:49 0:00 mysql -P9314 -h0
In my case I can see that the connection is from "mysql", in your case it may be different.