Skip to content

Commit 745a90d

Browse files
SmallJokernerzhul
authored andcommittedSep 8, 2017
Server: Calculate maximal total block sends dynamically (#6393)
The block sends per client is 1/2 when reaching the maximal player count.
1 parent 1105a14 commit 745a90d

File tree

6 files changed

+13
-17
lines changed

6 files changed

+13
-17
lines changed
 

Diff for: ‎builtin/settingtypes.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -865,11 +865,10 @@ ipv6_server (IPv6 server) bool false
865865
[**Advanced]
866866

867867
# Maximum number of blocks that are simultaneously sent per client.
868+
# The maximum total count is calculated dynamically:
869+
# max_total = ceil((#clients + max_users) * per_client / 4)
868870
max_simultaneous_block_sends_per_client (Maximum simultaneous block sends per client) int 10
869871

870-
# Maximum number of blocks that are simultaneously sent in total.
871-
max_simultaneous_block_sends_server_total (Maximum simultaneous block sends total) int 40
872-
873872
# To reduce lag, block transfers are slowed down when a player is building something.
874873
# This determines how long they are slowed down after placing or removing a node.
875874
full_block_send_enable_min_time_from_building (Delay in sending blocks after building) float 2.0

Diff for: ‎minetest.conf.example

+2-4
Original file line numberDiff line numberDiff line change
@@ -1049,13 +1049,11 @@
10491049
### Advanced
10501050

10511051
# Maximum number of blocks that are simultaneously sent per client.
1052+
# The maximum total count is calculated dynamically:
1053+
# max_total = ceil((#clients + max_users) * per_client / 4)
10521054
# type: int
10531055
# max_simultaneous_block_sends_per_client = 10
10541056

1055-
# Maximum number of blocks that are simultaneously sent in total.
1056-
# type: int
1057-
# max_simultaneous_block_sends_server_total = 40
1058-
10591057
# To reduce lag, block transfers are slowed down when a player is building something.
10601058
# This determines how long they are slowed down after placing or removing a node.
10611059
# type: float

Diff for: ‎src/clientiface.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,7 @@ class RemoteClient
272272
*/
273273
void ResendBlockIfOnWire(v3s16 p);
274274

275-
s32 SendingCount()
276-
{
277-
return m_blocks_sending.size();
278-
}
275+
u32 getSendingCount() const { return m_blocks_sending.size(); }
279276

280277
// Increments timeouts and removes timed-out blocks from list
281278
// NOTE: This doesn't fix the server-not-sending-block bug

Diff for: ‎src/defaultsettings.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ void set_default_settings(Settings *settings)
298298
settings->setDefault("strict_protocol_version_checking", "false");
299299
settings->setDefault("player_transfer_distance", "0");
300300
settings->setDefault("max_simultaneous_block_sends_per_client", "10");
301-
settings->setDefault("max_simultaneous_block_sends_server_total", "40");
302301
settings->setDefault("time_send_interval", "5");
303302

304303
settings->setDefault("default_game", "minetest");

Diff for: ‎src/server.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,7 @@ void Server::SendBlocks(float dtime)
21812181

21822182
std::vector<PrioritySortedBlockTransfer> queue;
21832183

2184-
s32 total_sending = 0;
2184+
u32 total_sending = 0;
21852185

21862186
{
21872187
ScopeProfiler sp2(g_profiler, "Server: selecting blocks for sending");
@@ -2195,7 +2195,7 @@ void Server::SendBlocks(float dtime)
21952195
if (!client)
21962196
continue;
21972197

2198-
total_sending += client->SendingCount();
2198+
total_sending += client->getSendingCount();
21992199
client->GetNextBlocks(m_env,m_emerge, dtime, queue);
22002200
}
22012201
m_clients.unlock();
@@ -2207,11 +2207,13 @@ void Server::SendBlocks(float dtime)
22072207
std::sort(queue.begin(), queue.end());
22082208

22092209
m_clients.lock();
2210-
s32 max_blocks_to_send =
2211-
g_settings->getS32("max_simultaneous_block_sends_server_total");
2210+
2211+
// Maximal total count calculation
2212+
// The per-client block sends is halved with the maximal online users
2213+
u32 max_blocks_to_send = (m_env->getPlayerCount() + g_settings->getU32("max_users")) *
2214+
g_settings->getU32("max_simultaneous_block_sends_per_client") / 4 + 1;
22122215

22132216
for (const PrioritySortedBlockTransfer &block_to_send : queue) {
2214-
//TODO: Calculate limit dynamically
22152217
if (total_sending >= max_blocks_to_send)
22162218
break;
22172219

Diff for: ‎src/serverenvironment.h

+1
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ class ServerEnvironment : public Environment
342342

343343
RemotePlayer *getPlayer(const u16 peer_id);
344344
RemotePlayer *getPlayer(const char* name);
345+
u32 getPlayerCount() const { return m_players.size(); }
345346

346347
static bool migratePlayersDatabase(const GameParams &game_params,
347348
const Settings &cmd_args);

0 commit comments

Comments
 (0)
Please sign in to comment.