Use max_connections in calculation, top prevent possible deadlock, if max_connection is high.
Attach a file by drag & drop or click to upload