:: Re: [DNG] systemd in wheezy, was: R…
Pàgina inicial
Delete this message
Reply to this message
Autor: Isaac Dunham
Data:  
A: Steve Litt
CC: dng
Assumpte: Re: [DNG] systemd in wheezy, was: Re: bummer
On Thu, Jul 09, 2015 at 01:36:23PM -0400, Steve Litt wrote:
> By the way, I have no personal knowledge of how many actor sockets a
> listener socket can spawn off, but if I had to guess, I'd imagine 50
> would be way too low a number, if for no other reason than none of my
> current and former ISPs would have been able to serve httpd to the
> masses if 50 was the limit.
>
> Hmmm, as far as just plain processes, maybe I'll make a fork bomb and
> see how many there are before the system bogs down. That should be
> interesting.


Here's a trivial forkbomb-ish program that I've used for some experiments.
(So as to recover safely, when fork() finally fails it will sleep briefly
and exit.)
It's probably not representative of even a trivial server, but on my
1GB N270 netbook running Alpine Linux, with ~100 programs running
(ls -d /proc/[0-9]*|wc -l = 103), it reports 7880 forks.

Thanks,
Isaac Dunham
/* Written by Isaac Dunham in the year of our Lord 2015
* No rights reserved, all warranties disclaimed.
* (You can do whatever you want, but entirely at your own risk.)
*
* A small forkbomb-ish test program intended to test how many trivial
* socket-using programs can run on a processor (and their effects on
* the scheduler).
* It gets a pair of connected sockets and repeatedly forks, with
* the main process reading from the socket and the children
* writing to it.
* On resource exhaustion, all processes will sleep for 20 seconds
* and exit, allowing you to briefly observe practical effects
* before the system recovers.
*
* Compile with -DUSLEEP if you would rather see effects of a *lot* of
* syscalls. (For example, what does the scheduler do?)
*/

#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <unistd.h>


int main(int argc, char *argv)
{
    pid_t pid;
    int count, sv[2];
    char got;


    if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv))
        return 32;


    while ((pid = fork()) > 0) {
        count += (read(sv[1], &got, 1) > 0 )? 1: 0 ;
        printf("pid: %lld forks: %d\n", (long long)pid, count);
    }
    if (!pid) {
        write(sv[0], "a", 1);
    }
#ifdef USLEEP
    count = 0;
    while (count < 20000) {
        usleep(1000);
        count ++;
    }
#else
    sleep(20);
#endif
    return 0;
}