pdsh Parallel Shell

When I was preparing for my qualification exams in graduate school, I talked with fellow grad students about their experiences. I remember one fellow student said something like, "When in doubt, focus on the fundamentals"; that is, go back to first principles to solve problems. I have always remembered his comment and I try to apply it when I can.

For HPC, one of the fundamentals is being able to run a command across a number of nodes in a cluster. A parallel shell is a simple but powerful tool that allows you to do so on designated (or all) nodes in the cluster, so you do not have to log in to each node and run the same command. This single tool has an infinite number of ways to be useful, but I like to use it when performing administrative tasks, such as:

  • discovering the status of the nodes in the cluster quickly,
  • checking the versions of particular software packages on each node,
  • checking the OS version on all nodes,
  • checking the kernel version on all nodes,
  • searching the system logs on each node (if you do not store them centrally),
  • examining the CPU usage on each node,
  • examining local I/O (if the nodes do any local I/O),
  • checking whether any nodes are swapping,
  • spot-monitoring the compute nodes, and
  • debugging.

This list is just the short version; the real list is extensive. Anything you want to do on a single node can be done on a large number of nodes using a parallel shell tool. However, for those that might be asking if they can use parallel shells on their 50,000-node clusters, the answer is that you can, but the time skew in the results will be large enough that the results might not be useful (which is a completely different subject). Parallel shells are more practical when used on a smaller number of nodes, on specific nodes (e.g., those associated with a specific job in a resource manager), or for gathering information that varies somewhat slowly. However, some techniques will allow you to run parallel commands on a large number of nodes.

Among the parallel shells available, many are written in Python, which has become a very popular DevOps tool. Some of the tools are perhaps not as appropriate or useful for HPC but may be good for other tasks. The shell I typically use – and that I have found a large number of other people using – is pdsh .

Introduction to pdsh

The pdsh tool is arguably one of the most popular parallel shells. It allows you to run commands on multiple nodes using only SSH, so the data transmission is encrypted. [It is a good practice to encrypt all data, whether it is “on the wire” or “at rest,” or within the cluster or from outside the cluster.] Only the client nodes need to have ssh installed, which is pretty typical for HPC systems. However, you need the ability to ssh to any node without a password (i.e., passwordless ssh ). Using ssh inside the cluster should alleviate your fears about not using passwords.

Building and Installing pdsh

Building and installing pdsh is really simple if you have built code using GNU’s autoconfigure before:

./configure --with-ssh --without-rsh
make
make install

These three lines put the binaries into /usr/local/ , which is fine for testing purposes. For production work, I would put them in /opt or the like; just be sure the directory is in your path. Also, to make life easier, I put the directory on a filesystem that is shared with the compute nodes, which allows pdsh to run regardless of what system you are using.

You might notice that I used the -- without-rsh option in the configure command. By default, pdsh uses rsh , which is not secure and should never be used. Notice the available rcmd modules (rcmd is the “remote command” used by pdsh ) at the bottom of Listing 1 states that only ssh and exec are available. If rsh wasn't excluded, it would be listed here, too, and it would be the default; however, it is highly recommended that you not build pdsh with rsh because it is such a security hole.

Listing 1: pdsh Options

$ pdsh -v
pdsh: invalid option -- 'v'
Usage: pdsh [-options] command ...
-S                return largest of remote command return values
-h                output usage menu and quit
-V                output version information and quit
-q                list the option settings and quit
-b                disable ^C status feature (batch mode)
-d                enable extra debug information from ^C status
-l user           execute remote commands as user
-t seconds        set connect timeout (default is 10 sec)
-u seconds        set command timeout (no default)
-f n              use fanout of n nodes
-w host,host,...  set target node list on command line
-x host,host,...  set node exclusion list on command line
-R name           set rcmd module to name
-M name,...       select one or more misc modules to initialize first
-N                disable hostname: labels on output lines
-L                list info on all loaded modules and exit
available rcmd modules: ssh,exec (default: ssh)

If you happened to build pdsh with rsh and do not or cannot rebuild it, you can override rsh and make ssh the default by adding the following line to your .bashrc file:

export PDSH_RCMD_TYPE=ssh

Be sure to source your .bashrc file (e.g., source .bashrc ) to set the environment variable. You can also log out and log back in.

If for some reason you see the following when you try running pdsh , then you have built it with rsh :

$ pdsh -w 192.168.1.250 ls -s
pdsh@home4: 192.168.1.250: rcmd: socket: Permission denied

You can either rebuild pdsh without rsh or use the environment variable in your .bashrc file (or both).

First pdsh Commands

A quick test ensures that pdsh is working correctly. This simple test gets the kernel version of a different node using the IP address of the other node.

$ pdsh -w 192.168.1.250 uname -r
192.168.1.250: 2.6.32-431.11.2.el6.x86_64

The -w option means that the IP address of the target’s node(s) is specified. In this case, the IP address of the target remote node is listed (192.168.1.250 ). Specifically, uname -r is the command to be run. Finally, notice that pdsh output starts the with the node name 192.168.1.250 followed by the output of the command or, as in this case, an error message.

In the off chance you need to mix rcmd modules in a single command, you can specify which module to use on the pdsh command line. For example, the command below uses ssh :

