Skip to content

PMM-7958 Fix connection issue. #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 5, 2021
Merged

Conversation

askomorokhov
Copy link

@askomorokhov askomorokhov commented May 4, 2021

https://jira.percona.com/browse/PMM-7958
FB: Percona-Lab/pmm-submodules#1735

Ref: prometheus-community#529


Before the fix db.SetMaxIdleConns(1), you can see:

  • the relatively slow performance;
  • errors in connection;
  • idle connections in all DBs;
  • errors on drop DB.

ab report:

[root@371cb8fe24c2 /]# ab -n 100 -c 2  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:        483030 bytes

Concurrency Level:      2
Time taken for tests:   1213.730 seconds
Complete requests:      100
Failed requests:        97
   (Connect: 0, Receive: 0, Length: 97, Exceptions: 0)
Total transferred:      48320076 bytes
HTML transferred:       48308876 bytes
Requests per second:    0.08 [#/sec] (mean)
Time per request:       24274.606 [ms] (mean)
Time per request:       12137.303 [ms] (mean, across all concurrent requests)
Transfer rate:          38.88 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       2
Processing: 12166 24031 4348.8  24260   36231
Waiting:    12159 24022 4349.4  24250   36225
Total:      12167 24031 4348.8  24260   36231

Percentage of the requests served within a certain time (ms)
  50%  24260
  66%  24288
  75%  24327
  80%  24405
  90%  30291
  95%  30313
  98%  30464
  99%  36231
 100%  36231 (longest request)
[root@371cb8fe24c2 /]# 

Error on drop db

postgres=# drop database my_db;                                                                                                                                                                                                                               
ERROR:  database "my_db" is being accessed by other users                                                                                                                                                                                                     
DETAIL:  There is 1 other session using the database.    


After the fix db.SetMaxIdleConns(-1), you can see:

  • an increase in performance;
  • no error in connection
  • no idle connections in all DBs;
  • no error on drop db.

ab report:

[root@371cb8fe24c2 /]# ab -n 100 -c 2  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:        483102 bytes

Concurrency Level:      2
Time taken for tests:   80.211 seconds
Complete requests:      100
Failed requests:        99
   (Connect: 0, Receive: 0, Length: 99, Exceptions: 0)
Total transferred:      48324786 bytes
HTML transferred:       48313586 bytes
Requests per second:    1.25 [#/sec] (mean)
Time per request:       1604.226 [ms] (mean)
Time per request:       802.113 [ms] (mean, across all concurrent requests)
Transfer rate:          588.35 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       0
Processing:  1062 1583 393.6   1466    3203
Waiting:     1054 1573 392.6   1455    3188
Total:       1062 1583 393.6   1466    3203

Percentage of the requests served within a certain time (ms)
  50%   1466
  66%   1621
  75%   1749
  80%   1852
  90%   2182
  95%   2309
  98%   3171
  99%   3203
 100%   3203 (longest request)

Idle connection to db

postgres=# SELECT * FROM pg_stat_activity WHERE datname='my_db';                                                                                                                                                                                              
 datid | datname | pid | leader_pid | usesysid | usename  | application_name | client_addr | client_hostname | client_port |         backend_start         | xact_start |          query_start          |         state_change          | wait_event_type | wa
it_event | state | backend_xid | backend_xmin |       query       |  backend_type                                                                                                                                                                             
-------+---------+-----+------------+----------+----------+------------------+-------------+-----------------+-------------+-------------------------------+------------+-------------------------------+-------------------------------+-----------------+---
---------+-------+-------------+--------------+-------------------+----------------                                                                                                                                                                           
 16384 | my_db   |  80 |            |       10 | postgres |                  | 172.25.0.4  |                 |       37364 | 2021-05-03 08:51:20.152445+00 |            | 2021-05-03 08:51:23.561045+00 | 2021-05-03 08:51:23.561157+00 | Client          | Cl
ientRead | idle  |             |              | SELECT version(); | client backend                                                                                                                                                                            
(1 row)        

No idle connection to DBs:

postgres=# SELECT COUNT(*) FROM pg_stat_activity WHERE state='idle';
-[ RECORD 1 ]
count | 0

No error on drop db.

postgres=# drop database my_db;                                                                                                                                                                                                                               
DROP DATABASE 

@askomorokhov askomorokhov self-assigned this May 4, 2021
@askomorokhov askomorokhov marked this pull request as ready for review May 4, 2021 09:24
@askomorokhov askomorokhov requested a review from ademidoff May 4, 2021 12:53
@askomorokhov askomorokhov merged commit 96114c2 into master May 5, 2021
@askomorokhov askomorokhov deleted the PMM-7958-PostresSQL-db-issue branch May 5, 2021 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants