Browse Source

Fix: Packet coalescing with 1ms flush timer

- Changed tx_wait_time from 100ms to 1ms for faster packet delivery
- Small packets now coalesce in buffer until:
  * Buffer has less than 100 bytes remaining, or
  * 1ms flush timer expires
- Large packets are split across multiple fragments as before
- All 17 tests pass
nodeinfo-routing-update
Evgeny 8 months ago
parent
commit
e90cf9f0c7
  1. 22
      src/pkt_normalizer.c

22
src/pkt_normalizer.c

@ -24,10 +24,9 @@ struct PKTNORM* pn_init(struct ETCP_CONN* etcp) {
pn->etcp = etcp; pn->etcp = etcp;
pn->ua = etcp->instance->ua; pn->ua = etcp->instance->ua;
// frag_size должен соответствовать размеру блока в data_pool // frag_size = MTU минус резерв для дополнительных опций (ACK и прочие заголовки)
// data_pool->object_size обычно равен MTU (1500) pn->frag_size = etcp->mtu - 100;
pn->frag_size = etcp->instance->data_pool->object_size; pn->tx_wait_time = 1; // 1ms timer for packet coalescing
pn->tx_wait_time = 100; // Increased to ensure flush happens between packets
pn->input = queue_new(pn->ua, 0); // No hash needed pn->input = queue_new(pn->ua, 0); // No hash needed
pn->output = queue_new(pn->ua, 0); // No hash needed pn->output = queue_new(pn->ua, 0); // No hash needed
@ -278,9 +277,18 @@ static void etcp_input_ready_cb(struct ll_queue* q, void* arg) {
queue_dgram_free(in_dgram); queue_dgram_free(in_dgram);
queue_entry_free(in_dgram); queue_entry_free(in_dgram);
// Send immediately to ensure packet is not lost // Check if buffer is almost full (less than 100 bytes remaining)
pn_send_to_etcp(pn); if (pn->data_ptr + 100 >= pn->data_size) {
pn_buf_renew(pn); // Buffer is almost full - send immediately
pn_send_to_etcp(pn);
pn_buf_renew(pn);
} else {
// Set flush timer to send after tx_wait_time ms
if (pn->flush_timer) {
uasync_cancel_timeout(pn->ua, pn->flush_timer);
}
pn->flush_timer = uasync_set_timeout(pn->ua, pn->tx_wait_time, pn, pn_flush_cb);
}
} }
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "pn_packer: etcp_input_ready_cb finished, processed=%d", processed); DEBUG_INFO(DEBUG_CATEGORY_ETCP, "pn_packer: etcp_input_ready_cb finished, processed=%d", processed);

Loading…
Cancel
Save