From 8972c80d7d5c5abdd31a0ab7caec7076769e1adb Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 18 Aug 2024 22:06:48 +0200 Subject: [PATCH] Warn if max_packets_per_iteration reduced --- builtin/settingtypes.txt | 5 ++--- src/network/mtp/threads.cpp | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index ccafde036..dd193a0c9 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -2024,9 +2024,8 @@ max_simultaneous_block_sends_per_client (Maximum simultaneous block sends per cl # 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 0.0 -# Maximum number of packets sent per send step, if you have a slow connection -# try reducing it, but don't reduce it to a number below double of targeted -# client number. +# Maximum number of packets sent per send step in the low-level networking code. +# You generally don't need to change this, however busy servers may benefit from a higher number. max_packets_per_iteration (Max. packets per iteration) int 1024 1 65535 # Compression level to use when sending mapblocks to the client. diff --git a/src/network/mtp/threads.cpp b/src/network/mtp/threads.cpp index c7c728c9d..d1a1e2a34 100644 --- a/src/network/mtp/threads.cpp +++ b/src/network/mtp/threads.cpp @@ -59,14 +59,24 @@ static inline u8 readChannel(const u8 *packetdata) /* Connection Threads */ /******************************************************************************/ +#define MPPI_SETTING "max_packets_per_iteration" + ConnectionSendThread::ConnectionSendThread(unsigned int max_packet_size, float timeout) : Thread("ConnectionSend"), m_max_packet_size(max_packet_size), m_timeout(timeout), - m_max_data_packets_per_iteration(g_settings->getU16("max_packets_per_iteration")) + m_max_data_packets_per_iteration(g_settings->getU16(MPPI_SETTING)) { - SANITY_CHECK(m_max_data_packets_per_iteration > 1); + auto &mppi = m_max_data_packets_per_iteration; + mppi = MYMAX(mppi, 1); + + const auto mppi_default = Settings::getLayer(SL_DEFAULTS)->getU16(MPPI_SETTING); + if (mppi < mppi_default) { + warningstream << "You are running the network code with a non-default " + "configuration (" MPPI_SETTING "=" << mppi << "). " + "This is not recommended in production." << std::endl; + } } void *ConnectionSendThread::run() @@ -769,7 +779,7 @@ void ConnectionSendThread::sendPackets(float dtime, u32 peer_packet_quota) } } - if (peer_packet_quota > 0) { + if (peer_packet_quota > 0 && !stopRequested()) { for (session_t peerId : peerIds) { PeerHelper peer = m_connection->getPeerNoEx(peerId); if (!peer)