Friday, October 3, 2014

How to Speedup Linux Boot Process using Startpar Command Examples

In a typical scenario, during the boot process, the run-level system startup scripts are executed one-by-one.
A particular run level startup script will not execute until the previous script is executed completely. If a particular service during the startup is hanging for some reason, it might take a while before it times-out and move on to the next startup script.
Startpar utility is used to run multiple run-level scripts in parallel. This helps to speed up the boot process of your server.

Startpar utility is part of sysvinit package.
The general syntax for the startpar is given below:
startpar –p par –i iorate –t timeout –T global timeout –a arg prg1 prg2

startpar –p par –I iorate –t timeout –T global timeout –M boot|start|stop
The following are the various options of startpar:
  • -p Number of process to run in parallel.
  • -i Change the process block weighing factor. The default is 800.
  • -t Timeout to empty the buffer of a script if no output has occurred.
  • -T Global timeout. It is used to flush the buffer output of previous scripts .
  • -a Arguments to be provided to all scripts.
  • -M Switch startpar to the “make” mode.
  • -P Specify previous run-level
  • -N Specify next run-level
When startpar is executing the run-level scripts, the output of the scripts is buffered to allow for controlled writing to logging facilities.
If other scripts are running in parallel, then it waits for the logging to be completed and then it writes the data from buffer to the logging area. The –t and –T options are used to control the clearing of these buffers depending on the time since the last output that is captured to buffer.
On my system, I have the following version fo startpar:
# startpar -v
startpar version 0.54
Startpar command can be used in a “make” mode using –M option. In this mode, startpar uses the following files to decide how to execute the startup scripts.
/etc/init.d/.depend.start
/etc/init.d/.depend.stop
/etc/init.d/.depend.boot
Here’s an example of .depend.start file:
# cat /etc/init.d/.depend.start
TARGETS = halt fbset lvm_wait_merge_snapshot microcode.ctl earlysyslog dbus acpid random purge-kernels reboot network haldaemon boot.clock syslog ford_tso_off Sts splash_early haveged rpcbind multipathd nfs smbfs kbd irq_balancer alsasound mcelog network-remotefs sshd java.binfmt_misc clamd logd gpm ntp single atd clamav-milter canna amavis cups nscd postfix xdm cron smartd
INTERACTIVE = kbd ntp single
network: dbus
haldaemon: dbus acpid
syslog: network earlysyslog
ford_tso_off: network
Sts: network
splash_early: syslog
haveged: syslog random
rpcbind: syslog
multipathd: syslog
nfs: rpcbind
.
.
.
.
mcelog: smbfs
network-remotefs: smbfs haldaemon
In the “make” mode, startpar uses the .depend.start file to find which dependent services needs to be started in order to start to start a specific service.
In the above ouput, when startpar is executed with start mode using make option, the dependent scripts are started first before the scripts are executed in parallel.
Here’s an example how the startpar can be used in the make mode during system startup sequence,
# startpar -p 4 -t 20 -T 3 -M start -P N -R 2
D-Bus already started. Not starting.
Starting acpid                    done
Re-Starting syslog services       done
Starting service at daemon        done
Starting sound driver             done
Starting cupsd                    done
Starting CRON daemon/usr/sbin/cron: can't lock /var/run/cron.pid, otherpid may be 3506: Resource temporarily unavailable
startproc:  exit status of parent of /usr/sbin/cron: 1
                                  done
Starting irqbalance                                                       unused
HAL already started. Not starting.
Starting mcelog... already running                                        done
Setting up network interfaces:
    eth0      device: Intel Corporation 82545EM Gigabit Ethernet Co
    eth0      IP address: 19.86.xxx.xxx/24                                done
    eth1      device: Intel Corporation 82545EM Gigabit Ethernet Co
    eth1      IP address: 19.86.xxx.xxx/24                                done
Setting up service network  .  .  .  .  .  .  .  .  .  .                  done
Hint: you may set mandatory devices in /etc/sysconfig/network/config
Setting up (remotefs) network interfaces:
Setting up service (remotefs) network  .  .  .  .  .  .  .  .  .  .       done
Initializing random number generator                                      done
Starting smartd                                                           unused
Disabling TSO on all interfaces and adding ETHTOOL_OPTIONS to nic config files  done
Re-Starting syslog services              done
Starting haveged daemon                  done
failed_service="alsasound"
skipped_service="irq_balancer smartd"
In the above example, startpar is executed with the total number of 4 process to run in parallel with a timeout of 20 seconds , global timeout 3 seconds to empty the buffer area, -M in make mode with “start” option to indicate startup is being used in start sequence.
This will use /etc/init.d/.depend. start file to verify the scripts that are dependent on each other. –P is the previous run-level –N is the new runlevel.
Here’s another example to use startpar just to execute 2 scripts in parallel, you can also define this script on /etc/init.d/rc to ensure these scripts gets started in parallel during system startup if required.
# startpar -p 4 -t 20 -T 3 -a start /etc/init.d/ypxfrd /etc/init.d/drbd
Starting rpc.ypxfrd              done
Starting DRBD resources:
.
.
Also in some Linux distros, you can setup the system to use startpar option in /etc/init.d/rc file.
In the rc file, just change the value “CONCURRENCY=SHELL” to “CONCURRENCY=STARTPAR”, which should calculate the dependencies automatically and start the applicable scripts in parallel.
# vi /etc/init.d/rc
CONCURRENCY=STARTPAR

1 comment:

  1. Hello, an amazing Information dude. Thanks for sharing this nice information with us. Website Erstellen Berlin

    ReplyDelete