Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance of start/stop/remove container #215

Closed
forfcw opened this issue Sep 24, 2021 · 2 comments
Closed

Performance of start/stop/remove container #215

forfcw opened this issue Sep 24, 2021 · 2 comments
Assignees
Labels
answer The question/bug has been answered/workaround recipe
Milestone

Comments

@forfcw
Copy link

forfcw commented Sep 24, 2021

Have you got some performance problems with start/stop/remove containers?

var hosts = new Hosts().Discover();
var host = hosts.FirstOrDefault(x => x.IsNative) ?? hosts.FirstOrDefault(x => x.Name == "default");
var _container = host.Create("nginx:alpine",
    prms: new ContainerCreateParams
    {
        Name = "test",
        Network = "host",
        PortMappings = new string[] { "9111:80", "9112:443" },
        Volumes = new string[] { "/data/log:/var/log:rw" },
        RestartPolicy = RestartPolicy.Always
    });
_container.Start();

It usually takes 4s or more to start a container, sometimes finding and deleting a container even takes 6s.

[root@root:~]# dotnet test.dll 
start: 5.230721
stop: 1.2377657
remove:1.7702362

Looking forward to your recovery!

@mariotoffia
Copy link
Owner

mariotoffia commented Sep 24, 2021

Hi @forfcw and thanks for reporting this issue. I've done a simple test to try to replicate what you see.

In my case, I have a really weak hp dragonfly laptop with an "Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz, 1992 Mhz, 4 Core(s)" with probably not the fastest ram in the world ;)

I'm using WSL2.

Using the following sample (I will check it in this into Examples Solution later on)

        Stopwatch stopwatch = new Stopwatch();
        
        stopwatch.Start();
        var hosts = new Hosts().Discover();
        var host = hosts.FirstOrDefault(x => x.IsNative) ?? hosts.FirstOrDefault(x => x.Name == "default");

        Console.WriteLine("Hosts discovered in {0} s", TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds).TotalSeconds);

        var _container = host.Create("nginx:alpine",
            prms: new ContainerCreateParams
            {
                Name = "test",
                Network = "host",
                PortMappings = new string[] { "9111:80", "9112:443" },
                Volumes = new string[] { "/data/log:/var/log:rw" },
                RestartPolicy = RestartPolicy.Always
            });
        
        Console.WriteLine("Create container: " + TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds).TotalSeconds);
        
        try
        {
            stopwatch.Restart();
            _container.Start();

            Console.WriteLine("Start container: " + TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds).TotalSeconds);
        } finally
        {

            stopwatch.Restart();
            _container.Dispose();
            Console.WriteLine("Dispose container: " + TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds).TotalSeconds);

            stopwatch.Stop();

        }

It will output the following:

Hosts discovered in 0.083 s
Create container: 1.51 s
Start container: 0.56 s
Dispose container: 0.353 s

When I try to do it on my shell, the creation will take around one to two seconds so I think FluentDocker, in this case, do not add any substantial additional time.

I will investigate this a bit further, but in the meantime can you please use the docker commands from the shell and clock how long an "nginx:alpine" takes to start and be deleted on your system?

💡 Note that it will call both stop and remove when disposing the container.

docker -H unix:///var/run/docker.sock start 37ec8c07e093b452b3a18346b4338dd7bdb33d203582b1bd8d0035f888f2921a
docker -H unix:///var/run/docker.sock inspect 37ec8c07e093b452b3a18346b4338dd7bdb33d203582b1bd8d0035f888f2921a

docker -H unix:///var/run/docker.sock stop 37ec8c07e093b452b3a18346b4338dd7bdb33d203582b1bd8d0035f888f2921a
docker -H unix:///var/run/docker.sock rm --force 37ec8c07e093b452b3a18346b4338dd7bdb33d203582b1bd8d0035f888f2921a

Cheers,
Mario

@mariotoffia mariotoffia self-assigned this Sep 24, 2021
@mariotoffia mariotoffia added under-investigation A investigation is made around the issue waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further. labels Sep 24, 2021
@mariotoffia mariotoffia added this to the 3.0.0-RELEASE milestone Sep 24, 2021
@forfcw
Copy link
Author

forfcw commented Sep 26, 2021

May be I wronged FULENTDOCKER, It takes the same time in shell!

@forfcw forfcw closed this as completed Sep 26, 2021
@mariotoffia mariotoffia added answer The question/bug has been answered/workaround recipe and removed waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further. under-investigation A investigation is made around the issue labels Sep 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answer The question/bug has been answered/workaround recipe
Projects
None yet
Development

No branches or pull requests

2 participants