int128 / gradle-ssh-plugin

Gradle SSH Plugin
https://gradle-ssh-plugin.github.io
Apache License 2.0
318 stars 60 forks source link

Parallel execution of ssh commands on multiple hosts #274

Closed matthiasbalke closed 7 years ago

matthiasbalke commented 7 years ago

We do our server deployment with the gradle-ssh-plugin. It is running perfectly fine, but we wan't to speed it up by executing some commands in parallel on multiple hosts.

Is it possible? Down below is an example on how I imagine to use it.

today

ssh.run {
        session(remotes.allRoles('tomcat', stage)) {
            execute "echo 'starting deployment ...'"
            execute "${sudo_prefix} deploy.sh"
        }
    }

parallel

ssh.run {
        parallelSession(remotes.allRoles('tomcat', stage)) {
            execute "echo 'starting deployment ...'"
            execute "${sudo_prefix} deploy.sh"
        }
    }
int128 commented 7 years ago

Use executeBackground to run commands in parallel.

    ssh.run {
        session(remotes.allRoles('tomcat', stage)) {
            executeBackground "echo 'starting deployment ...'"
            executeBackground "${sudo_prefix} deploy.sh"
        }
    }

I think this behavior is confusing and parallelSession is intuitive. It will be improved in the next major release.

matthiasbalke commented 7 years ago

Awesome, I didn't know about executeBackground, I will try it.

matthiasbalke commented 7 years ago

After testing executeBackground I realized that it is not doing what I intended to do.

I wanted to execute a serial block, parallel on multiple hosts. As far as I understand, I cannot configure this using executeBackground.

int128 commented 7 years ago

At this moment session blocks are executed in serial because parallel execution needs complex implementation on Java 6.

In the release 2.7.0, Java 6 support will be removed and session blocks will be executed in parallel using ForkJoinPool.

matthiasbalke commented 7 years ago

@int128 Today I tested the parallel execution with 2.7.0. It seems to work, but I'm wondering why I do not get the expected performance boost. I will figure it out for my concrete problem. From my side everything I needed was released with 2.7.0 and this issue can be closed.