$ pdsh -w ssh:laytonjb@192.168.1.250 uname -r
192.168.1.250: 2.6.32-431.11.2.el6.x86_64

You just put the specific rcmd module before the node name. In this case, ssh .

A very common use of pdsh is to use the WCOLL environment variable that points to the file with a list of hosts. If you don't specify a host list on the command line, pdsh will use the host list indicated by WCOLL . As an example, I created a pdsh subdirectory with a file named hosts that lists the default hosts:

$ mkdir PDSH
$ cd PDSH
$ vi hosts
$ more hosts
192.168.1.4
192.168.1.250

For this specific case, only two nodes are listed: 192.168.1.4 and 192.168.1.250 . The first node is the cluster head node, and the second is the first test compute node. The hosts in the file can be specified in a comma-separated list, if desired. Just be sure not to put a blank line at the end of the file because pdsh will think it is a host and try to connect to it. You can put the WCOLL environment variable in the .bashrc file:

export WCOLL=/home/laytonjb/PDSH/hosts

As before, you can source your .bashrc file, or you can log out and log back in to activate it after you create it.

Ideally, your /home directory is shared with all nodes in the cluster, which means you only have to edit .bashrc once; otherwise, you have to log in to every node and update the local .bashrc . (What a pain!)

Specifying Hosts

Specifying a list of nodes can be done in several ways, which I will not list here. The pdsh site discusses virtually all of them, some of which are pretty handy.

The simplest way to specify the nodes is on the command line with the -w option, separated by commas:

$ pdsh -w 192.168.1.4,192.168.1.250 uname -r
192.168.1.4: 2.6.32-696.30.1.el6.x86_64
192.168.1.250: 2.6.32-431.11.2.el6.x86_64

Or, you can use a range of hosts on the command line:

$ pdsh -w host[1-11] uname -r
$ pdsh -w host[1-4,8-11] uname -r

In the first case, pdsh expands the host range to host1 , host2 , host3 , etc., through host11 . In the second case pdsh expands the host list to host1 , host2 , host3 , host4 , host8 , host9 , etc., through host11 . The pdsh website has more information on hostlist expressions. Being able to specify a range of hosts is very convenient if you have a large number of nodes.

Even if you use a range of hosts, specifying the exact host targets can result in a long command. Another option is to have pdsh read the hosts from a file other than the WCOLL environment variable:

$ pdsh -w ^/tmp/hosts uptime
192.168.1.4:  15:51:39 up  8:35, 12 users,  load average: 0.64, 0.38, 0.20
192.168.1.250:  15:47:53 up 2 min,  0 users,  load average: 0.10, 0.10, 0.04
$ more /tmp/hosts
192.168.1.4
192.168.1.250

This command tells pdsh to take the hostnames from the file listed after -w ^ (no space between the ^ and the file name), which is /tmp/hosts here.

Using files that contain lists of nodes is a great way to examine subsets of nodes, especially for larger systems. For example, you could create a list of hosts in one file for the first rack, a second list in a different file for the second rack, and so on. A command could then be run that uses the specific file that lists the hosts in a specific rack.

The subsets do not have to be divided on a rack basis. The lists can be based on node type or cluster function, such as putting all I/O nodes or all login nodes into a single file; you are not limited as to what you can do with these files. This method allows you to use pdsh with very large systems by breaking it to subclusters that are more manageable; then, you can run the same command on each of the subclusters.

The following example shows how to use several host files at once:

$ more /tmp/hosts
192.168.1.4
$ more /tmp/hosts2
192.168.1.250
$ pdsh -w ^/tmp/hosts,^/tmp/hosts2 uname -r
192.168.1.4: 2.6.32-696.30.1.el6.x86_64
192.168.1.250: 2.6.32-431.11.2.el6.x86_64

Notice that both nodes respond to the command. Hosts can also be excluded from a list:

$ pdsh -w -192.168.1.250 uname -r
192.168.1.4: 2.6.32-696.30.1.el6.x86_64

The hyphen in front of 192.168.1.250 means it is excluded from the command, so the output is only from 192.168.1.4 . Nodes listed in a file can also be excluded from the pdsh command:

$ pdsh -w -^/tmp/hosts2  uname -r
192.168.1.4: 2.6.32-696.30.1.el6.x86_64

By using the hyphen in front of the file name, the nodes listed in the file are excluded. In this case /tmp/hosts2 , which contains 192.168.1.250 , is not included in the output.

Alternatively, you can use the -x option combined with a hostname or a list of hostnames to be excluded:

$ pdsh -x 192.168.1.4 uname -r
192.168.1.250: 2.6.32-431.11.2.el6.x86_64
$ pdsh -x ^/tmp/hosts uname -r
192.168.1.250: 2.6.32-431.11.2.el6.x86_64
$ more /tmp/hosts
192.168.1.4

The first command excludes 192.168.1.4 from the default list of hosts. The second command excludes the host in /tmp/hosts from the output.

The combinations of these options are very powerful, allowing you to set up files with hosts for specific subsets of nodes, such as racks, or to create node lists on the basis of node function, such as login or storage. If nodes are down, you can exclude them, if you like. The point is, you should think about common node combinations and include them in specific files. Simple bash scripts could also allow you to specify combinations of node files.

Related content

comments powered by Disqus