Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sbt high cpu usage with ~run

It seems to me that SBT is taking an excessive amount of CPU time just watching for file changes. I'm aware of this post, but the author there was confounding the IDE cpu time with SBT cpu time; I don't have an IDE running.

I'm developing a Play project in Scala with about 370 scala files divided up into 5 modules.

Running sbt with ~run consumes about 70-90% CPU on my MacBook Pro (mid 2012). I don't have an IDE running, I'm not editing any files, no browser accessing the server... Just idling with ~run (and watching the file system) takes 70-90% of a CPU according to Activity Monitor.

After watching it idle for a while I fired up VisualVM; it shows itself and one other JVM process:

VisualVM overview

Details on the xsbt process (per VisualVM):

PID: 56661
Host: localhost
Main class: xsbt.boot.Boot
Arguments: -Dhttp.port=9001 -Dhttps.port=9443 -Djsse.enableSNIExtension=false -Dhazelcast.config=conf/hazelcast-dev.xml -Dlogger.file=conf/logback-dev.xml -Dconfig.file=conf/passwords/local-dev.conf

JVM: Java HotSpot(TM) 64-Bit Server VM (25.121-b13, mixed mode)
Java: version 1.8.0_121, vendor Oracle Corporation
Java Home: /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre
JVM Flags: <none>

Heap dump on OOME: disabled

JVM arguments:

-Xms1024m
-Xmx1024m
-XX:ReservedCodeCacheSize=128m
-XX:MaxMetaspaceSize=256m
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

Here's a bit more detail from VisualVM on where the time goes:

CPU sampling

Is 80% CPU usage -- and fans running most of the time -- reasonable while sbt is idling? Seems really high. Any strategies for bringing it down?

PS: When sbt is just at the command prompt (not watching for file changes) Activity Monitor shows about 5% CPU usage.

PPS: I normally have concurrentRestrictions in Global += Tags.limit(Tags.Test, 4) in my build file to prevent too many concurrent database connections during tests. I'm not sure if this actually does what I think it does. The stats, above, are with that line commented out. When I restore it Activity Monitor still reports ~80% CPU usage but in the CPU samples idleAwaitWork doesn't show up at all and ConcurrentRestrictions$$anon$4.take takes the top spot with SourceModificationWatch$.watch right behind it.

like image 587
bwbecker Avatar asked May 17 '17 13:05

bwbecker


People also ask

How to troubleshoot high CPU usage in SQL Server?

You can use the following steps to troubleshoot high-CPU-usage issues in SQL Server. Use one of the following tools to check whether the SQL Server process is actually contributing to high CPU usage: Task Manager: On the Process tab, check whether the CPU column value for SQL Server Windows NT-64 Bit is close to 100 percent.

How to fix high CPU usage in Windows 10?

How to Fix High CPU Usage. 1. Reboot. First step: save your work and restart your PC. “Turn it off and on again” is classic troubleshooting advice for a reason. This may resolve ... 2. End or Restart Processes. 3. Update Drivers. 4. Scan for Malware. 5. Power Options.

Is it normal to have high CPU usage while multitasking?

It’s important to remember that high CPU usage while multitasking can be normal. Modern CPUs handle multitasking situations by splitting processes between multiple processor cores, which work through different sets of instructions simultaneously.

Is it safe to run at 100% CPU utilization in games?

CPUs are designed to run safely at 100% CPU utilization. However, you’ll want to avoid these situations whenever they cause perceptible slowness in games. The steps above should teach you how to fix high CPU usage and hopefully solve the issues that have an outsize impact on your CPU usage and gameplay.


1 Answers

Assuming you're using sbt 1, this might be due to https://github.com/sbt/sbt/issues/3860 as pointed out by Waldemar Wosiński in comment.

Since we've adopted Close Watch, the problem should now be fixed. Please try sbt 1.1.6 or later and see if the problem still persists.

like image 135
Eugene Yokota Avatar answered Oct 12 '22 14:10

Eugene Yokota