Code Monkey home page Code Monkey logo

Comments (6)

seirl avatar seirl commented on July 23, 2024

I tried both of those on two different machines (archlinux and ubuntu 16.10 x86_64) multiple times and I can't reproduce your result at all. Do you get similar differences in user time? Can you compute the average wall time of 1000 runs, for instance?

from isolate.

johnchen902 avatar johnchen902 commented on July 23, 2024

User time is always 0.00. Wall time average is computed with this script, isolate.sh:

sumt1=0
sumt2=0
for ((i=1; i<=$ITERATIONS; i++)); do
    isolate --init >/dev/null
    /usr/bin/time -f %e -o /tmp/time1 isolate --run -- /usr/bin/echo 1 >/dev/null 2>/dev/null
    isolate --cleanup >/dev/null
    isolate --init >/dev/null
    /usr/bin/time -f %e -o /tmp/time2 isolate --run -- /usr/bin/echo 2 >/dev/null 2>/dev/null
    isolate --cleanup >/dev/null
    sumt1=$(echo $sumt1 + $(cat /tmp/time1) | bc)
    sumt2=$(echo $sumt2 + $(cat /tmp/time2) | bc)
    sleep $SLEEPTIME
done
echo sumt1 = $sumt1, sumt2 = $sumt2

On the first machine:

$ sudo env ITERATIONS=1000 SLEEPTIME=0.1 bash isolate.sh
sumt1 = 43.54, sumt2 = 99.61

On the second machine:

johnchen902@johnchen902 ~> sudo env ITERATIONS=100 SLEEPTIME=1 bash isolate.sh 
sumt1 = 4.34, sumt2 = 84.86

from isolate.

johnchen902 avatar johnchen902 commented on July 23, 2024

Seems like kernel just spent that much time tearing down namespaces before the child can be reaped, as demostrated by timing the following code and toggling the comments.

#define _GNU_SOURCE
#include <fcntl.h>
#include <sched.h>
#include <signal.h>
#include <sys/wait.h>
#include <unistd.h>
#define CHILD_STACK_SIZE (1 << 23)
static int fd[2];
static int child_main(void *param) { (void) param;
    // close(fd[1]);
    // execl("/usr/bin/true", "/usr/bin/true", NULL);
    return 0;
}
int main() {
    static int child_stack[CHILD_STACK_SIZE];
    int flags = SIGCHLD | CLONE_NEWCGROUP | CLONE_NEWIPC | CLONE_NEWNET
            | CLONE_NEWNS | CLONE_NEWPID | CLONE_NEWUTS ;
    pipe2(fd, O_CLOEXEC);
    clone(child_main, child_stack + CHILD_STACK_SIZE, flags, NULL);
    close(fd[1]);
    // char buf[1]; read(fd[0], buf, 1);
    // wait(NULL);
}

A special "init" program in the namespace may serve as a workaround, because we need not to wait for the init to die.

from isolate.

gollux avatar gollux commented on July 23, 2024

This is definitely a kernel issue. I do not think it matters much as average execution times in most contests are significantly higher than this delay, but if anybody feels it does matter, please reopen this issue and we shall investigate further.

from isolate.

johnchen902 avatar johnchen902 commented on July 23, 2024

When I opened this issue, it did matter because I want to run 20 tasks concurrently on the 0.8s machine (with >20 cores), and it is observed that such overhead cannot be parallelized.

Later I decided to roll my solution, which avoids destroying and recreating namespaces. As I no longer use isolate at all, it doesn't matter to me now.

from isolate.

bblackham avatar bblackham commented on July 23, 2024

See further discussion and proposed workaround in issue #34.

from isolate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.