Add knobs for various packet buffer sizes

This commit is contained in:
Jingyu Zhou 2019-06-11 17:52:25 -07:00
parent b151141965
commit 2363326ecb
3 changed files with 10 additions and 3 deletions

View File

@ -444,7 +444,7 @@ struct Peer : NonCopyable {
loop { loop {
lastWriteTime = now(); lastWriteTime = now();
int sent = conn->write(self->unsent.getUnsent(), 200 * 1024); // avoid sending large packet int sent = conn->write(self->unsent.getUnsent(), /* limit= */ FLOW_KNOBS->MAX_PACKET_SEND_BYTES);
if (sent) { if (sent) {
self->transport->bytesSent += sent; self->transport->bytesSent += sent;
self->unsent.sent(sent); self->unsent.sent(sent);
@ -735,14 +735,15 @@ static void scanPackets(TransportData* transport, uint8_t*& unprocessed_begin, c
static int getNewBufferSize(uint8_t* begin, uint8_t* end, const NetworkAddress& peerAddress) { static int getNewBufferSize(uint8_t* begin, uint8_t* end, const NetworkAddress& peerAddress) {
const int len = end - begin; const int len = end - begin;
if (len < sizeof(uint32_t)) { if (len < sizeof(uint32_t)) {
return std::max(65536, len * 2); return std::max(FLOW_KNOBS->DEFAULT_PACKET_BUFFER_BYTES, len * 2);
} }
const uint32_t packetLen = *(uint32_t*)begin; const uint32_t packetLen = *(uint32_t*)begin;
if (packetLen > FLOW_KNOBS->PACKET_LIMIT) { if (packetLen > FLOW_KNOBS->PACKET_LIMIT) {
TraceEvent(SevError, "Net2_PacketLimitExceeded").detail("FromPeer", peerAddress.toString()).detail("Length", (int)packetLen); TraceEvent(SevError, "Net2_PacketLimitExceeded").detail("FromPeer", peerAddress.toString()).detail("Length", (int)packetLen);
throw platform_error(); throw platform_error();
} }
return std::max<uint32_t>(4096, packetLen + sizeof(uint32_t) * (peerAddress.isTLS() ? 1 : 2)); return std::max<uint32_t>(FLOW_KNOBS->MIN_PACKET_BUFFER_BYTES,
packetLen + sizeof(uint32_t) * (peerAddress.isTLS() ? 1 : 2));
} }
ACTOR static Future<Void> connectionReader( ACTOR static Future<Void> connectionReader(

View File

@ -109,6 +109,9 @@ FlowKnobs::FlowKnobs(bool randomize, bool isSimulated) {
init( PACKET_LIMIT, 100LL<<20 ); init( PACKET_LIMIT, 100LL<<20 );
init( PACKET_WARNING, 2LL<<20 ); // 2MB packet warning quietly allows for 1MB system messages init( PACKET_WARNING, 2LL<<20 ); // 2MB packet warning quietly allows for 1MB system messages
init( TIME_OFFSET_LOGGING_INTERVAL, 60.0 ); init( TIME_OFFSET_LOGGING_INTERVAL, 60.0 );
init( MAX_PACKET_SEND_BYTES, 256 * 1024 );
init( DEFAULT_PACKET_BUFFER_BYTES, 64 * 1024 );
init( MIN_PACKET_BUFFER_BYTES, 4 * 1024 );
//Sim2 //Sim2
init( MIN_OPEN_TIME, 0.0002 ); init( MIN_OPEN_TIME, 0.0002 );

View File

@ -128,6 +128,9 @@ public:
int64_t PACKET_LIMIT; int64_t PACKET_LIMIT;
int64_t PACKET_WARNING; // 2MB packet warning quietly allows for 1MB system messages int64_t PACKET_WARNING; // 2MB packet warning quietly allows for 1MB system messages
double TIME_OFFSET_LOGGING_INTERVAL; double TIME_OFFSET_LOGGING_INTERVAL;
int MAX_PACKET_SEND_BYTES;
int DEFAULT_PACKET_BUFFER_BYTES;
int MIN_PACKET_BUFFER_BYTES;
//Sim2 //Sim2
//FIMXE: more parameters could be factored out //FIMXE: more parameters could be factored out