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

Configurable job parallelism #29

Merged
merged 12 commits into from
Mar 23, 2016

Conversation

smashwilson
Copy link
Member

I'm introducing a runner configuration option, concurrentJobs, to allow multiple jobs to be scheduled in parallel.

@@ -297,7 +298,9 @@ Runner.prototype = {
// Keep around N most recent build directories.
// Default is 0, ie wipe at start of each run.
// Later, this can be configurable in the UI.
keeper({baseDir: path.join(this.config.dataDir, "data"), count: 0}, function(err) {
keeper({baseDir: path.join(this.config.dataDir, "data"), count: this.config.concurrentJobs - 1}, function(err) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized after I put this together that this is too simplistic; it assumes that, at most, the most recent n-1 data directories (possibly) belong to concurrent builds. If you have one long build and many short ones that happen before it completes, you can have many more data directories still in use.

I'll have to introduce a better way to track which data directories are in use and which are not.

@knownasilya
Copy link
Member

Good start

@niallo
Copy link
Member

niallo commented Mar 21, 2016

Good to see some work on this. The data dirs could be keyed by job ID or similar. Reaping them becomes a little tricky. Some folks may like to re-use build directories in some circumstances too (even though that's not always going to be safe). Just something to think about.

@knownasilya
Copy link
Member

I feel like concurrent jobs for the same project in the same branch don't make sense at the moment. Maybe that should be the limitation.

@smashwilson
Copy link
Member Author

I feel like concurrent jobs for the same project in the same branch don't make sense at the moment. Maybe that should be the limitation.

Hmm! That's going to be tricky to manage - an async.queue won't cut it any more, because more commits can arrive on a branch corresponding to an existing job even while the queue is unsaturated.

Concurrent builds on a single branch will be an issue if they trigger deployments, though.

The data dirs could be keyed by job ID or similar. Reaping them becomes a little tricky.

I had been thinking about maintaining an in-memory structure of data directories that are in-use and excluding them from the culling somehow. I think the runner can get away with something in memory because simple-runner jobs don't persist across service restarts anyway - otherwise I'd need to either parse the job ID from the data directory name or use some kind of flag file to identify active data directories.

Some folks may like to re-use build directories in some circumstances too (even though that's not always going to be safe). Just something to think about.

Re-using a data directory from one job to another? I'd thought that was what the cache was intended for. With the job ID in the data directory name, how does that work - or am I misunderstanding?

@knownasilya
Copy link
Member

So there are two concepts, the cache and the data dir (as far as I know) and the cache is used by certain plugins but the data dir is where the project is cloned into and built. Personally I always copy the contents from the data dir to /var/www/<project name> when using strider locally.

@smashwilson
Copy link
Member Author

Okay, I've revisited this to:

  • Use a custom JobQueue. It's an async queue that prevents the concurrent scheduling of tasks that share a key, namely a (project, branch) tuple. Otherwise, it runs parallel jobs up to a defined concurrency limit.
  • Prune recent data directories specific to each project and branch rather than globally. (This should also be helpful for For jobs data directory keeper is not branch aware and count is not configurable on ui #28.) Because jobs on the same branch don't run concurrently, this'll prevent Strider from deleting a build directory that's in use by a concurrent job.

Here's what the data directory structure looks like:

~/code/strider-simple-runner (parallel-jobs=) 
$ find /Users/ashl6947/.strider/data -type d -maxdepth 2
/Users/ashl6947/.strider/data
/Users/ashl6947/.strider/data/deconst-deconst-control-master
/Users/ashl6947/.strider/data/deconst-deconst-control-master/job-56f29d31a141bc8723e5bf9a
/Users/ashl6947/.strider/data/deconst-deconst-docs-control-master
/Users/ashl6947/.strider/data/deconst-deconst-docs-control-master/job-56f29d30a141bc8723e5bf98
/Users/ashl6947/.strider/data/deconst-deconst-docs-master
/Users/ashl6947/.strider/data/deconst-deconst-docs-master/job-56f29d2fa141bc8723e5bf97
/Users/ashl6947/.strider/data/deconst-deploy-master
/Users/ashl6947/.strider/data/deconst-deploy-master/job-56f29d30a141bc8723e5bf99

I've also tried to be careful in extracting branch names from the job in a sane way because Job's ref field can hold arbitrary things. I'm testing for a few common keys (branch, fetch) but falling back to an ugly-but-safe "URI-encoded stable JSON representation of the whole thing".

@knownasilya
Copy link
Member

Do you think this is ready for merge? Did you have any plans to write some basic tests for this JobQueue?

@smashwilson smashwilson changed the title [wip] Configurable job parallelism Configurable job parallelism Mar 23, 2016
@knownasilya
Copy link
Member

Nvm, you have tests.

@smashwilson
Copy link
Member Author

I was just giving it a last look-over to see if there was anything obvious I'd missed. I don't think so 😄

@knownasilya knownasilya merged commit 01d2d15 into Strider-CD:master Mar 23, 2016
@knownasilya
Copy link
Member

So it's probably a good idea to expose the configuration in Strider UI.

@smashwilson
Copy link
Member Author

Yeah, agreed. The number of recent directories to keep should be simple enough to add. The level of concurrency is less clear to me.

Is there a place for installation-wide (rather than build-specific) configuration for runner plugins?

@smashwilson smashwilson deleted the parallel-jobs branch March 23, 2016 14:25
knownasilya pushed a commit that referenced this pull request Mar 23, 2016
- Concurrent Jobs #29
@knownasilya
Copy link
Member

Hum, no but Strider-CD/strider#681 would help when I get more time to finish it.

@knownasilya
Copy link
Member

How is it configured now, an env var? Need to document in the mean time.

@smashwilson
Copy link
Member Author

Yeah, CONCURRENT_JOBS.

@smashwilson
Copy link
Member Author

It's a little generic, but I wasn't sure how far to go down the STRIDER_SIMPLE_RUNNER_... prefixing road. I can patch it if there's a pattern I wasn't following.

@knownasilya
Copy link
Member

No, this is good. I documented it in the strider repo and updated the version of simple-runner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants