From 1fcc353b7b4b7977dfd9ec4a5a0fcbd90c94bef3 Mon Sep 17 00:00:00 2001 From: rbucek Date: Wed, 6 Dec 2023 08:34:08 +0100 Subject: [PATCH] force heap cleanup if the size is greater than 20% extension of the output from the manager command packetbuffer_log: - block size - sum of block sizes - heap values --- buffers_control.h | 12 ++++++++++++ manager.cpp | 3 ++- pcap_queue.cpp | 10 +++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/buffers_control.h b/buffers_control.h index e289f52ef..0f29cac8a 100644 --- a/buffers_control.h +++ b/buffers_control.h @@ -135,6 +135,18 @@ class cBuffersControl { pb_trash_minTime = -1; pb_trash_maxTime = -1; } + string debug() { + ostringstream outStr; + outStr << "BUFFERS CONTROL" << endl + << " max_buffer_mem: " << max_buffer_mem << " (" << (max_buffer_mem / 1024 / 1024) << "MB)" << endl + << " max_buffer_mem_own_use: " << max_buffer_mem_own_use << " (" << (max_buffer_mem_own_use / 1024 / 1024) << "MB)" << endl + << " max_buffer_mem_other_uses: " << max_buffer_mem_other_uses << " (" << (max_buffer_mem_other_uses / 1024 / 1024) << "MB)" << endl + << " pb_used_size: " << pb_used_size << " (" << (pb_used_size / 1024 / 1024) << "MB)" << endl + << " pb_trash_size: " << pb_trash_size << " (" << (pb_trash_size / 1024 / 1024) << "MB)" << endl + << " pb_pool_size: " << pb_pool_size << " (" << (pb_pool_size / 1024 / 1024) << "MB)" << endl + << " asyncwrite_size: " << asyncwrite_size << " (" << (asyncwrite_size / 1024 / 1024) << "MB)" << endl; + return(outStr.str()); + } private: u_int64_t max_buffer_mem; u_int64_t max_buffer_mem_own_use; diff --git a/manager.cpp b/manager.cpp index ee5189d0d..1275aec86 100644 --- a/manager.cpp +++ b/manager.cpp @@ -4859,7 +4859,8 @@ int Mgmt_packetbuffer_log(Mgmt_params *params) { } if(strstr(params->buf, "packetbuffer_log") != NULL) { extern PcapQueue_readFromFifo *pcapQueueQ; - string log = pcapQueueQ->debugBlockStoreTrash(); + extern cBuffersControl buffersControl; + string log = pcapQueueQ->debugBlockStoreTrash() + "\n" + buffersControl.debug(); return(params->sendString(log)); } else if(strstr(params->buf, "packetbuffer_save") != NULL) { char *nextParams = params->buf + strlen("packetbuffer_save"); diff --git a/pcap_queue.cpp b/pcap_queue.cpp index 10953364a..4a2e39bee 100644 --- a/pcap_queue.cpp +++ b/pcap_queue.cpp @@ -7265,12 +7265,14 @@ bool PcapQueue_readFromFifo::addBlockStoreToPcapStoreQueue(u_char *buffer, size_ string PcapQueue_readFromFifo::debugBlockStoreTrash() { ostringstream outStr; + size_t sum_size = 0; lock_blockStoreTrash(); for(unsigned i = 0; i < this->blockStoreTrash.size(); i++) { pcap_block_store *bs = this->blockStoreTrash[i]; outStr << "* " << hex << bs << dec << endl; outStr << "* " << sqlDateTimeString_us2ms(bs->timestampMS * 1000) << endl; outStr << "lock packets: " << (int)bs->_sync_packet_lock << endl; + outStr << "size: " << bs->getUseAllSize() << endl; #if DEBUG_SYNC_PCAP_BLOCK_STORE unsigned counter = 0; for(unsigned j = 0; j < bs->count; j++) { @@ -7294,8 +7296,11 @@ string PcapQueue_readFromFifo::debugBlockStoreTrash() { } #endif outStr << "---------" << endl; + sum_size += bs->getUseAllSize(); } unlock_blockStoreTrash(); + outStr << "SUM SIZE: " << sum_size + << " (" << (sum_size / 1024 / 1024) << "MB)" << endl; return(outStr.str()); } @@ -8084,7 +8089,10 @@ void *PcapQueue_readFromFifo::writeThreadFunction(void *arg, unsigned int arg2) } if(!(this->packetServerDirection != directionWrite && opt_ipaccount)) { - if(!(++this->cleanupBlockStoreTrash_counter % 10)) { + double heap_pb_trash_perc = buffersControl.getPerc_pb_trash(); + if(heap_pb_trash_perc > 20) { + this->cleanupBlockStoreTrash(); + } else if(!(++this->cleanupBlockStoreTrash_counter % 10)) { u_int64_t time_ms = getTimeMS_rdtsc(); if(!cleanupBlockStoreTrash_at_ms || (time_ms > cleanupBlockStoreTrash_at_ms && time_ms - cleanupBlockStoreTrash_at_ms > 1000)) {