dreadedmonkeygod . net

Ant: Parallel Execution

I've been playing some more with Ant. I'm using it to regulate a process that sucks data out of a source database, slices and dices it, then stuffs it into a destination database.

The whole process takes something like 3 hours to complete, and I'm trying to speed things up. I noticed that it was spending a lot of time waiting for I/O, and thought using Ant's parallel task might help things.

Except, parallel doesn't behave as I thought.

Take this, for example:

<project name="DemonstrateParallel" default="all">

  <target name="all">
    <parallel>
      <antcall target="foo" />
      <antcall target="bar" />
      <antcall target="baz" />
    </parallel>
  </target>

  <target name="foo" depends="bar">
    <echo message="FOO" />
  </target>

  <target name="bar" depends="baz">
    <echo message="BAR" />
  </target>

  <target name="baz">
    <echo message="BAZ" />
  </target>

</project>

Now, I thought that all the dependencies would kick in, and we'd see each target get executed once. Foo would wait for bar, bar would wait for baz. Not so. Here's the actual output:

all:

baz:

baz:

baz:
     [echo] BAZ
     [echo] BAZ
     [echo] BAZ

bar:
     [echo] BAR

bar:
     [echo] BAR

foo:
     [echo] FOO

BUILD SUCCESSFUL
Total time: 0 seconds

Yep. Each "parallel" thread has its own dependency tracking. Ick.

I'm fine with this definition of parallel. However, this seems to leave an important hole in Ant's expressive power. There's no way to tell it to plough through a set of tasks, parallelizing where possible. If you want that effect, you basically have to do all the dependency tracking manually, which defeats the point of using Ant, and you lose a lot of flexibility, which defeats the point of running tasks in parallel.

So, I'm tempted to spend some time contributing to the implementation of Ant's parallel tag. I'd add the shareDependencies attribute. Set to yes/true, it would let tasks running within that parallel context share dependencies. If two tasks had a common dependency, they'd wait for that dependency to be satisfied, then they'd both continue. None of the multiple execution nonesense above.

Post a Comment

Name:
Email (Never, ever displayed.)
URL:
Remember me next time.
Comments (Sorry, no HTML allowed. Space paragraphs with a blank line.):