<?xml version="1.0"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>CRIN Trac: Ticket #116: Limit the number of MySQL connections from Crin4 to Crin1</title>
    <link>https://trac.crin.org/trac/ticket/116</link>
    <description>&lt;p&gt;
Both the dev, &lt;a class="wiki" href="https://trac.crin.org/trac/wiki/Crin4"&gt;Crin4&lt;/a&gt; and live &lt;a class="wiki" href="https://trac.crin.org/trac/wiki/Crin2"&gt;Crin2&lt;/a&gt;, servers use the MySQL database on &lt;a class="wiki" href="https://trac.crin.org/trac/wiki/Crin1"&gt;Crin1&lt;/a&gt; and we want to limit the resources available to &lt;a class="wiki" href="https://trac.crin.org/trac/wiki/Crin4"&gt;Crin4&lt;/a&gt; so it reduced the impact on the live site.
&lt;/p&gt;
&lt;p&gt;
Some documentation on this:
&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;a class="ext-link" href="https://dba.stackexchange.com/a/15427"&gt;&lt;span class="icon"&gt;​&lt;/span&gt;https://dba.stackexchange.com/a/15427&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;&lt;a class="ext-link" href="https://dev.mysql.com/doc/refman/5.7/en/user-resources.html"&gt;&lt;span class="icon"&gt;​&lt;/span&gt;https://dev.mysql.com/doc/refman/5.7/en/user-resources.html&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;</description>
    <language>en-us</language>
    <image>
      <title>CRIN Trac</title>
      <url>https://trac.crin.org/trac/chrome/site/logo.gif</url>
      <link>https://trac.crin.org/trac/ticket/116</link>
    </image>
    <generator>Trac 1.0.2</generator>
    <item>
      
        <dc:creator>peter</dc:creator>

      <pubDate>Wed, 17 May 2017 12:35:08 GMT</pubDate>
      <title></title>
      <link>https://trac.crin.org/trac/ticket/116#comment:1</link>
      <guid isPermaLink="false">https://trac.crin.org/trac/ticket/116#comment:1</guid>
      <description>
        &lt;pre class="wiki"&gt;I think we should just start with connections for now.
What if we took connections down to 50?
UPDATE mysql.user SET max_connections = 50 WHERE user='myuser' AND
host='10.1.2.30'; FLUSH PRIVILEGES;
On Wed, 17 May 2017 at 12:44 CRIN Trac &amp;lt;trac@trac.crin.org&amp;gt; wrote:
&amp;gt; #116: Limit the number of MySQL connections from Crin4 to Crin1
&amp;gt; ------------------------------+-----------------------------------------
&amp;gt;            Reporter:  chris   |                      Owner:  chris
&amp;gt;                Type:  defect  |                     Status:  new
&amp;gt;            Priority:  major   |                  Milestone:  Maintenance
&amp;gt;           Component:  crin1   |                    Version:
&amp;gt;            Keywords:          |  Estimated Number of Hours:  0
&amp;gt; Add Hours to Ticket:  0       |                  Billable?:  1
&amp;gt;         Total Hours:  0       |
&amp;gt; ------------------------------+-----------------------------------------
&amp;gt;  Both the dev, [[Crin4]] and live [[Crin2]], servers use the MySQL database
&amp;gt;  on [[Crin1]] and we want to limit the resources available to [[Crin4]] so
&amp;gt;  it reduced the impact on the live site.
&amp;gt;
&amp;gt;  Some documentation on this:
&amp;gt;
&amp;gt;  * https://dba.stackexchange.com/a/15427
&amp;gt;  * https://dev.mysql.com/doc/refman/5.7/en/user-resources.html
&amp;gt;
&amp;gt; --
&amp;gt; Ticket URL: &amp;lt;https://trac.crin.org/trac/ticket/116&amp;gt;
&amp;gt; CRIN Trac &amp;lt;https://trac.crin.org/trac&amp;gt;
&amp;gt; Trac project for CRIN website and servers.
&amp;gt;
&lt;/pre&gt;
      </description>
      <category>Ticket</category>
    </item><item>
      
        <dc:creator>chris</dc:creator>

      <pubDate>Thu, 18 May 2017 11:27:07 GMT</pubDate>
      <title>hours changed; totalhours set</title>
      <link>https://trac.crin.org/trac/ticket/116#comment:2</link>
      <guid isPermaLink="false">https://trac.crin.org/trac/ticket/116#comment:2</guid>
      <description>
          &lt;ul&gt;
            &lt;li&gt;&lt;strong&gt;hours&lt;/strong&gt;
                changed from &lt;em&gt;0&lt;/em&gt; to &lt;em&gt;0.5&lt;/em&gt;
            &lt;/li&gt;
            &lt;li&gt;&lt;strong&gt;totalhours&lt;/strong&gt;
                set to &lt;em&gt;0.5&lt;/em&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;p&gt;
