Skip to content

Ensures a single database connection is used.#807

Merged
Poslovitch merged 1 commit intodevelopfrom
805_database
Jul 2, 2019
Merged

Ensures a single database connection is used.#807
Poslovitch merged 1 commit intodevelopfrom
805_database

Conversation

@tastybento
Copy link
Copy Markdown
Member

#805

Database connectors were creating a new connection every time they were
called. Also the top-level database object was being recreated every
time getDatabase was requested.

#805

Database connectors were creating a new connection every time they were
called. Also the top-level database object was being recreated every
time getDatabase was requested.
@tastybento tastybento added this to the 1.6.0 milestone Jul 2, 2019
@tastybento tastybento self-assigned this Jul 2, 2019
@tastybento tastybento requested a review from Poslovitch July 2, 2019 00:54
@tastybento
Copy link
Copy Markdown
Member Author

Testing with MySQL shows that this code reduces the process list to 1:

MySQL [(none)]> show processlist;
+------+----------+-----------------+----------+---------+------+----------+------------------+
| Id   | User     | Host            | db       | Command | Time | State    | Info             |
+------+----------+-----------------+----------+---------+------+----------+------------------+
|   49 | username | localhost       | NULL     | Query   |    0 | starting | show processlist |
| 1110 | username | localhost:58442 | bentobox | Sleep   |    7 |          | NULL             |
+------+----------+-----------------+----------+---------+------+----------+------------------+
2 rows in set (0.000 sec)

Before, this is what it looked like:

MySQL [(none)]> show processlist;
+-----+----------+-----------------+----------+---------+------+----------+------------------+
| Id  | User     | Host            | db       | Command | Time | State    | Info             |
+-----+----------+-----------------+----------+---------+------+----------+------------------+
|  49 | username | localhost       | NULL     | Query   |    0 | starting | show processlist |
| 743 | username | localhost:58099 | bentobox | Sleep   | 1127 |          | NULL             |
| 744 | username | localhost:58100 | bentobox | Sleep   | 1127 |          | NULL             |
| 745 | username | localhost:58101 | bentobox | Sleep   |  863 |          | NULL             |
| 751 | username | localhost:58164 | bentobox | Sleep   |  864 |          | NULL             |
| 752 | username | localhost:58165 | bentobox | Sleep   |  864 |          | NULL             |
| 753 | username | localhost:58166 | bentobox | Sleep   | 1102 |          | NULL             |
| 754 | username | localhost:58168 | bentobox | Sleep   | 1101 |          | NULL             |
| 755 | username | localhost:58169 | bentobox | Sleep   |  863 |          | NULL             |
| 756 | username | localhost:58170 | bentobox | Sleep   |  863 |          | NULL             |
| 757 | username | localhost:58171 | bentobox | Sleep   | 1101 |          | NULL             |
| 759 | username | localhost:58173 | bentobox | Sleep   |  863 |          | NULL             |
| 760 | username | localhost:58174 | bentobox | Sleep   | 1101 |          | NULL             |
| 797 | username | localhost:58198 | bentobox | Sleep   |  861 |          | NULL             |
| 798 | username | localhost:58199 | bentobox | Sleep   |  861 |          | NULL             |
| 799 | username | localhost:58200 | bentobox | Sleep   |  612 |          | NULL             |
| 800 | username | localhost:58204 | bentobox | Sleep   |  613 |          | NULL             |
| 801 | username | localhost:58205 | bentobox | Sleep   |  613 |          | NULL             |
| 802 | username | localhost:58206 | bentobox | Sleep   |  858 |          | NULL             |
| 803 | username | localhost:58207 | bentobox | Sleep   |  858 |          | NULL             |
| 804 | username | localhost:58208 | bentobox | Sleep   |  613 |          | NULL             |
| 805 | username | localhost:58209 | bentobox | Sleep   |  613 |          | NULL             |
| 806 | username | localhost:58210 | bentobox | Sleep   |  858 |          | NULL             |
| 808 | username | localhost:58212 | bentobox | Sleep   |  612 |          | NULL             |
| 809 | username | localhost:58213 | bentobox | Sleep   |  858 |          | NULL             |
| 898 | username | localhost:58326 | bentobox | Sleep   |  262 |          | NULL             |
| 899 | username | localhost:58327 | bentobox | Sleep   |  262 |          | NULL             |
| 900 | username | localhost:58328 | bentobox | Sleep   |   88 |          | NULL             |
| 901 | username | localhost:58332 | bentobox | Sleep   |   88 |          | NULL             |
| 902 | username | localhost:58333 | bentobox | Sleep   |   88 |          | NULL             |
| 903 | username | localhost:58334 | bentobox | Sleep   |  260 |          | NULL             |
| 904 | username | localhost:58335 | bentobox | Sleep   |  260 |          | NULL             |
| 905 | username | localhost:58336 | bentobox | Sleep   |   88 |          | NULL             |
| 906 | username | localhost:58337 | bentobox | Sleep   |   88 |          | NULL             |
| 907 | username | localhost:58338 | bentobox | Sleep   |  260 |          | NULL             |
| 909 | username | localhost:58340 | bentobox | Sleep   |   88 |          | NULL             |
| 910 | username | localhost:58341 | bentobox | Sleep   |  260 |          | NULL             |
| 935 | username | localhost:58350 | bentobox | Sleep   |   11 |          | NULL             |
+-----+----------+-----------------+----------+---------+------+----------+------------------+
38 rows in set (0.057 sec)

I believe that the excessive number of connections is likely causing the issues in #805 and probably #798. It will require real life testing to confirm. Even if those are not fixed, this is still the right way to use the database.

@Poslovitch Poslovitch added the Status: Need review Waiting for a review to be made on this Pull Request label Jul 2, 2019
Copy link
Copy Markdown
Member

@Poslovitch Poslovitch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good.

@Poslovitch
Copy link
Copy Markdown
Member

Thanks for the PR, mergimg.

@Poslovitch Poslovitch added Status: Done This issue has been completed or answered. This pull request has been merged. and removed Status: Need review Waiting for a review to be made on this Pull Request labels Jul 2, 2019
@Poslovitch Poslovitch merged commit bd69179 into develop Jul 2, 2019
@Poslovitch Poslovitch deleted the 805_database branch July 2, 2019 04:47
@Poslovitch Poslovitch mentioned this pull request Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Done This issue has been completed or answered. This pull request has been merged. Type: Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants