Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here we go:</p> <p>Get the 5 slave servers to update a table in a database on the main server inserting their load every X seconds/minutes. Then in the main server, check which of them has the lowest load and redirect the user to that particular one. <img src="https://i.stack.imgur.com/RHelk.jpg" alt="alt text"></p> <p><strong>How to get the server load?</strong></p> <p>There's a function called <code>sys_getloadavg();</code> which will return three samples representing the average system load (the number of processes in the system run queue) over the last 1, 5 and 15 minutes, respectively in an array.</p> <p>That way, if the system load is over a set number, you should redirect the visitor to a different slave server. For example:</p> <pre><code>$load = sys_getloadavg(); if ($load[0] &gt; 80) { //insert into database "I'm busy!!" $query = "UPDATE `server_load` SET `load` = $load WHERE `server_id` = 1"; mysql_query($query); } </code></pre> <p>Note the <code>0</code> on <code>$load</code> means that it's getting the server load for the last minute, use 1 or 2 for the 5 and 15 minute average system load. The query, would be on a script on the slave servers and every time it was run, it would update the average server load on the table <code>server_load</code>.</p> <p><strong>How to choose from the main server</strong></p> <p>Once you've isolated the 'get server load' functionality from the slave servers. All you need to do from the main server is query the database and get the lowest load from the <code>server_load</code> table. The mentioned table, would be functional enough with a timestamp field, an id field, and a load field with the following structure:</p> <pre><code>`timestamp` int(11) not_null `id` int(1) not_null autoincrement `load` int(3) not_null </code></pre> <p>For a basic tutorial introducing mysql and php interaction I suggest this <a href="http://phpsense.com/php/php-mysql.html" rel="nofollow noreferrer">link</a> from phpsense. If you dedicate enough time an read through the documentation I've linked you with, you should be able to achieve your goal. Make sure to ask all your following questions as independent entities if you are unable to find them on this site already. Chances are they've been asked over and over again by people preceding you. Hope I've been of help.</p> <p><strong>Sources:</strong></p> <ul> <li><a href="http://php.net/manual/en/function.sys-getloadavg.php" rel="nofollow noreferrer">php docs</a></li> <li><a href="http://phpsense.com/php/php-mysql.html" rel="nofollow noreferrer">phpsense</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload