Running OTRS on MySQL you might get seldom ‘Too Many Connections’ Error.
This happened recently on my company’s OTRS implementation; I’m just recording findings, nothing to blame neither OTRS nor MySQL!
Facts
After several years of successfully running OTRS on CENTOS/MySQL (MyISAM storage engine) we suddenly started facing daily customers/agents complaining about not being able to use the system any more while getting ‘Too Many Connections’ error. Outage lasted tens of minutes and disappeared without any intervention.
During outage we were unable to open MySQL Workbrench to check through Client Connections what was happening.
Findings
After several such events we decided to leave open an instance of MySQL Workbrench with Client Connection active. When next event occurred we noticed that there was a client connection running a long lasting query with state ‘Copy data to tmp table’ while all other connections were in ‘Locked’ state.
Please notice that MyISAM:
- Has only full table lock granularity;
- Caches only indexes, not data
- Data cache is left at OS operating mercy
Running the query once again we noticed:
- it took no time to complete
- after clearing the query cache (RESET QUERY CACHE;
) it took 5 seconds
- after clearing OS disk cache (CentOS) through echo 3 > /proc/sys/vm/drop_caches
(see Clear Disk Cache ) the query took over 180 seconds.
Conclusion
Due to some facts (…?) at some point there was a query triggered by a client action, query that lasts very long. During this period one of the most used table becomes locked so any subsequent queries will become locked waiting the initial query to finish. OTRS client, noticing no response from the system, will try refreshing the page or clicking once again some link which in turn will trigger server side opening of a new MySQL connection till the default 151 connections is hit.
Solution
After increasing the OS memory from 6 GB to 12 GB and key_buffer_size
to 3 GB (a little bit to defensive) we encountered no more errors.
Some useful MySQL queries
SHOW STATUS LIKE 'key%';
SHOW VARIABLES LIKE 'key%';
SHOW VARIABLES LIKE 'max_heap_table_size';
SHOW STATUS LIKE '%tmp%';
RESET QUERY CACHE;
show engines;
PGgxIGlkPSJydW5uaW5nb3Ryc29ubXlzcWx5b3VtaWdodGdldHNlbGRvbXRvb21hbnljb25u
ZWN0aW9uc2Vycm9yLiI+UnVubmluZyBPVFJTIG9uIE15U1FMIHlvdSBtaWdodCBnZXQgc2Vs
ZG9tICYjODIxNjtUb28gTWFueSBDb25uZWN0aW9ucyYjODIxNzsgRXJyb3IuPC9oMT4NCg0K
PHA+VGhpcyBoYXBwZW5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