Network Latencies

LatencyDescription
Name resolution latencyThe time for a host to be resolved to an IP address, usually by DNS resolution—a common source of performance issues.
Ping latencyThe time from an ICMP echo request to a response. This measures the network and kernel stack handling of the packet on each host.
TCP connection initialization latencyThe time from when a SYN is sent to when the SYN,ACK is received. Since no applications are involved, this measures the network and kernel stack latency on each host, similar to ping latency, with some additional kernel processing for the TCP session. TCP Fast Open (TFO) may be used to reduce this latency.
TCP first-byte latencyAlso known as the time-to-first-byte latency (TTFB), this measures the time from when a connection is established to when the first data byte is received by the client. This includes CPU scheduling and application think time for the host, making it a more a measure of application performance and current load than TCP connection latency.
TCP retransmitsIf present, can add thousands of milliseconds of latency to network I/O.
TCP TIME_WAIT latencyThe duration that locally closed TCP sessions are left waiting for late packets.
Connection/session lifespanThe duration of a network connection from initialization to close. Some protocols like HTTP can use a keep-alive strategy, leaving connections open and idle for future requests, to avoid the overheads and latency of repeated connection establishment.
System call send/ receive latencyTime for the socket read/write calls (any syscalls that read/write to sockets, including read(2), write(2), recv(2), send(2), and variants).
System call connect latencyFor connection establishment; note that some applications perform this as a non-blocking syscall.
Network round-trip timeThe time for a network request to make a round-trip between endpoints. The kernel may use such measurements with congestion control algorithms.
Interrupt latencyTime from a network controller interrupt for a received packet to when it is serviced by the kernel.
Inter-stack latencyTime for a packet to move through the kernel TCP/IP stack.

Latency Numbers for various components in a system

Units of time

UnitAbbreviationFraction of 1 second
Minutem60
Seconds1
Milisecondms0.001 or 1 × 10-3
Microsecondμs1 × 10-6
Nanosecondns1 × 10-9
Picosecondps1 × 10-12

Time scale of system latencies
Numbers are from runs on (4 vCPUs, 16 GB memory), SSD persistent – Intel Cascade machine.

EventLatency
L1 cache reference1ns
Branch mispredict3ns
L2 cache reference4ns
Mutex lock/unlock17ns
Main memory reference100ns
SSD Random read16μs
Read 1 MiB from memory3μs
Read 1MiB sequentially from SSD49μs
Read 1MiB sequentially from HDD825μs
System Call500ns
Context Switch10μs
Sequential Memory R/W 1MiB100μs
Random HDD Seek 1MiB15ms
Random SSD Seek 1MiB15ms
Sequential SSD write 1MiB (with fsync)100ms
Sequential SSD write 1MiB (without fsync)1ms

Key terms for system performance

The following are key terms for systems performance.

  1. IOPS: Input/output operations per second is a measure of the rate of data transfer operations. 
  2. Throughput: The rate of work performed
  3. Response time: The time required for an operation to complete. This includes time spent by the request waiting for resources.
  4. Latency: The time spent by the request waiting. Sometimes it might be used as an equivalent of response time.
  5. Utilisation: Measure of how busy a resource is for a given interval when it was servicing requests.
  6. Saturation: The amount of queued work a resource has which it cannot service.
  7. Bottleneck: A resource that limits the system performance.
  8. Workload: Load on/Input to the system
  9. Cache: A system that can buffer a limited amount of data, usually faster than the underlying primary storage.
  10. Bandwidth: Maximum transfer rate of a channel

fswatch – Monitors Files and Directory Changes or Modifications in Linux

fswatch is a cross-platform, file change monitor that gets notification alerts when the contents of the specified files or directories are altered or modified.

It executes four types of monitors on different operating systems such as:

  1. A monitor build on the File System Events API of Apple OS X.
  2. A monitor based on kqueue, a notification interface present in FreeBSD 4.1 also supported on many *BSD systems, OS X inclusive.
  3. A monitor based on File Events Notification API of the Solaris kernel plus its spin-offs.
  4. A monitor based on inotify, a kernel subsystem that shows file system modifications to apps.
  5. A monitor based on ReadDirectoryChangesW, a Windows API that records alters to a directory.
  6. A monitor that regularly check that status of file system, keeps file modification times in memory, and manually determine file system changes (which works anywhere, where stat can be used).

Features of fswatch

  1. Supports several OS-specific APIs
  2. Allows recursive directory monitoring
  3. Performs path filtering using including and excluding regular expressions
  4. Supports customizable record format
  5. Additionally, it supports periodic idle events

How To Install fswatch in Linux Systems

Unfortunately, fswatch package is not available to install from the default system repositories in any Linux distributions. The only way to install the latest version of fswatch is to build from source tarball as show in the following installation instructions.

First grab the latest fswatch tarball using following wget command and install it as shown:

$ wget https://github.com/emcrisostomo/fswatch/releases/download/1.9.3/fswatch-1.9.3.tar.gz
$ tar -xvzf fswatch-1.9.3.tar.gz
$ cd fswatch-1.9.3
$ ./configure
$ make
$ sudo make install 

Important: Make sure you’ve GNU GCC (C and C++ Compiler) and Development Tools (build-essential on Debian/Ubuntu) installed on the system, before you compile fswatch from source. If not, install it using following command on your respective Linux distributions..

# yum group install 'Development Tools'		[On CentOS/RHEL]
# dnf group install 'Development Tools'		[On Fedora 22+ Versions]
$ sudo apt-get install build-essential          [On Debian/Ubuntu Versions]

On Debian/Ubuntu distributions, you might get following error while executing fswatch command..

fswatch: error while loading shared libraries: libfswatch.so.6: cannot open shared object file: No such file or directory

To fix it, you need to execute the command below, this will help refresh the links and cache to the dynamic libraries before you can start using fswatch.

$ sudo ldconfig

How do I use fswatch on Linux?

The general syntax for running fswatch is:

$ fswatch [option] [path]

On Linux, it is recommended that you use the default inotify monitor, you can list available monitors by employing the -M or - list-monitors option:

$ fswatch -M
$ fswatch --list-monitors

fswatch - List Monitors

The command below enables you to watch the changes in the current directory (/home/tecmint), with events being delivered to standard output every 4 seconds.

The -l or –-latency option allows you to set the latency in seconds, the default being 1 second.

$ fswatch -l 4 .

fswatch - Monitor Home Directory Changes

The next command monitors changes to the /var/log/auth.log file every 5 seconds:

$ fswatch -l 5 /var/log/auth.log

Using -t or --timestamp option prints the time stamp for every event, to print the time in UTC format, employ -u or --utf-time option. You can as well format time using -f or --format-time format option:

$ fswatch --timestamp /var/log/auth.log

Next, -x or --event-flags tells fswatch to print the event flags along side the event path. You can use –event-field-seperator option to print events using the particular separator.

$ fswatch --events-flags ~ /var/log/auth.log

To print the numeric value of an event indicating changes in your home directory and /var/log/auth.log file, use -n or --numeric option as below:

$ fswatch --numeric ~ /var/log/auth.log 

Perhaps you can look through the fswatch man page for detailed usage options and information:

$ man fswatch