I would like to control the number of threads that sbt uses when running in parallel. One reason is that a lot of my tests are calling rest api's which means they are waiting most of the time, so if I increase the threads above the number of cpu's, the tests should run faster.
I've seen a lot of configurations that claim to do this, i.e.
concurrentRestrictions in Test := Tags.limit(Tags.CPU,16) :: Nil
But nothing seems to make any difference. Using sbt 1.4.3
The correct setting is
concurrentRestrictions in ThisBuild := Tags.limit(Tags.Test, 16 ) :: Nil
The CPU
tag only limits compile
by default. Please refer to these docs for more details.
The tasks that are currently tagged by default are:
compile : Compile, CPU
test : Test
update : Update, Network
publish, publishLocal : Publish, Network
Thanks, what does this limit to 16? The CPU only?
Thanks once again. I run some tests but it doesn't seem to make any difference. I have a multi module project and added this to the settings of each project. ` lazy val x = project ... .settings( concurrentRestrictions := Tags.limit(Tags.Test, 16) :: Nil )`
So I added ` Thread.sleep(5000) ; println(Thread.currentThread()) ` to a few of my tests and even with Tags.limit(Tags.Test,1) , they print a different thread, so they run on more than 1 thread.
Made a simple project/testcase and indeed the above doesn't seem to work. My test project has 2 ScalaTest suites, TestASuite and TestBSuite. Both have 2 tests each (total 4 tests) that have a Thread.sleep(5000). If I set Tags.limit(Tags.Test, 1 ) or Tags.limit(Tags.Test, 16 ), the tests take 10 secs to complete so the value 1 is ignored. If it was 1 shouldn't the tests effectively run single threaded which means it would take 20 secs? Also the tests print the thread the run and they run in 2 threads.
this works : concurrentRestrictions in Global := Tags.limit(Tags.Test, 16) :: Nil . But how do I restrict it to Test runs only?