Replying to &lt;a class="ticket" href="https://trac.crin.org/trac/ticket/116#comment:1" title="Comment 1"&gt;peter&lt;/a&gt;:
&lt;/p&gt;
&lt;blockquote class="citation"&gt;
&lt;p&gt;
I think we should just start with connections for now.
What if we took connections down to 50?
&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
OK, looking at what we have to start with:
&lt;/p&gt;
&lt;pre class="wiki"&gt;mysql&amp;gt; select Host,User,ssl_type,max_questions,max_updates,max_connections,max_user_connections from user;
+-----------+------------------+----------+---------------+-------------+-----------------+----------------------+
| Host      | User             | ssl_type | max_questions | max_updates | max_connections | max_user_connections |
+-----------+------------------+----------+---------------+-------------+-----------------+----------------------+
| localhost | root             |          |             0 |           0 |               0 |                    0 |
| crin1     | root             |          |             0 |           0 |               0 |                    0 |
| 127.0.0.1 | root             |          |             0 |           0 |               0 |                    0 |
| ::1       | root             |          |             0 |           0 |               0 |                    0 |
| localhost | debian-sys-maint |          |             0 |           0 |               0 |                    0 |
| localhost | piwik            |          |             0 |           0 |               0 |                    0 |
| localhost | owncloud         |          |             0 |           0 |               0 |                    0 |
| localhost | mediawiki        |          |             0 |           0 |               0 |                    0 |
| localhost | phpmyadmin       |          |             0 |           0 |               0 |                    0 |
| crin2     | example          | ANY      |             0 |           0 |               0 |                    0 |
| crin2     | drupal           | ANY      |             0 |           0 |               0 |                    0 |
| crin2     | root             | ANY      |             0 |           0 |               0 |                    0 |
| crin4     | stage            | ANY      |             0 |           0 |               0 |                    0 |
| crin4     | dev              | ANY      |             0 |           0 |               0 |                    0 |
| crin4     | newprod          | ANY      |             0 |           0 |               0 |                    0 |
| crin2     | newprod          | ANY      |             0 |           0 |               0 |                    0 |
| localhost | newprod          |          |             0 |           0 |               0 |                    0 |
| localhost | stage            |          |             0 |           0 |               0 |                    0 |
| localhost | dev              |          |             0 |           0 |               0 |                    0 |
+-----------+------------------+----------+---------------+-------------+-----------------+----------------------+
19 rows in set (0.00 sec)
&lt;/pre&gt;&lt;p&gt;
It looks to me that we have some lines above that we don't need, users "example" doesn't need to connect from the live server, &lt;a class="wiki" href="https://trac.crin.org/trac/wiki/Crin2"&gt;Crin2&lt;/a&gt; to the database server, so:
&lt;/p&gt;
&lt;pre class="wiki"&gt;mysql&amp;gt; delete from user where Host="crin2" and User="example";
Query OK, 1 row affected (0.00 sec)
&lt;/pre&gt;&lt;p&gt;
In terms of the max connections, looking at &lt;tt&gt;/etc/mysq;/my.cnf&lt;/tt&gt; we haven't set a limit for this, looking at &lt;a class="ext-link" href="https://munin.crin.org/munin/crin.org/crin1.crin.org/index.html#mysql2"&gt;&lt;span class="icon"&gt;​&lt;/span&gt;the Munin graphs&lt;/a&gt; there is a default limit of 151 or 152.
&lt;/p&gt;
&lt;p&gt;
I think a max of 50 connections per hour might not make any difference -- connections are probably per &lt;tt&gt;php-fpm&lt;/tt&gt; process and one process might be running a while?
&lt;/p&gt;
&lt;blockquote class="citation"&gt;
&lt;p&gt;
The value for each per-hour limit should be an integer representing a count per hour. For MAX_USER_CONNECTIONS, the limit is an integer representing the maximum number of simultaneous connections by the account.
&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
How about setting the max number of connections to 2 and limiting the select and updates to 1,000 per hour?:
&lt;/p&gt;
&lt;pre class="wiki"&gt;UPDATE user SET max_user_connections=2,max_questions=1000,max_updates=1000 WHERE host="crin4";
&lt;/pre&gt;
      </description>
      <category>Ticket</category>
    </item><item>
      
        <dc:creator>chris</dc:creator>

      <pubDate>Fri, 19 May 2017 12:54:13 GMT</pubDate>
      <title>hours, totalhours changed</title>
      <link>https://trac.crin.org/trac/ticket/116#comment:3</link>
      <guid isPermaLink="false">https://trac.crin.org/trac/ticket/116#comment:3</guid>
      <description>
          &lt;ul&gt;
            &lt;li&gt;&lt;strong&gt;hours&lt;/strong&gt;
                changed from &lt;em&gt;0&lt;/em&gt; to &lt;em&gt;0.25&lt;/em&gt;
            &lt;/li&gt;
            &lt;li&gt;&lt;strong&gt;totalhours&lt;/strong&gt;
                changed from &lt;em&gt;0.5&lt;/em&gt; to &lt;em&gt;0.75&lt;/em&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;p&gt;
