Fix connection issue to multiple databases. #529
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the issue #528
This also speeds up response time by about twice and prevents connection errors (
pq: sorry, too many clients already
).Tested on a hundred databases in a single server.
Before:
Time taken for tests: 213.938 seconds
ab -n 100 http://localhost:42006/metrics
Too many connection errors:
level=error ts=2021-05-05T07:58:24.170Z caller=postgres_exporter.go:1624 err="Error opening connection to database (postgresql://postgres:PASSWORD_REMOVED@postgres:5432/my_db49?sslmode=disable): pq: sorry, too many clients already"
Connection errors
Error on DROP DATABASE
After:
Time taken for tests: 118.641 seconds
ab -n 100 http://localhost:42006/metrics
[root@72cc76a6022e /]# ab -n 100 http://localhost:42006/metrics This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient).....done
Server Software:
Server Hostname: localhost
Server Port: 42006
Document Path: /metrics
Document Length: 490369 bytes
Concurrency Level: 1
Time taken for tests: 118.641 seconds
Complete requests: 100
Failed requests: 99
(Connect: 0, Receive: 0, Length: 99, Exceptions: 0)
Total transferred: 49070954 bytes
HTML transferred: 49059754 bytes
Requests per second: 0.84 [#/sec] (mean)
Time per request: 1186.406 [ms] (mean)
Time per request: 1186.406 [ms] (mean, across all concurrent requests)
Transfer rate: 403.92 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 898 1186 193.1 1142 1870
Waiting: 892 1179 192.3 1135 1863
Total: 898 1186 193.2 1143 1870
Percentage of the requests served within a certain time (ms)
50% 1143
66% 1217
75% 1292
80% 1321
90% 1463
95% 1600
98% 1867
99% 1870
100% 1870 (longest request)
[root@72cc76a6022e /]#
No errors in logs:
No error on DROP DATABASE: