chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How does process-fork affect mailbox and threads


From: Claude Marinier
Subject: How does process-fork affect mailbox and threads
Date: Thu, 22 Sep 2022 21:06:39 -0400

Allô,

I am considering a different approach for an old project which collects IP traffic addresses and counters. The old approach has serious flaws: the PCAP handler calls Scheme to process each packet without buffering and it forks at regular intervals to write statistics.

In practice, the old approach consumed a lot of CPU time; it should be unobtrusive. I am simplifying the data structures to avoid unnecessary memory allocation and GC. The approach is not neat or tidy.

Using the mailbox egg should provide buffering; a thread can loop on mailbox-receive! and accumulate the counts. On exit, the main can send a message to the mailbox to stop the thread cleanly; the remaining data can then be saved. 

I have never used threads; this is intimidating. Here are some questions.

1) The SRFI-18 egg has not reached version 1. Which threading egg do you recommend for my simple case?

2) After calling process-fork, will the child still have an open PCAP handle? Will the thread still be running? If the thread is running, the child process could immediately ask it to stop and clean-up. If the thread is dead, it could be messy. The child can wait for the thread to stop, right? The PCAP loop will not be running when the main forks.

3) The parent will need to reset the hash tables. Which is cleaner hash-table-clear! or make-hash-table to start fresh (and let GC cleanup the old one)? Which has less impact on performance?

I am willing to read and experiment. I need to know where to start.

Merci.

P. S. I have asked many questions about other aspects of this before (years ago) and the responses were excellent. Thank you.

--
Claude Marinier

reply via email to

[Prev in Thread] Current Thread [Next in Thread]