I have done the following:
&lt;/p&gt;
&lt;pre class="wiki"&gt;mysql&amp;gt; UPDATE user SET max_user_connections=2,max_questions=1000,max_updates=1000 WHERE host="crin4";
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3  Changed: 3  Warnings: 0
mysql&amp;gt; select Host,User,Grant_priv,ssl_type,max_questions,max_updates,max_connections,max_user_connections from user;
+-----------+------------------+------------+----------+---------------+-------------+-----------------+----------------------+
| Host      | User             | Grant_priv | ssl_type | max_questions | max_updates | max_connections | max_user_connections |
+-----------+------------------+------------+----------+---------------+-------------+-----------------+----------------------+
| localhost | root             | Y          |          |             0 |           0 |               0 |                    0 |
| crin1     | root             | Y          |          |             0 |           0 |               0 |                    0 |
| 127.0.0.1 | root             | Y          |          |             0 |           0 |               0 |                    0 |
| ::1       | root             | Y          |          |             0 |           0 |               0 |                    0 |
| localhost | debian-sys-maint | Y          |          |             0 |           0 |               0 |                    0 |
| localhost | piwik            | N          |          |             0 |           0 |               0 |                    0 |
| localhost | owncloud         | N          |          |             0 |           0 |               0 |                    0 |
| localhost | mediawiki        | N          |          |             0 |           0 |               0 |                    0 |
| localhost | phpmyadmin       | N          |          |             0 |           0 |               0 |                    0 |
| crin2     | drupal           | N          | ANY      |             0 |           0 |               0 |                    0 |
| crin2     | root             | N          | ANY      |             0 |           0 |               0 |                    0 |
| crin4     | stage            | N          | ANY      |          1000 |        1000 |               0 |                    2 |
| crin4     | dev              | N          | ANY      |          1000 |        1000 |               0 |                    2 |
| crin4     | newprod          | N          | ANY      |          1000 |        1000 |               0 |                    2 |
| crin2     | newprod          | N          | ANY      |             0 |           0 |               0 |                    0 |
| localhost | newprod          | N          |          |             0 |           0 |               0 |                    0 |
| localhost | stage            | N          |          |             0 |           0 |               0 |                    0 |
| localhost | dev              | N          |          |             0 |           0 |               0 |                    0 |
+-----------+------------------+------------+----------+---------------+-------------+-----------------+----------------------+
18 rows in set (0.00 sec)
&lt;/pre&gt;&lt;p&gt;
Please let me know if this needs tweaking -- I have loaded the front page of the dev site and it seems fine but I haven't tried load testing it,
&lt;/p&gt;
&lt;p&gt;
Replying to &lt;a class="ticket" href="https://trac.crin.org/trac/ticket/116#comment:2" title="Comment 2"&gt;chris&lt;/a&gt;:
&lt;/p&gt;
&lt;blockquote class="citation"&gt;
&lt;p&gt;
How about setting the max number of connections to 2 and limiting the select and updates to 1,000 per hour?:
&lt;/p&gt;
&lt;pre class="wiki"&gt;UPDATE user SET max_user_connections=2,max_questions=1000,max_updates=1000 WHERE host="crin4";
&lt;/pre&gt;&lt;/blockquote&gt;
      </description>
      <category>Ticket</category>
    </item><item>
      
        <dc:creator>peter</dc:creator>

      <pubDate>Tue, 23 May 2017 11:29:04 GMT</pubDate>
      <title></title>
      <link>https://trac.crin.org/trac/ticket/116#comment:4</link>
      <guid isPermaLink="false">https://trac.crin.org/trac/ticket/116#comment:4</guid>
      <description>
        &lt;p&gt;
Thanks Chris. We will be doing some careful testing soon.
&lt;/p&gt;
      </description>
      <category>Ticket</category>
    </item>
 </channel>
</rss>