]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Server: Calculate maximal total block sends dynamically (#6393)
authorSmallJoker <SmallJoker@users.noreply.github.com>
Fri, 8 Sep 2017 22:36:48 +0000 (00:36 +0200)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Fri, 8 Sep 2017 22:36:48 +0000 (00:36 +0200)
The block sends per client is 1/2 when reaching the maximal player count.

builtin/settingtypes.txt
minetest.conf.example
src/clientiface.h
src/defaultsettings.cpp
src/server.cpp
src/serverenvironment.h

index 23101f2ee8ca89a8e1fc00d49577c206edb942e7..39f7a854524acffe07253016fd66f17436f4fffa 100644 (file)
@@ -865,11 +865,10 @@ ipv6_server (IPv6 server) bool false
 [**Advanced]
 
 #    Maximum number of blocks that are simultaneously sent per client.
+#    The maximum total count is calculated dynamically:
+#    max_total = ceil((#clients + max_users) * per_client / 4)
 max_simultaneous_block_sends_per_client (Maximum simultaneous block sends per client) int 10
 
-#   Maximum number of blocks that are simultaneously sent in total.
-max_simultaneous_block_sends_server_total (Maximum simultaneous block sends total) int 40
-
 #    To reduce lag, block transfers are slowed down when a player is building something.
 #    This determines how long they are slowed down after placing or removing a node.
 full_block_send_enable_min_time_from_building (Delay in sending blocks after building) float 2.0
index e92cd82f2e8f4384ba06ad5eb241addd7c80351b..10f64e8595c4cdcbfb2a8326a6902add7d9da3f6 100644 (file)
 ### Advanced
 
 #    Maximum number of blocks that are simultaneously sent per client.
+#    The maximum total count is calculated dynamically:
+#    max_total = ceil((#clients + max_users) * per_client / 4)
 #    type: int
 # max_simultaneous_block_sends_per_client = 10
 
-#    Maximum number of blocks that are simultaneously sent in total.
-#    type: int
-# max_simultaneous_block_sends_server_total = 40
-
 #    To reduce lag, block transfers are slowed down when a player is building something.
 #    This determines how long they are slowed down after placing or removing a node.
 #    type: float
index 4d61ae74e45ee89986c5f6ab81c24d0c2da45cc7..4850b0c2aec5a3c74b5a8901aa21b03e7585e6cc 100644 (file)
@@ -272,10 +272,7 @@ class RemoteClient
         */
        void ResendBlockIfOnWire(v3s16 p);
 
-       s32 SendingCount()
-       {
-               return m_blocks_sending.size();
-       }
+       u32 getSendingCount() const { return m_blocks_sending.size(); }
 
        // Increments timeouts and removes timed-out blocks from list
        // NOTE: This doesn't fix the server-not-sending-block bug
index 212bc62084d69226a3ce7d6dae8dffa3fc6bcbb5..2ddd5a43b198b311cf4ffda6c3291cabb855a239 100644 (file)
@@ -298,7 +298,6 @@ void set_default_settings(Settings *settings)
        settings->setDefault("strict_protocol_version_checking", "false");
        settings->setDefault("player_transfer_distance", "0");
        settings->setDefault("max_simultaneous_block_sends_per_client", "10");
-       settings->setDefault("max_simultaneous_block_sends_server_total", "40");
        settings->setDefault("time_send_interval", "5");
 
        settings->setDefault("default_game", "minetest");
index 7bae69d559b1af295fd28f20099fa30cd781b78b..c5b7bbd79df8458ba8743fd4d59320ca6ac0c2e6 100644 (file)
@@ -2181,7 +2181,7 @@ void Server::SendBlocks(float dtime)
 
        std::vector<PrioritySortedBlockTransfer> queue;
 
-       s32 total_sending = 0;
+       u32 total_sending = 0;
 
        {
                ScopeProfiler sp2(g_profiler, "Server: selecting blocks for sending");
@@ -2195,7 +2195,7 @@ void Server::SendBlocks(float dtime)
                        if (!client)
                                continue;
 
-                       total_sending += client->SendingCount();
+                       total_sending += client->getSendingCount();
                        client->GetNextBlocks(m_env,m_emerge, dtime, queue);
                }
                m_clients.unlock();
@@ -2207,11 +2207,13 @@ void Server::SendBlocks(float dtime)
        std::sort(queue.begin(), queue.end());
 
        m_clients.lock();
-       s32 max_blocks_to_send =
-                       g_settings->getS32("max_simultaneous_block_sends_server_total");
+
+       // Maximal total count calculation
+       // The per-client block sends is halved with the maximal online users
+       u32 max_blocks_to_send = (m_env->getPlayerCount() + g_settings->getU32("max_users")) *
+               g_settings->getU32("max_simultaneous_block_sends_per_client") / 4 + 1;
 
        for (const PrioritySortedBlockTransfer &block_to_send : queue) {
-               //TODO: Calculate limit dynamically
                if (total_sending >= max_blocks_to_send)
                        break;
 
index 9d84d7a480c82108e7428211b8372fcb6cc03405..0eabfc08fa0867cc24b49cca89ac90a31daa7b5d 100644 (file)
@@ -342,6 +342,7 @@ class ServerEnvironment : public Environment
 
        RemotePlayer *getPlayer(const u16 peer_id);
        RemotePlayer *getPlayer(const char* name);
+       u32 getPlayerCount() const { return m_players.size(); }
 
        static bool migratePlayersDatabase(const GameParams &game_params,
                        const Settings &cmd_args);