Skip to content

Commit 12a8778

Browse files
committed
manualyy trigger the garbage collection to see if it flatens the linear time the profiler takes to process flows
1 parent 358da92 commit 12a8778

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

slips_files/core/profiler_worker.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ipaddress import IPv4Network, IPv6Network, IPv4Address, IPv6Address
1818
import netifaces
1919
import validators
20+
import gc
2021

2122

2223
from slips_files.common.printer import Printer
@@ -665,6 +666,9 @@ def log_time(self, what, time):
665666
self.times = {}
666667

667668
def main(self):
669+
# Disable automatic GC, we'll trigger it manually
670+
gc.disable()
671+
668672
while not self.should_stop_profiler_workers():
669673
try:
670674
msg = self.get_msg_from_queue(self.flows_to_process_q)
@@ -677,8 +681,6 @@ def main(self):
677681
if line is True:
678682
continue
679683

680-
# Received new input data
681-
self.print(f"< Received Line: {line}", 2, 0)
682684
self.received_lines += 1
683685

684686
n = time.time()
@@ -697,6 +699,12 @@ def main(self):
697699

698700
self.handle_setting_local_net(flow)
699701
self.db.increment_processed_flows()
702+
703+
# manually run garbage collection to avoid the latency
704+
# introduced by it when slips is given a huge number of flows
705+
if self.received_lines % 10000 == 0:
706+
gc.collect()
707+
700708
except Exception as e:
701709
self.print(
702710
f"Problem processing line {line}. "
@@ -709,4 +717,5 @@ def main(self):
709717
# so the modules receive no more flows.
710718
# modules should just finish the flows they have and slips will
711719
# exit gracefully
720+
gc.enable()
712721
continue

0 commit comments

Comments
 (0)