Skip to content

Commit

Permalink
force heap cleanup if the size is greater than 20%
Browse files Browse the repository at this point in the history
extension of the output from the manager command packetbuffer_log:
 - block size
 - sum of block sizes
 - heap values
  • Loading branch information
rbucek committed Dec 6, 2023
1 parent 913bf86 commit 1fcc353
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
12 changes: 12 additions & 0 deletions buffers_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
10 changes: 9 additions & 1 deletion pcap_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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());
}

Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 1fcc353

Please sign in to comment.