4

I have a production server that is showing a very large number of forks when running vmstat -f. Any suggestions on steps that could be used to help find out what the origin of the forks are?

vmstat -f 1
      6650796 forks

EDIT:

[~]$ ./forks.sh 
Forks in last 2 seconds: 20 
Forks in last 2 seconds: 40 
Forks in last 2 seconds: 58 
Forks in last 2 seconds: 9 
Forks in last 2 seconds: 6 
Forks in last 2 seconds: 28 
Forks in last 2 seconds: 8 
Forks in last 2 seconds: 10 
Forks in last 2 seconds: 15 
Forks in last 2 seconds: 9

5 Answers5

5

According to the man page, it includes all calls to fork, vfork or clone. The last one of these three (clone) is used by Java to implement its threads

So each time your Java server creates a new thread, that value increments.

Providing it doesn't go silly, it should be fine. How many per second do you see on average?

MarkR
  • 2,928
1

Any process that spawns another process without itself terminating is a fork - for example, every command that's executed at a shell will be counted as a fork. An very high number of fork calls since the system booted is totally normal.

Luke
  • 628
1

The first thing to note is that running vmstat with out its two time arguments show the accumulated value since last reboot. You'd have to run it multiple times to get a "forks per second" number to see if it's really a big number or not. Something like this (which could obviously be made into a much friendlier script):

g3 0 /home/jj33 ># while true
> do
>   vmstat -f
>   sleep 15
> done
       278039 forks
       278044 forks
       278047 forks
       278051 forks

So, that system did 5, 3, and 4 forks in 3 15 second intervals, which, given that every process call on a *nix box involves a fork, doesn't seem like a big number.

jj33
  • 11,388
0

A high fork count really isn't a problem - I've been running a Gentoo-based router for several months now, and my fork count is over twice yours, but the machine itself is rock-solid.

dijkstra ~ # vmstat -f 1
     14623947 forks
dijkstra ~ # uptime
 15:29:26 up 291 days, 14:02,  1 user,  load average: 0.02, 0.04, 0.07
Tim
  • 1,158
0

If you suspect a certain process (like JVM) to be the reason for the high fork count (2/s is not high and not a problem) you can use strace/ltrace to see what it is doing.

Specifically fork should also be visible in process accounting (higher impact) with the accton command. But I dont think it covers clone() for starting threads.

If you get into the range of 100 clones/s then you should really have a look at the applicaton.

BTW: regarding the comment above (cant comment on it yet): no Tomcat does not fork, it only starts threads, but not for each request, it uses a pool.

eckes
  • 865