Files
fork_vs_thread/README.md
T

66 lines
1.6 KiB
Markdown

# Fork vs Threads Experiments
This project compares Linux process creation (fork) versus thread creation (pthreads).
It includes timing, scaling, and stress tests to show performance differences and
system limits.
## How to run
Run all experiments (safe by default):
```sh
bash run_all_experiments.sh
```
Run individual experiments (examples):
```sh
bash creation_time_experiment/bash_test_iter.sh
bash thread_recursive_scaling/run_thread_recursive.sh
```
Enable the dangerous stress test (timeboxed):
```sh
ALLOW_DANGEROUS=1 FORK_BOMB_SECONDS=5 bash run_all_experiments.sh
```
## Key Commands for lifting linux kernel restrictions on alpine linux for threads & processes:
```
# Lift shell nproc limit
ulimit -u unlimited
# Raise kernel PID/thread caps (temporary until reboot)
sysctl -w kernel.pid_max=131072
sysctl -w kernel.threads-max=131072
# cgroup v2 setup (Alpine Linux)
mkdir -p /sys/fs/cgroup/test
echo max > /sys/fs/cgroup/test/pids.max
echo $$ > /sys/fs/cgroup/test/cgroup.procs
```
## Clean-up commands run after tests:
```
# Cleanup to make it non-persistent (move out, then delete)
echo $$ > /sys/fs/cgroup/cgroup.procs
rmdir /sys/fs/cgroup/test
```
## Potential dangers
- The fork bomb can freeze your machine or make it unresponsive by exhausting
processes/threads.
- You may need elevated limits (ulimit or sysctl) to run high-stress tests.
- Running heavy tests on shared systems or laptops can disrupt other users and
risk data loss if the system becomes unstable.
If you are unsure, do not enable the dangerous tests.
It is very important to run above test in virtual machine to avoid some of the potential dangers
#