1. b.93z.org
  2. Notes

PLT building and too high CPU usage

Dialyzer is a static analysis tool for Erlang. It can store results of such analysis in PLT (persistent lookup table) files, and use them as a starting point for subsequent analysis.

That is, developer generates global PLT file for Erlang/OTP’s and some common used applications (for instance, MochiWeb and Cowboy), and then uses it to analyse his projects’s code.

Such PLT generation fully utilises all available cores of CPU, making impossible any significant use of computer, and in some cases causing CPU overheat—laptops, for example, just shut down.

So, how to make Dialyzer use no more than, say, 30% of CPU? nice wouldn’t work here, as overheat still may be a problem (it just sets process’ niceness). There is utility (cpulimit) that limits real CPU usage via sending SIGSTOP and SIGCONT to process.

PLT generation with dialyzer, limited by cpulimit, will look like this:

$ dialyzer --build_plt --apps kernel erts stdlib crypto other apps here &
$ cpulimit --pid=$! --limit=30

There are many different approaches to getting process’ PID that use different utilities, but, in my opinion, this one (start process in foreground and use $! to get PID) is simplest and requires no external utilities (such as pidof; by the way, cpulimit supports limiting by executable name). Note that development version can lauch process by itself (thus no need to tell it about process’ PID or executable).

© 2008–2017 93z.org