4

The responsiveness is really bad on a newly installed Ubuntu 14.04 LTS.

Here's the specs of my laptop:

Quadcore Intel i7-4600U CPU @ 2.10GHz
12GB Ram
1TB Samsung EVO SSD

And when gradle is compiling, my entire system slows to a crawl, videos begin stuttering, browser scrolling lags... etc.

The same goes when a page refresh occurs in another window in Chrome, and while it refreshes, the HTML5 video in another tab begins stuttering.

How can I fix this?

Here are some logs:

$ vmstat -a 1 5 - http://paste.ubuntu.com/7493966/

$ iostat -x 1 5 - http://paste.ubuntu.com/7493970/

$ top -b - http://paste.ubuntu.com/7493974/

c0rp
  • 9,820
  • 3
  • 38
  • 60
nubela
  • 227
  • What video card do you have? Could also be wireless. You could also try k/x/lubuntu. – Panther May 20 '14 at 16:32
  • It's the integrated intel HD4400 card. is it really the desktop environment? because it seems more like a cpu scheduler issue. my macbook air is so much slower but i have way better application responsiveness on it. – nubela May 20 '14 at 16:39
  • On my (older) intel card I find both KDE and XFCE are more responsive., you can boot a live usb and try it. – Panther May 20 '14 at 16:41
  • Could you provide some logs while lagging occure. Put it on paste.ubuntu. top -b -n 2, iostat -x 1 5, vmstat -a 1 5 – c0rp May 20 '14 at 17:11
  • hi @c0rp, added the logs as you requested. – nubela May 20 '14 at 17:46
  • It seems that you have a java thing which is trying to use all CPUs for itself... (I do not know which gradle is, so I may just be pointing the obvious). – Rmano May 20 '14 at 18:12
  • I don't see anything strange. As iostat says, 95% of your CPU is working. Also if summarize first 20 apps in top it gives 392% (because you have 4 CPUs). vmstat says that a few processes are waiting. Your java project eating your CPU – c0rp May 20 '14 at 18:19
  • Could you provide your gradle version – c0rp May 20 '14 at 18:31
  • i'm using gradle 1.10. But even if it eats up all the cpu, shouldn't the scheduler attempt to mitigate the resources appropriately? – nubela May 20 '14 at 20:01
  • in other words, how can i configure my install to give less to distribute resources more fairly? – nubela May 20 '14 at 20:03
  • @nubela This is the common problem of gradle. It trying to use all CPU cores. At least you can try to reduce niceness of IDE process while building. Also if you want let me know that you write comment add "@c0rp" to your text – c0rp May 21 '14 at 18:12
  • @c0rp, i'd love to accept your answer, but before i do that, i'd like to know something more general. if it is possible for the scheduler to be more fair, such that ever if there is a process that is super greedy, it will not starve the other processes (particularly the desktop environ) of necessary resources.

    is it possible?

    – nubela May 22 '14 at 06:20
  • @nubela I think this would be a great question, but this is another question. You can edit current question and I will update my answer. – c0rp May 22 '14 at 06:32
  • @c0rp, i will accept this answer just to let you have the karma for this question. cheers and thanks1 – nubela May 22 '14 at 18:15
  • @nubela, I update answer a little bit. It is not necessary to accept my answer, I'm doing this because it is also interesting for me. If you find any other solution, please let me know, or answer your question by yourself. I have the same problem with vaadin – c0rp May 23 '14 at 05:19

1 Answers1

4

I do not work with gradle. But as I understand it is common problem.

Here is a links:

Very helpful topic

CPU utilization problem

Gradle performance

Google

What you can do is change process scheduling. For process that runs IDE or gradle.

nice

nice is a program found on Unix and Unix-like operating systems such as Linux. It directly maps to a kernel call of the same name. nice is used to invoke a utility or shell script with a particular priority, thus giving the process more or less CPU time than other processes. A niceness of −20 is the highest priority and 19 or 20 is the lowest priority. The default niceness for processes is inherited from its parent process, usually 0.

To change niceness you can use renice command

sudo renice <PID> <niceness> 

Read this for more information

For building time you can set niceness for 15-20. After build change it to default value, usually it is 0.

cpulimit

Install cpulimit. sudo apt-get install cpulimit

-p : Process PID.
-e : Process name.
-l : percentage of CPU allowed from 0 to 100.
-P: absolute path name of the executable program file.

To limit CPU usage of the process called firefox to 30%, enter:

# cpulimit -e firefox -l 30

To limit CPU usage of the process to 30% by using its PID, enter:

# cpulimit -p 1313 -l 30

cpulimit should run at least with the same user running the controlled process. But it is much better if you run cpulimit as root, in order to have a higher priority and a more precise control.

If your machine has one processor you can limit the percentage from 0% to 100%, which means that if you set for example 50%, your process cannot use more than 500 ms of cpu time for each second. But if your machine has four processors, percentage may vary from 0% to 400%, so setting the limit to 200% means to use no more than half of the available power. In any case, the percentage is the same of what you see when you run top.

Cpulimit usage

How to limit CPU usage

chrt

You also can change process scheduler or PID.

SCHED_FIFO
Scheduling policy designed for special time-critical applications. It uses the First In-First Out scheduling algorithm.

SCHED_BATCH
Scheduling policy designed for CPU-intensive tasks.

SCHED_IDLE
Scheduling policy intended for very low prioritized tasks.

SCHED_OTHER
Default Linux time-sharing scheduling policy used by the majority of processes.

SCHED_RR
Similar to SCHED_FIFO, but uses the Round Robin scheduling algorithm.

Most if process in Ubuntu are SCHED_OTHER

Find priority values for scheduling policy

$ chrt -m
SCHED_OTHER min/max priority    : 0/0
SCHED_FIFO min/max priority : 1/99
SCHED_RR min/max priority   : 1/99
SCHED_BATCH min/max priority    : 0/0
SCHED_IDLE min/max priority : 0/0

Set SCHED_IDLE to process

$ chrt -i -p 0 PID

or you can change priority SCHED_OTHER

$ chrt -o -p 1 PID

Howto

Another way

Also you can try to reduce number of Thread for gradle. You can read about it here. As I see it has this options:

./gradlew -PtaskThreads=2

Also you can try reduce memory usage:

GRADLE_OPTS=-Mmx512m

Quote from Very helpful topic

--parallel-threads only applies to project parallelization.

For android tasks that are running in parallel, we always create as many threads as possible. For slower machine (or with low ram) this is not great. We should allow control on that.

Possible though:
./gradlew assemble -PandroidThread=3

Studio would have to allow configuring and sending this (it should also let you configure --parallel-threads if it doesn't already).

Long term gradle will have a thread pool shared across all level of parallelization (multi-projects. inside a project, inside a task) so this will become obsolete but it would be good to do now.
c0rp
  • 9,820
  • 3
  • 38
  • 60