<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>technology on Digi Hunch</title><link>https://www.digihunch.com/tag/technology/</link><description>Recent content in technology on Digi Hunch</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Tue, 08 Apr 2025 14:46:49 -0400</lastBuildDate><atom:link href="https://www.digihunch.com/tag/technology/index.xml" rel="self" type="application/rss+xml"/><item><title>Virtualization 1 of 4 – Hypervisor</title><link>https://www.digihunch.com/2020/07/overview-of-virtualization/</link><pubDate>Mon, 27 Jul 2020 22:52:00 -0400</pubDate><guid>https://www.digihunch.com/2020/07/overview-of-virtualization/</guid><description>&lt;p class="wp-block-paragraph"&gt;In broad terms, virtualization of computing resource is about isolation of resources, at different levels. There are five levels of virtualization:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Application level, such as JVM, .NET CLR&lt;/li&gt;&#10;&lt;li&gt;Library (user-level API) level&lt;/li&gt;&#10;&lt;li&gt;Operating system level, such as LXC, Docker, OpenVZ&lt;/li&gt;&#10;&lt;li&gt;Hardware abstraction layer (HAL) level, such as VMware, Xen, etc&lt;/li&gt;&#10;&lt;li&gt;Instruction set architecture (ISA) level&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In my context I deal mostly with OS level and HAL (hardware abstraction layer) level of virtualization. In loose terms, the word &lt;em&gt;containerization&lt;/em&gt; refers to &lt;span style="text-decoration: underline;"&gt;OS level virtualization&lt;/span&gt;, while the word &lt;em&gt;virtualization&lt;/em&gt; is exclusively reserved for &lt;span style="text-decoration: underline;"&gt;HAL level virtualization&lt;/span&gt;, also referred to as &lt;span style="text-decoration: underline;"&gt;hypervisor-based virtualization&lt;/span&gt;. This post will just focus on this family of technology and loosely refers to it as virtualization.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Virtualization technology evolved from on-premise data centre environment and now is the backbone of cloud computing. The challenges of IT operation in the era of virtualization involves managing VM sprawling, investigating performance issues, planning capacity and addressing storage I/O block. The idea of virtualization is sharing (thus isolating) resources for better utilization, leading to better return on investment. This posting is to cover only the very basics of virtualization.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-hypervisor"&gt;Hypervisor&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Hypervisor is the software layer which provides the capability to run multiple virtual machines on the same physical host. It is broken down into two categories:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;strong&gt;Type I hypervisor (aka bare metal hypervisor)&lt;/strong&gt;: directly run on physical hardware. They control the hardware as well as manage the virtual machines. For example, Linux KVM, VMware ESXi, Xen and Microsoft Hyper-V&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Type II hypervisor&lt;/strong&gt;: runs as an application or service on top of the host operating system, which is installed on the bare metal. Guest operating system calls need to traverse via the host operating system stack to reach hardware resource. For example, Oracle Virtual Box, VMware Fusion and Linux Containers (LXC)&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter"&gt;&lt;img decoding="async" src="https://img.vembu.com/wp-content/uploads/2019/12/Hypervisor-Types.png" alt="Type-1 vs Type-2 Hypervisor"/&gt;&lt;figcaption class="wp-element-caption"&gt;Hypervisor Types&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;h3 class="wp-block-heading" id="h-virtualization-techniques"&gt;Virtualization Techniques&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The most primitive form of technology that can be arguably categorized under virtualization is hardware emulation, where a piece of (more accessible) hardware imitates another (less accessible). The architecture limits itself in functional testing only, and is not built for performance or production at all.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The original virtualization technology deals with CPU and memory virtualization. In this well-written &lt;a href="https://github.com/skonstantinov89/books/blob/master/Understanding%20Full%20Virtualization%2C%20Paravirtualization%2C%20and%20Hardware%20Assist.pdf"&gt;whitepaper &lt;/a&gt;fromVMware, there are three CPU virtualization techniques introduced for x86 architecture.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The x86 architecture offers four levels of privilege known as Ring 0,1,2 and 3 to operating system and applications to manage access to the computer hardware. User-level applications typically run in Ring 3, the OS must execute its privileged instructions in Ring 0 since it needs to have direct access to memory and hardware. The two main challenges with virtualizing x86 architecture are:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;A virtualization layer between hardware operating system who expects Ring 0 privilege;&lt;/li&gt;&#10;&lt;li&gt;Some instructions with different semantics when not executed in Ring 0 cannot be virtualized effectively. They need to be translated at runtime.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;These challenges makes true virtualization of x86 architecture impossible and thus VMware developed three alternative technologies.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;a href="https://en.wikipedia.org/wiki/Full_virtualization"&gt;&lt;strong&gt;Full virtualization&lt;/strong&gt;&lt;/a&gt; (using binary translation): virtual machine presents a complete simulation of the actual hardware environment so that an unmodified guest OS can run in isolation. The Guest OS is not aware that the underlying environment it is running on is virtualized, and issues hardware calls to communicate with (what it thinks as) hardware. The virtual processors have to understand guest CPU instruction, and reproduce the equivalent CPU instructions of the host machine. VMware&amp;#8217;s technology to address this is called &lt;strong&gt;Binary Translation&lt;/strong&gt;. This overhead makes true full virtualization difficult to achieve. In real life, a virtual environment that provides &amp;#8220;enough representation of the underlying hardware&amp;#8221; can be considered to provide full virtualization as long as it allows guest OS to run without modification. Full virtualization comes with a performance penalty. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;a href="https://en.wikipedia.org/wiki/Paravirtualization"&gt;&lt;strong&gt;Paravirtualization &lt;/strong&gt;&lt;/a&gt;(aka OS assisted virtualization): refers to communication between the guest OS and the hypervisor to improve performance and efficiency. In this technology, guest OS is modified with an interface to host hardware to be able to communicate and operate seamlessly. Since the guest OS is modified, the VM does not need to be a complete simulation of the hardware. The modified guest OS knows it is running on a virtualized environment, and (vm driver) makes API calls (known as &amp;#8216;hyper calls&amp;#8217;) to the hypervisor. This allows para-virtualization technology to achieve performance closer to non-virtualized environment. However, since paravirtualization cannot support unmodified operating systems, its compatibility and portability is poor. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;a href="https://en.wikipedia.org/wiki/Hardware-assisted_virtualization"&gt;&lt;strong&gt;Hardware-Assisted Virtualization&lt;/strong&gt;&lt;/a&gt;: hardware vendors such as Intel and AMD both have developed extensions (new features) to simplify virtualization techniques, for example, the introduction of privileged instructions with new CPU execution mode feature to allow hypervisor to run in a new root mode below ring 0. This removed the need for full virtualization and paravirtualization. With VMware originally as a promoter of full virtualization and Xen for paravirtualization, most virtualization technologies today utilizes hardware-assisted virtualization feature, for example, Linux KVM, VMware workstation, VMware fusion, Xen, VirtualBox, etc. Intel&amp;#8217;s virtualization extension is VT-x. AMD&amp;#8217;s counterpart is AMD-V technology.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;To virtualize memory, another level of memory virtualization is required (similar to the virtual memory support in Linux). Hypervisor is responsible for mapping guest physical memory to the actual machine memory, and it uses shadow page tables to accelerate the mappings, usually at a performance cost.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-popular-hypervisors"&gt;Popular hypervisors&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;On the market there are a few popular hypervisor technologies. They are all type 1 hypervisors:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;a href="https://en.wikipedia.org/wiki/Xen"&gt;Xen &lt;/a&gt;is an open-source &lt;a href="https://xenproject.org/"&gt;hypervisor project&lt;/a&gt; originally developed in Cambridge University, licensed under GPLv2. . Based on that, Citrix developed its commercial product XenServer, a bare-metal virtualization platform with enterprise-grade features for x86 and AMD environments. Oracle VM is another commercial implementation of Xen. The Xen project also supports many cloud platforms such as Openstack, Cloudstac, etc. Xen project supports paravirtualization (Xen-PV) as well as hardware-assisted virtualization (Xen-HVM) for virtualization of X86, IA64, ARM and other CPU architectures. The earlier versions does not support memory overcommit (aka &amp;#8220;dynamic memory optimization&amp;#8221;, &amp;#8220;memory &lt;a href="https://www.digihunch.com/2020/05/understanding-where-the-memory-goes-on-linux-vm/"&gt;ballooning&lt;/a&gt;&amp;#8220;, or as Citrix calls it &amp;#8220;dynamic memory control, DMC&amp;#8221;). This delivers better performance but also has higher budgetary requirement on hardware since there isn&amp;#8217;t room for over-subscription. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Hyper-V is a Microsoft product. It executes in high CPU privilege (Microsoft calls it ring -1 which is equivalent to root mode as Intel calls it). On the guest VM, OS kernel and drivers run in ring 0, application rin in ring 3. This eliminates the need for binary translation. Hyper-V does not support memory overcommit either. Hyper-V is well integrated with Windows platform. It supports Linux as well although with some performance penalty.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Linux KVM (Kernel-based Virtual Machine) is a full open-source virtualization solution for GNU/Linux. What makes KVM a special hypervisor is that it uses a loadable kernel module kvm.ko that turns itself into a hypervisor and provides VMs with direct access to the hardware. So it is a type 1 hypervisor despite of the presence of Linux OS. KVM also contains a processor specific module, kvm-intel.ko or kvm-amd.ko. KVM leverages qemu to access devices. Because KVM runs as a process inside of Linux OS, KVM can use many existing feature in Linux kernel. Redhat has an enterprise solution based on KVM.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-full"&gt;&lt;img loading="lazy" decoding="async" width="850" height="414" src="https://www.digihunch.com/wp-content/uploads/2023/01/Comparison-of-Xen-KVM-and-QEMU.png" alt="" class="wp-image-7813" srcset="https://www.digihunch.com/wp-content/uploads/2023/01/Comparison-of-Xen-KVM-and-QEMU.png 850w, https://www.digihunch.com/wp-content/uploads/2023/01/Comparison-of-Xen-KVM-and-QEMU-300x146.png 300w, https://www.digihunch.com/wp-content/uploads/2023/01/Comparison-of-Xen-KVM-and-QEMU-768x374.png 768w" sizes="auto, (max-width: 850px) 100vw, 850px" /&gt;&lt;figcaption class="wp-element-caption"&gt;Xen vs KVM&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;VMware &lt;a href="https://en.wikipedia.org/wiki/VMware_ESXi"&gt;ESXi &lt;/a&gt;is VMware&amp;#8217;s premium hypervisor product (not open-source) and is available for &lt;s&gt;free download&lt;/s&gt;, although the advanced features are not free. (Update no free download link &lt;a href="https://www.reddit.com/r/vmware/comments/1amtzvc/esxi_hypervisor_free_gone/"&gt;anymore&lt;/a&gt;.) VMware &lt;a href="https://www.digihunch.com/2018/07/overview-of-vsphere/"&gt;vSphere&lt;/a&gt; is virtualization platform built on top of ESXi, including a whole family of virtualization products.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-market-segments-and-players"&gt;Market segments and players&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Virtualization involves many market segments such as virtual desktop infrastructure (VDI, for desktop virtualization), server virtualization is the predominant domain in the virtualization of data centre environment. This effort led to Hyper-Converged Infrastructure (HCI) where almost all the traditional hardware resources are software-defined through the virtualization layer. The management of infrastructure is abstracted away from the physical hardware management. The three most fundamental areas in HCI are:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Server (compute) virtualization: the previous section covers the virtualization of memory and x86 CPU, which are the main focus on computing resource virtualization. Additionally, graphics computing resources can be virtualized today. Example products include: VMware vShpere (compute virtualization based on ESXi hypervisor).&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;&lt;a href="https://en.wikipedia.org/wiki/Storage_virtualization"&gt;Storage Virtualization&lt;/a&gt;&lt;/strong&gt;: the technology to abstract physical data storage resource to make them appear as if they were a centralized resource. Storage virtualization takes place at three levels depending on the use case: block-level, file-level and object level. Example products include: VMWare vSAN (vSphere-native storage), HPE 3PAR (Tier-1 storage), EMC VxRail, PureStorage Flash Array (Tier 1), etc. Storage Virtualization enables &lt;a href="https://en.wikipedia.org/wiki/Software-defined_storage"&gt;&lt;strong&gt;Software-Defined Storage&lt;/strong&gt; &lt;/a&gt;&lt;strong&gt;(SDS)&lt;/strong&gt;, the provisioning and management of data storage independent of the underlying hardware.&amp;nbsp;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;&lt;a href="https://en.wikipedia.org/wiki/Network_virtualization"&gt;Network Virtualization&lt;/a&gt;&lt;/strong&gt;: the technology to abstract network resources that were traditionally delivered in hardware to software. Network virtualization decouples network services from the underlying hardware management and allows virtual provisioning of an entire network. VLAN is a classic example of network virtualization. There are also various overlay technologies such as VXLAN, which provides an industry framework for overlaying virtualized layer 2 network over layer 3 network (used in Docker network) using an encapsulation mechanism and a control plane. Example products include: VMware NSX Data Center (L2-L7 network and security virtualization platform), Cisco ACI, Palo Alto Panorama. Network Virtualization enables &lt;strong&gt;&lt;a href="https://en.wikipedia.org/wiki/Software-defined_networking"&gt;Software-Defined Network&lt;/a&gt; (SDN)&lt;/strong&gt;, an approach to network management that enables dynamic, programmatically efficient network configuration in order to improve network performance and monitoring, making it more like cloud computing than traditional network management.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-delivery-model"&gt;Delivery model&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Virtualization allows managed service providers (MSPs) to deliver IT service in the following three models:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;strong&gt;Iaas (Infrastructure as a Service)&lt;/strong&gt;: MSP delivers VM to customers.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;PaaS (Platform as a Service)&lt;/strong&gt;: MSP delivers environments to customers (e.g. Database as a Service, managed RabbitMQ service, etc).&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;SaaS (Software as a Service)&lt;/strong&gt;: MSP delivers entire application for the customer.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img decoding="async" src="https://www.redhat.com/cms/managed-files/iaas_focus-paas-saas-diagram-1200x1046.png" alt="What is IaaS?" style="width:608px;height:388px"/&gt;&lt;figcaption class="wp-element-caption"&gt;IT service delivery models enabled by virtualization technology&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Since virtualization is the backbone of cloud computing. This model is also referred to as cloud computing delivery model.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-virtualization-and-containerization"&gt;Virtualization and Containerization&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;These two concepts are similar and could be confusing to beginners. Both provide a mechanism to isolate computing resource for different applications, for the purpose of higher utilization of resource. The difference lies in how and where the isolation is made. Virtualization requires a guest operating system per VM (OS level isolation), whereas the container technology isolates application processes along with its runtime into a container (dependency level isolation), using some new Linux kernel features such as &lt;em&gt;namespaces &lt;/em&gt;and &lt;em&gt;cgroups&lt;/em&gt;. All containers make their system calls to the container engine on the host operating system. So they share a kernel on the same host. In this sense, container engine running on OS could be considered as type 2 hypervisor.&lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img decoding="async" src="https://dzone.com/storage/temp/10561741-vm-container-figure1.jpg" alt="Image title"/&gt;&lt;figcaption class="wp-element-caption"&gt;From VMs to containers&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;VMware is a major player in enterprise data centre virtualization, which is facing fierce competition from public and private cloud vendors. VMware also has its own private cloud services. Docker is the most popular container technology that conforms to the specifications of Open Container Initiative (OCI), a governance structure for industry standards around container formats and runtimes.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-virtualization-and-cloud"&gt;Virtualization and Cloud&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Among public cloud vendors, AWS &lt;a href="https://cloudacademy.com/blog/aws-ami-hvm-vs-pv-paravirtual-amazon/"&gt;EC2 &lt;/a&gt;used Xen PV and Xen HVM in its earlier implementations. It has transitioned to AWS bare metal. The history is well summarized &lt;a href="http://www.brendangregg.com/blog/2017-11-29/aws-ec2-virtualization-2017.html"&gt;here&lt;/a&gt;. Microsoft Azure runs Azure Hypervisor as the native hypervisor in Azure Cloud Services platform. It is a customized version of Microsoft Hyper-V specifically for Azure platform. With GCP, Google &lt;a href="https://cloud.google.com/compute/docs/faq"&gt;Compute Engine&lt;/a&gt; (GCE) instance runs VMs on KVM as hypervisor. It can also enable nested virtualization.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The scope of cloud computing is evolving overtime. It originally only refers to a business model of offering IT services (in one of the three delivery models outlined above) based on virtualization technology. Therefore I cannot make comparison between a technology and a business model. Today, with public cloud vendor extending their offerings (with various managed services and platforms) and people&amp;#8217;s misuse of the terms, the buzz-word &amp;#8220;cloud&amp;#8221; seems to suggest anything that is offered in public cloud service. The essence still remain the same where managed services and managed platforms are built on top of virtualized compute unit under the hood, which are driven by virtualization technologies.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2020/07/zookeeper-and-kafka-overview/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Kafka high-level Overview&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2020/08/virtualization-of-graphics-computing-resource/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Virtualization 2 of 4 – Graphics Computing&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>How RPC and NFS work</title><link>https://www.digihunch.com/2020/07/nfs-network-file-system-and-rpc-remote-procedure-call/</link><pubDate>Wed, 15 Jul 2020 10:45:00 -0400</pubDate><guid>https://www.digihunch.com/2020/07/nfs-network-file-system-and-rpc-remote-procedure-call/</guid><description>&lt;p class="wp-block-paragraph"&gt;I touched on NFS in several previous postings, and here is a deeper dive of this particular protocol. NFS is built on top of Remote Procedure Call (RPC) and therefore it is important to understand RPC first. In fact NFS is one of the most prominent user of RPC and the best example for learning RPC.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;RPC overview&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;According to &lt;a href="https://en.wikipedia.org/wiki/Remote_procedure_call"&gt;Wikipedia&lt;/a&gt;, an RPC is when a computer program causes a procedure to execute in a different address space (commonly on another computer on a shared network), which is coded as if it were a normal (local) procedure call, without the programmer explicitly coding the details for the remote interaction. That is, the programmer writes essentially the same code whether the subroutine is local to the executing program, or remote. This is a form of client–server interaction (caller is client, executor is server), typically implemented via a request–response message-passing system. In the object-oriented programming paradigm, RPCs are represented by remote method invocation (RMI), such as Java RMI API.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;RPCs are a form of inter-process communication (IPC), in that other processes have a different address spaces: if on the same host machine, they have distinct virtual address spaces, even though the physical address space is the same; while if they are on different hosts, the physical address space is different. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;RPC is a&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Request%E2%80%93response"&gt;request–response&lt;/a&gt;&amp;nbsp;protocol, and therefore synchronous. An RPC is initiated by the&amp;nbsp;&lt;em&gt;client&lt;/em&gt;, which sends a request message to a known remote&amp;nbsp;&lt;em&gt;server&lt;/em&gt;&amp;nbsp;to execute a specified procedure with supplied parameters. The remote server sends a response to the client, and the application continues its process. While the server is processing the call, the client is blocked (it waits until the server has finished processing before resuming execution), unless the client sends an asynchronous request to the server. There are many variations and subtleties in various implementations, resulting in a variety of different (incompatible) RPC protocols.&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="694" height="475" src="https://www.digihunch.com/wp-content/uploads/2020/07/image-1.png" alt="" class="wp-image-1161"/&gt;&lt;/figure&gt;&#10;&lt;h3 class="wp-block-heading"&gt;NFS overview&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;NFS is defined as a set of RPCs, including their arguments, results and effects. RPC makes NFS protocol transparent. RPC is also stateless so the server does not keep the state of RPCs once the request has been served. Each RPC contains the necessary information to complete the call. In the event of server failure, client will need to resubmit requests. &lt;a href="https://en.wikipedia.org/wiki/Network_File_System"&gt;NFS&lt;/a&gt; has several versions, with v3 and v4 most popular. We will focus on v3 in this posting and brief on v4.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;Portmap&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;RPC makes a remote call appears to client application as a local call, with the help of &lt;a href="https://en.wikipedia.org/wiki/Portmap"&gt;portmap&lt;/a&gt;. The utility for portmap is rpcbind. In RedHat/CentOS 5 or prior, it was even simply called portmap but they are essentially the same service for RPC port mapper. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The rpcbind service is required on both NFS client and NFS server. On the client, it talks to client application, as well as its counterpart on the server. Its main function is query its counterpart on the server, providing a RPC program number, and expects a port number in return. On the server, the rpcbind utility listens at port 111, waiting for request with RPC program number(service), and return the TCP or UDP port number on which the requested service is hosted. RPC program number is reserved numeric indicator of services as outlined in &lt;a href="https://www.iana.org/assignments/rpc-program-numbers/rpc-program-numbers.xhtml"&gt;RFC5531&lt;/a&gt;. For example, 100005 for mountd, 100021 for nlockmgr, and 100003 for nfs. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The port that rpcbind service itself listens on is always at port 111, which is known to both client and server. This is also referred to as portmapper daemon. Other than this fixed port, each NFS-related service (with their respect reserved program number) may be hosted on different ports on the server. The client rpcbind service must first look up for the port for the requested program number, then it directs the client to initiate connection to the specified port for the specific service. &lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img decoding="async" src="https://docs.oracle.com/cd/E37838_01/html/E61058/figures/S9_portmap_seq.jpg" alt="image:Graphic illustrates portmap sequence for TCP/IP only"/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;With the following command rpcinfo command you may look up the program to port number mapping on destination server isilon.company.com&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# rpcinfo -p isilon.company.com&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;The following command is commonly used for displaying mountpoint and troubleshooting mount. Under the hood it is using the information from rpcinfo.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;showmount -e isilon.dcb.digitalhunch.com&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;On the NFS server side, rpcbind service must start before nfs service start. Otherwise nfs service cannot register ports to rpcbind. If you restart rpcbind, every service that had registered to rpcbind must restart to register themselves again. By default, NFS server can dynamically assign a port for mountd, nlockmgr within a port range. &lt;a href="https://www.systutorials.com/fixing-ports-used-by-nfs-server/"&gt;This&lt;/a&gt; makes firewall setting a pain. These dynamically assigned port can be fixed via configuration files. &lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;File handle&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;NFS uses &lt;a href="https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxb500/bpx1fr_NFS_file_handles.htm"&gt;file handles&lt;/a&gt; (or fhandle) to represent files. It is a better mechanism to reference a file object than pathname for three reasons: 1. file handle has fixed length (32bytes); 2. If the file is renamed, the file handle reference remain the same; 3. If a file is deleted, and then a new file is created with the same path, a new file handle will be created. A file handle has three parts:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;volume ID: to identify the mounted file system&lt;/li&gt;&lt;li&gt;inode #: to identify the file within the mounted file system&lt;/li&gt;&lt;li&gt;&lt;a href="https://utcc.utoronto.ca/~cks/space/blog/unix/NFSFilehandleInternals"&gt;generation #&lt;/a&gt;: to detect when file handle refers to an older version of inode. Traditional Unix filesystems may reuse inode and thus NFS client could mistakenly use an old file handle and access a new file.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The file handle information is only meaningful to the server. New file handles are returned to client by certain procedures, such as LOOKUP, CREATE, and MKDIR. The file handle for the root of the file system, is obtained by the client when it mounts the file system, as permission allows.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;Permission and Locking&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;When accessing a file on server, the client passes uid/gid info in RPCs, and the server performs permission checks as if the user was performing the operation locally. So users and groups are represented as integers. There are two security problems:&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&lt;li&gt;The mapping from uid/gid to user must be the same on all clients. This is not practical in large deployment, although can be solved via Network Information Service (NIS);&lt;/li&gt;&lt;li&gt;Whether the root user on the client has root access to files on the server, is a server policy configuration. This can be addressed by enabling &amp;#8220;root squashing&amp;#8221; on server, so that client&amp;#8217;s uid 0 (root) is mapped to 65534 (nobody).&lt;/li&gt;&lt;/ol&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Unix has &lt;a href="https://gavv.github.io/articles/file-locks/"&gt;two locking mechanisms&lt;/a&gt; (fcntl and flock). NFS protocol supports fcntl but not flock. The flock function is managed by a separate service (nfslock) to allow NFS to lock files. The &lt;a href="https://www.thegeekdiary.com/linux-os-service-nfslock/"&gt;nfslock&lt;/a&gt; daemon provides the ability to lock regions of NFS files. NFS service itself is still completely stateless with locking managed separately. This is changed in NFSv4.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;Procedures used in NFS service&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;NFS service defines a &lt;a href="https://docs.oracle.com/cd/E19620-01/805-4448/z4000027624/index.html"&gt;list of procedures&lt;/a&gt;. Here is a list with brief summary of activities. The bottom five RPCs are introduced in v3.&lt;/p&gt;&#10;&lt;figure class="wp-block-table is-style-regular"&gt;&lt;table class="has-background" style="background-color:#e9fbe5"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Procedure&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Activity&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;GETATTR(fh)&lt;/td&gt;&lt;td&gt;Returns the attributes of a file, similar to stat syscall.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SETATTR(fh, attr)&lt;/td&gt;&lt;td&gt;Sets the attributes of a file (mode, uid, gid, size, atime, mtime); setting the size to 0 truncates the file&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;STATFS(fh)&lt;/td&gt;&lt;td&gt;Returns the status of a filesystem, such as block size, number of free blocks. e.g. df command.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;LOOKUP (dirfh, name)&lt;/td&gt;&lt;td&gt;Returns fhandle and attributes for the named file in the directory specified by dirfh&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;READ (fh, offset, count)&lt;/td&gt;&lt;td&gt;Reads from a file, with offset and count specified. In v2, the length is up to 8192 bytes; v3 support more.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;WRITE (fh, offset, count, data)&lt;/td&gt;&lt;td&gt;Writes to a file, with offset and count specified, as well as a separate field called data. Returns the new attributes of the file after the write.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CREATE (dirfh, name, attr)&lt;/td&gt;&lt;td&gt;Creates a file with the name, in directory, returns new fhandle and attributes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;REMOVE (dirfh, name)&lt;/td&gt;&lt;td&gt;Deletes the named file in from directory dirfh and returns status.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;RENAME (dirfh, name, tofh, toname)&lt;/td&gt;&lt;td&gt;Renames name in directory dirfh, to toname in directory tofh.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;LINK (dirfh, name, tofh, toname)&lt;/td&gt;&lt;td&gt;Creates a hard link toname, in directory tofh, that points to name, indirectory dirfh.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SYMLINK (dirfh, name, string)&lt;/td&gt;&lt;td&gt;Creates a symbolic link name, in the directory dirfh, with value string.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;READLINK (fh)&lt;/td&gt;&lt;td&gt;Reads a symbolic link and get file name of the target.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;MKDIR (dirfh, name, attr)&lt;/td&gt;&lt;td&gt;Creates a directory name in the directory dirfh, and returns the new fh and attributes.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;RMDIR(dirfh, name)&lt;/td&gt;&lt;td&gt;Removes a directory with the name, from parent directory dirfh.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;READDIR (dirfh, cookie, count)&lt;/td&gt;&lt;td&gt;Reads a directory and returns up to count bytes of directory entries from the directory dirfh. The cookie is used in subsequent readdir calls to start reading at a specific entry in the directory. Cookie of zero get the server to start with the first entry in the directory.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;NULL&lt;/td&gt;&lt;td&gt;No activity. Used for testing only.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ACCESS&lt;/td&gt;&lt;td&gt;Helps with client caching.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;MKNOD&lt;/td&gt;&lt;td&gt;Makes a device special file.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;FSINFO&lt;/td&gt;&lt;td&gt;Returns information about the server&amp;#8217;s capabilities. &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;READDIRPLUS&lt;/td&gt;&lt;td&gt;Returns both file handle and attributes to eliminate LOOKUP calls when scanning a directory&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;COMMIT&lt;/td&gt;&lt;td&gt;In NFSv3, the server can reply to WRITE RPCs immediately without syncing to disk. When client wants to ensure that the data is on stable storage, it sends a COMMIT RPC. This is used in asynchronous writes for better performance, which is an option negotiated at mount time.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The addition of COMMIT procedure in v3 offers the option to improve write performance in place of synchronous write. However, asynchronous write requires more coordination to ensure data integrity during transmission, in the event of server crash. NFSv3 uses write verifier for this purpose. A write verifier is an 8-bye value that the server must change if it crashes. &lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;After an asynchronous write, the reply from WRITE RPC includes a write verifier, the client must keep it for later use;&lt;/li&gt;&lt;li&gt;The client then sends a COMMIT RPC and the reply contains another write verifier;&lt;/li&gt;&lt;li&gt;The client compares the verifiers from the two returns for crash detection. If the verifiers don&amp;#8217;t match, the client must rewrite all uncommitted data.&lt;/li&gt;&lt;li&gt;The client must keep all uncommitted data in case of a server crash.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;h3 class="wp-block-heading"&gt;Additional daemon processes&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In addition to the three essential services, (nfs, rpcbind and nfslock), there are several auxiliary processes that facilitates NFS services. Their functions are listed &lt;a href="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/storage_administration_guide/ch-nfs"&gt;here&lt;/a&gt;:&lt;/p&gt;&#10;&lt;figure class="wp-block-table is-style-regular"&gt;&lt;table class="has-background" style="background-color:#e9fbe5"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Process&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;rpc.mountd&lt;/td&gt;&lt;td&gt;Used by NFS server to process MOUNT requests from NFSv3 client. It checks that the requested NFS share is currently exported by the NFS server, and that the client is allowed to access it. If the mount request is allowed, the rpc.mountd server replies with a Success status and provides the File-Handle for this NFS share back to the NFS client.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;rpc.nfsd&lt;/td&gt;&lt;td&gt;Allows explicit NFS versions and protocols the server advertises to be defined. It works with the Linux kernel to meet the dynamic demands of NFS clients, such as providing server threads each time an NFS client connects. This process corresponds to the nfs service.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;rpc.lockd&lt;/td&gt;&lt;td&gt;A kernel thread which runs on both clients and servers. It implements the Network Lock Manager (NLM) protocol, which allows NFSv3 clients to lock files on the server, using procedures such as NLM_NULL, NLM_TEST, NLM_LOCK, NLM_GRANTED, NLM_UNLOCK, NLM_FREE. The service is started automatically whenever the NFS server is run and whenever an NFS file system is mounted.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;rpc.statd&lt;/td&gt;&lt;td&gt;This process implements the Network Status Monitor (NSM) RPC protocol, which notifies NFS clients when an NFS server is restarted without being gracefully brought down. rpc.statd is started automatically by the nfslock service, and does not require user configuration. This is not used with NFSv4.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;rpc.rquotad&lt;/td&gt;&lt;td&gt;This process provides user quota information for remote users. rpc.rquotad is started automatically by the nfs service and does not require user configuration.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;rpc.idmapd&lt;/td&gt;&lt;td&gt;provides NFSv4 client and server upcalls, which map between on-the-wire NFSv4 names (strings in the form of user@domain) and local UIDs and GIDs. For idmapd to function with NFSv4, the /etc/idmapd.conf file must be configured. At a minimum, the &amp;#8220;Domain&amp;#8221; parameter should be specified, which defines the NFSv4 mapping domain. If the NFSv4 mapping domain is the same as the DNS domain name, this parameter can be skipped. The client and server must agree on the NFSv4 mapping domain for ID mapping to function properly.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;h3 class="wp-block-heading"&gt;NFSv4&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Even NFSv4 was introduced in 20 years ago, it improves access and performance of NFS on the Internet. It should be the default option for any new deployment.&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;NFSv4 is TCP only protocol and it is stateful. &lt;/li&gt;&lt;li&gt;NFSv4 combines mount and lock protocols into NFS so only one port is being used. &lt;/li&gt;&lt;li&gt;Users and groups are identified with strings (user@domain, or group@domain where domain represents a registered DNS domain or sub-domain), instead of integers. The access control policies are compatible with both Unix and Windows.&lt;/li&gt;&lt;li&gt;NFSv4 mandates strong RPC security built on cryptography, with negotiation at the time of mount&lt;/li&gt;&lt;li&gt;NFSv4 adopted a framework for authentication, integrity and privacy at RPC level&lt;/li&gt;&lt;li&gt;Introduced new RPC COMPOUND, which allows for several operations in one go. At the server, operations are evaluated in order, and each has a return value.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;NFSv4.1 was release in 2010, and 4.2 in 2016. Both AWS EFS and Azure File storage supports 4.1.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2020/07/emc-productlines/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;EMC Isilon storage product&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2020/07/zookeeper-and-kafka-overview/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Kafka high-level Overview&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>EMC Isilon storage product</title><link>https://www.digihunch.com/2020/07/emc-productlines/</link><pubDate>Wed, 08 Jul 2020 20:04:00 -0400</pubDate><guid>https://www.digihunch.com/2020/07/emc-productlines/</guid><description>&lt;p class="wp-block-paragraph"&gt;EMC has several product lines for different use cases in enterprise data storage. Like may other IT solutions, the website is clouded with marketing terms and slogans, and is purposefully not technical. This makes it difficult for technical staff to grasp the advantage of its product in a glimpse. I personally have to know their product (mostly with Isilon and ECS) well in order to make integration decisions. So I&amp;#8217;m putting together this note (updated as of July 2020), with lots of details from their technical white paper.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-overview-of-emc-storage"&gt;Overview of EMC storage&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;At the highest level, the EMC enterprise data storage product lines are categorized into two groups: &lt;strong&gt;primary storage&lt;/strong&gt; (along the lines of block-level storage) and &lt;strong&gt;unstructured storage&lt;/strong&gt; (mostly file and object storage). The &lt;span style="text-decoration: underline;"&gt;primary storage &lt;/span&gt;includes the following product:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;span style="text-decoration: underline;"&gt;PowerMax&lt;/span&gt; for OLTP database (Oracle, MicrosoftSQL and SAP)&lt;/li&gt;&#10;&lt;li&gt;&lt;span style="text-decoration: underline;"&gt;PowerFlex&lt;/span&gt;: for Software defined storage, Oracle RAC, Elastic Stack, Kubernetes, Splunk&lt;/li&gt;&#10;&lt;li&gt;&lt;span style="text-decoration: underline;"&gt;XtremIO&lt;/span&gt; for VMware, VDI, SAP&lt;/li&gt;&#10;&lt;li&gt;&lt;span style="text-decoration: underline;"&gt;PowerStore&lt;/span&gt; for Database, VMware&lt;/li&gt;&#10;&lt;li&gt;&lt;span style="text-decoration: underline;"&gt;PowerVault&lt;/span&gt; for Entry-level SAN and DAS environment&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;This post only expands on the &lt;span style="text-decoration: underline;"&gt;unstructured storage&lt;/span&gt; product line, which mainly consists of PowerScale and ECS. &lt;strong&gt;ECS (elastic cloud storage) &lt;/strong&gt;is EMC&amp;#8217;s object storage. &lt;strong&gt;PowerScale (aka Isilon)&lt;/strong&gt; is scale-out NAS platform for high-volume storage (up to 50 PB in a single file system), backup and archiving of unstructured data. For the rest of this post, I will still refer to PowerScale as Isilon. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Dell&amp;#8217;s official support website is the most resourceful place to get information. For example, when I want to read about Isilon. I start with &lt;a href="https://www.dell.com/support/home/en-ca"&gt;Dell support&lt;/a&gt;, then click on &lt;a href="https://www.dell.com/support/home/en-ca?app=knowledgebase"&gt;knowledgebase&lt;/a&gt; at the top, then go to &amp;#8220;&lt;a href="https://www.dell.com/support/contents/en-ca/category/product-support/self-support-knowledgebase/enterprise-resource-center"&gt;servers, storage and networking&lt;/a&gt;&amp;#8220;, then &amp;#8220;&lt;a href="https://www.dell.com/support/article/en-ca/sln312354/storage-technical-documents-and-videos?lang=en"&gt;storage technical documents and videos&lt;/a&gt;&amp;#8220;. There I can select a productline such as &lt;a href="https://www.dell.com/support/article/en-ca/sln316985/powerscale-and-isilon-technical-documents-and-videos?lang=en"&gt;Isilon&lt;/a&gt;.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-overview-of-isilon-family"&gt;Overview of Isilon Family&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Isilon is a clustered storage system consisting of three or more nodes. A node is a server with OneFS as its operating system. Based on FreeBSD, OneFS is EMC&amp;#8217;s proprietary operating system to unify a cluster of nodes into a single shared resource. So &lt;a href="https://en.wikipedia.org/wiki/OneFS_distributed_file_system"&gt;OneFS&lt;/a&gt; is for Isilon only. It is the basis of Isilon. Isilon has three series of products:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;strong&gt;F series&lt;/strong&gt;: F200, F600, F800 and F810.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;H series&lt;/strong&gt;: typical models are H400, H500 and H600, which seeks to balance performance and capacity&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;A series&lt;/strong&gt;: typical models are A200 and A2000 for active and deep archive storage&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In June 2020, Dell decoupled OneFS software (with 9.0 released) from server hardware (referred to as PowerScale). Going forward EMC will refer to Isilon as PowerScale for OneFS version newer than 9.0 in spec sheets and white papers.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;span style="text-decoration: underline;"&gt;F200&lt;/span&gt; is the cost-effective choice with SSD for remote office, small hospital, retail outlets, IOT or factory floor. &lt;span style="text-decoration: underline;"&gt;F600&lt;/span&gt; uses NVMe drives instead, and has more ECC memory and faster ethernet backend network. and is higher than F200 in its use case. Both F200 and F600 provide inline data compression and deduplication capabilities. &lt;span style="text-decoration: underline;"&gt;F800 and F810 &lt;/span&gt;both use SSD and they are similar. F800 comes with InfiniBand backend network and F810 provides inline data compression and deduplication capabilities. H series tries to strike a balance between performance and capacity so they are pretty much everything in betwee. On the other end, &lt;span style="text-decoration: underline;"&gt;A200 and A2000&lt;/span&gt; are almost the same except for capacity difference.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-isilon-s-advantage"&gt;Isilon&amp;#8217;s advantage&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Isilon has lots of intelligence built into its solution compared to a traditional NAS. Here are some aspects from its product white paper:&lt;/p&gt;&#10;&lt;figure class="wp-block-table is-style-stripes"&gt;&lt;table class="has-background" style="background-color:#e9fbe5"&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Aspects of Design&lt;/th&gt;&lt;th&gt;Isilon OneFS Scale-Out NAS&lt;/th&gt;&lt;th&gt;Traditional NAS&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Network&lt;/td&gt;&lt;td&gt;Separation of front-end and back-end network to isolate node-to-node communication to a private low-latency network. Front-end traffic load balanced with SmartConnect&lt;/td&gt;&lt;td&gt;Single network for both external and internal traffic&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;File system structure and NameSpace&lt;/td&gt;&lt;td&gt;The storage is completely virtualized to users as a truly &lt;span style="text-decoration: underline;"&gt;single file system with one namespace&lt;/span&gt;. There is no partitioning or volumes. The single file tree can grow organically without requiring planning or oversight about how the tree grows. SmartPool handles tiering of files to appropriate disk, without disrupting the single file tree.&lt;/td&gt;&lt;td&gt;An appearance of single namespace is typically achieved through &lt;span style="text-decoration: underline;"&gt;namespace aggregation&lt;/span&gt;, where files are still managed in separate volumes, and a simple &amp;#8220;veneer&amp;#8221; layer glues individual directories to a &amp;#8220;top-level&amp;#8221; tree via symbolic links. LUNs and volumes, as well as volume limits are still present. Files have to be manually moved from volume-to-volume to load-balance.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Data Layout&lt;/td&gt;&lt;td&gt;OneFS controls the placement of file directly, down to the sector-level on any drive anywhere in the cluster. The addressing scheme for data and metadata is indexed at physical level by a tuple of {node, drive, offset}&lt;/td&gt;&lt;td&gt;Data are sent through RAID and volume management layers, introducing inefficiencies in data layout and providing non-optimized block access. &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Redundancy Control&lt;/td&gt;&lt;td&gt;OneFS can flexibly control the type of striping as well as the redundancy level of the storage system at the system, directory and even file-levels.&lt;/td&gt;&lt;td&gt;The entire RAID volume is dedicated to a particular performance type and protection setting.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;h3 class="wp-block-heading" id="h-isilon-terms"&gt;Isilon terms&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The Isilon technology re-implemented the read and write path during file storage and introduced several terms along with its technology.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;SmartPools &lt;/strong&gt;&amp;#8211; Job that runs and moves data between the tiers of nodes within the same cluster. Also executes the CloudPools functionality if licensed and configured. FilePolicy is changelist-based SmartPools file pool policy job. SmartPoolsTree enforces SmartPools file policies on a subtree. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Storage Pools &lt;/strong&gt;&amp;#8211; Storage pools provide the ability to define subsets of hardware within a single cluster, allowing file layout to be aligned with specific sets of nodes through the configuration of storage pool policies. The notion of Storage pools is an abstraction that encompasses disk pools, node pools, and tiers.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Disk Pools&lt;/strong&gt; &amp;#8211; Disk pools are the smallest unit within the storage pools hierarchy. OneFS provisioning works on the premise of dividing similar nodes’ drives into sets, or disk pools, with each pool representing a separate failure domain. Disk pools are laid out across all five sleds in each node.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Node Pools &lt;/strong&gt;&amp;#8211; groups of disk pools, spread across similar storage nodes (or equivalent classes). Multiple groups of different node types can work together in a single, heterogeneous cluster. For example, one node pool of all-flash F-Series anodes, one node pool of H-series, and one node pool of A-series. Each node pool only contains disk pools from the same type of storage nodes.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Tiers&lt;/strong&gt; &amp;#8211; groups of nodepools combined into a logical superset to optimize data storage, according to OneFS platform type. this allows customers who consistently purchase highest capacity nodes available to consolidate a variety of node styles within a single tier, and manage them as one logical group. SmartPools users typically deploy 2 to 4 tiers. different node pools under a tier needs to be compatible.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Global Namespace Acceleration (GNA)&amp;#8217;&lt;/strong&gt;s principal goal is to help accelerate metadata read operations by keeping a copy of a cluster&amp;#8217;s metadata on high performance, low latency SSD media.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;SmartConnect&lt;/strong&gt; is a load balancer that works at the front-end Ethernet layer to evenly distribute client connections across the cluster. SmartConnect supports dynamic NFS failover and failback to ensure that when a node failure occurs, or preventative maintenance is performed, all in-flight reads and writes are handed off to another node in the cluster to finish its operation without any user or application interruption.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Auto Balance&lt;/strong&gt; reallocates and rebalances data and make storage space more usable and efficient.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;SmartQuotas&lt;/strong&gt; is directory-level quota management. Note: there is no partitioning, and no need for volume creation in OneFS.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;SmartRead&lt;/strong&gt; creates a data &amp;#8220;pipeline&amp;#8221; from L2 cache, prefetching into a local &amp;#8220;L1&amp;#8221; cache, on the captain node, in order to greatly improve sequential-read performance. For high-sequential cases, SmartRead can very aggressively prefetch ahead. SmartRead can control how aggresive the pre-fetching is, and how long data stays in the cache, and optimizes where data is cached.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;In-line Data Reduction&lt;/strong&gt; &amp;#8211; the write path involves zero block removal, in-line deduplication, and in-line compression. This is supported in some models only.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Smart Dedupe&lt;/strong&gt; &amp;#8211; post-process, asynchronous deduplication. Smart Dedupe scans the on-disk data for identical blcoks and then eliminate the duplicates. After duplicate blocks are discovered, SmartDedupe movees a single copy of those blocks to a special set of files known as shadow stored. With post-process deduplication, new data is first stored on the storage device and then a subsequent process analyzes the data looking for commonality. This means that initial file write or modify performance is not impacted, since no additional computation is required in the write path, as opposed to in-line deduplication. This is supported on some models only.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;OneFS SSD strategy&lt;/strong&gt; &amp;#8211; How OneFS leverage the SSD for performance. It has these options:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;L3 cache (implemented at nodepool level)&lt;/li&gt;&#10;&lt;li&gt;metadata read&lt;/li&gt;&#10;&lt;li&gt;metadata read/write&lt;/li&gt;&#10;&lt;li&gt;Global Namespace Acceleration (GNA)&lt;/li&gt;&#10;&lt;li&gt;Data on SSD&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;L3 cache consumes all the SSD in node pool. L3 cannot coexist with other SSD strategies, with the exception of GNA just because L3 cache node pool SSD cannot participate in GNA.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-isilon-s-high-availability"&gt;Isilon&amp;#8217;s High Availability&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The OneFS is distributed across all nodes in the cluster and is accessible by clients connecting to any node in the cluster. Metadata and locking tasks are managed by all nodes collectively and equally in a peer-to-peer architecture. This symmetry is key to the simplicity and resiliency of the architecture. There is no single metadata server, lock manager or gateway node.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The entire cluster forms a single file system with a single namespace that runs across every node equally. No one node controls or &amp;#8220;masters&amp;#8221; the cluster; all nodes are true peers.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;During failover, clients are evenly redistributed across all remaining nodes in the cluster, ensuring minimal performance impact. If a node is brought down for any reason, including a failure, the virtual IP addresses on that node is seamlessly migrated to another node in the cluster. When the offline node is brought back online, SmartConnect automatically rebalances the NFS and SMB3 clients across the entire cluster to ensure maximum storage and performance utilization. This functionality allows for per-node rolling upgrades affording full-availability throughout the duration of the maintenance window.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;There are two logical roles in processing an I/O request from client:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;span style="text-decoration: underline;"&gt;The initiator&lt;/span&gt;: the node that the client connects to with front-end protocol. The initiator acts as the &amp;#8216;captain&amp;#8217; for the entire I/O operation.&lt;/li&gt;&#10;&lt;li&gt;&lt;span style="text-decoration: underline;"&gt;The participant&lt;/span&gt;: Every node in the cluster is a participant for a particular I/O operation.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 class="wp-block-heading" id="h-file-write-in-isilon"&gt;File Write in Isilon&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;OneFS employs a patented transaction system during write to eliminate single point of failure. In a write operation, the initiator &amp;#8220;captains&amp;#8221; or orchestrates the layout of data and metadata, the creation of erasure codes, and the normal operations of lock management and permission control.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;When a client connects to a node to write a file, it is connecting to the Initiator. OneFS breaks the file down into atomic units. An atomic unit is a smaller logical chunk of data, also called stripe, or protection groups in the context of data protection. The size of each file chunk is referred to as the stripe unit size. After this division, OneFS then write the stripe individually to the Participant (with disks). This design ensures that data is protected at the specified level as soon as it is being written. Redundancy is built into protection groups, such that if every protection group of a file is safe, then the entire file is safe. In terms of protection mechanism, OneFS can use either Reed-Solomon erasure coding system, or simply mirroring for data protection. Erasure coding is the predominant mechanism with very high performance without sacrificing on-disk efficiency.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The initiator node uses a modified two-phase commit transaction to safely distribute writes to multiple &lt;a href="https://en.wikipedia.org/wiki/Non-volatile_random-access_memory"&gt;NVRAMs&lt;/a&gt; across the cluster. As client initiates write to OneFS cluster, instead of immediately writing to disk, OneFS temporarily writes the data to an NVRAM-based journal cache on the initiator node and acknowledge the write the client. As outlined above, these writes are also mirrored to participant nodes&amp;#8217; NVRANM journals to satisfy the file&amp;#8217;s protection requirement. Later, at a more convenient time, OneFS then flush these cached writes to disks asynchronously.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Since NVRADM journals all the transactions that are occurring across every node in the storage cluster. If a node fails mid-transaction, and then re-joins the cluster, the uncommitted cached writes are fully protected, and the only required actions for the node, are to replay its journal from NVRAM, and occasionally for AutoBalance to rebalance files that were involved in the transaction. Writes are never blocked due to a failure. There is no &amp;#8216;fsck&amp;#8217; or &amp;#8216;disk-check&amp;#8217; process.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;OneFS file system block size is 8KB. A file smaller than 8KB will use a full 8KB block. For larger files, OneFS can maximize sequential performance by taking advantage of a stripe unit consisting of 16 contiguous blocks, for a total of 128KB per stripe unit.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-cache-in-isilon"&gt;Cache in Isilon&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;OneFS aggregates the cache present on each node in a cluster into one globally accessible pool of memory by using a messaging system similar to NUMA (non-uniform memory access). This allows all the nodes&amp;#8217; memory cache to be available to each and every node in the cluster. Remote memory is access over internal network with much lower latency than accessing hard disk drives. The internal network as distributed system bus, is a redundant, under-subscribed flat Ethernet up to 40Gb. The oneFS caching subsystem is coherent across the cluster, due to the use of MESI protocol to maintain cache coherency. If the same content exists in the private caches of multiple nodes, this cached data is consistent across all instances.&lt;br&gt;OneFS uses up to three levels of read cache, plus an NVRAM-backed write cache, or coalescer.&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="1466" height="900" src="https://www.digihunch.com/wp-content/uploads/2020/07/image.png" alt="" class="wp-image-1131"/&gt;&lt;figcaption class="wp-element-caption"&gt;OneFS Caching Hierarchy&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;L1 cache &amp;#8211; prefetches data from remote nodes. Data is prefetched per file, and this is optimized in order to reduce the latency associated with the nodes’ back-end network. The L1 cache refers to memory on the same node as the initiator. It is only accessible to the local node, and typically the cache is not the master copy of the data.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;L1 is also known as remote cache because it contains data retrieved from other nodes in the cluster. It is coherent across the cluster but is used only by the node on which it resides and is not accessible by other nodes. Data in L1 cache on storage nodes is aggressively discarded after it is used. L1 cache uses file-based addressing, in which data is accessed via an offset into a file object.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;OneFS also uses a dedicated inode cache in which recently requested inodes are kept. The inode cache frequently has a large impact on performance, because clients often cache data, and many network I/O activities are primarily requests for file attributes and metadata, which can be quickly returned from the cached inode.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;L2 cache (backend cache) refers to local memory on the node on which a particular block of data is stored. L2 cache is globally accessible from any node in the cluster and is used to reduce the latency of a read operation by not requiring a seek directly from the disk drives.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;L2 cache is also known as local cache because it contains data retrieved from disk drives located on that node and then made available for requests from remote nodes. Data in L2 cache is evicted according to a Least Recently Used (LRU) algorithm.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;L3 cache, or Smart Flash, is configurable on nodes that contain solid state drives. Smart Flash (L3) is an eviction cache that is populated by L2 cache blocks as they are aged out from memory.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;During I/O request, clients talk to L1 cache and write coalescer; L1 cache talks to L2 cache on all cluster nodes. L2 cache buffers to and from disks. L3 cache is optionally enabled per node pool, as an extension from L2. L3 and L2 communicate in backend network.&lt;/p&gt;&#10;&lt;figure class="wp-block-table is-style-regular"&gt;&lt;table class="has-background" style="background-color:#e9fbe5"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Medium&lt;/td&gt;&lt;td&gt;Description&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;L1 Cache (aka front-end cache or remote cache)&lt;/td&gt;&lt;td&gt;RAM (volatile)&lt;/td&gt;&lt;td&gt;holds clean, cluster coherent copies of file system data and metadata blocks requested by clients via front-end network&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;L2 Cache (aka back-end cache or local cache)&lt;/td&gt;&lt;td&gt;RAM (volatile)&lt;/td&gt;&lt;td&gt;contains clean copies of file system data and metadata on a local node&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SmartCache (Write Coalescer)&lt;/td&gt;&lt;td&gt;Battery-backed NVRAM (Persistent)&lt;/td&gt;&lt;td&gt;a persistent journal cache that buffers any pending writes to front-end files that have not been committed to disk&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SmartFlash or L3 Cache&lt;/td&gt;&lt;td&gt;SSD (persistent)&lt;/td&gt;&lt;td&gt;contains file data and metadata blocks evicted from L2 cache, effectively increasing L2 cache capacity&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;h3 class="wp-block-heading" id="h-file-read-in-isilon"&gt;File Read in Isilon&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The high-level steps for fulfilling a read request with cache interaction involves:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Step 1 &amp;#8211; on local node, determine whether part of the requested data is in the local L1 cache:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;if so, return to client&lt;/li&gt;&#10;&lt;li&gt;if not, request data from remote nodes&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Step 2 &amp;#8211; on remote nodes, determine whether requested data is in the local L2 or L3 cache:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;if so, return to the requesting node&lt;/li&gt;&#10;&lt;li&gt;if not, read from disk and return to requesting node&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;During a read operation, the “captain” node gathers all of the data from the various nodes in the cluster and presents it in a cohesive way to the requestor. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The cluster provides a high ratio of cache to disk (multiple GB per node) that is dynamically allocated for read and write operations as needed. This RAM-based cache is unified and coherent across all nodes in the cluster, allowing a client read request on one node to benefit from I/O already transacted on another node. As the cluster grows larger, the cache benefit increases. For this reason, the amount of I/O to disk on a cluster is generally substantially lower than it is on traditional platforms.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;For files marked with an access pattern of concurrent or streaming, OneFS can take advantage of pre-fetching of data based on heuristics used by the SmartRead component&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-conclusion"&gt;Conclusion&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;This post provided a high level introduction to EMC storage product line and expanded into some technical details in the read write operation in OneFS/Isilon. Some of the features can be seen in &lt;a href="https://www.youtube.com/watch?v=pCIrjAQJf2g&amp;amp;t=1903s"&gt;OneFS simulator&lt;/a&gt; which is a free tool from EMC.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2020/07/dockersnetwork/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Docker network in different modes&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2020/07/nfs-network-file-system-and-rpc-remote-procedure-call/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;How RPC and NFS work&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Performance Analysis</title><link>https://www.digihunch.com/2020/06/performance-analysis-tools/</link><pubDate>Fri, 19 Jun 2020 16:47:01 -0400</pubDate><guid>https://www.digihunch.com/2020/06/performance-analysis-tools/</guid><description>&lt;h3 class="wp-block-heading" id="h-overview"&gt;Overview&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In 2015, Brendan Gregg posted two great articles&lt;a href="https://netflixtechblog.com/linux-performance-analysis-in-60-000-milliseconds-accc10403c55"&gt; &lt;/a&gt;on Netflix blog: &lt;a href="https://netflixtechblog.com/linux-performance-analysis-in-60-000-milliseconds-accc10403c55"&gt;Linux Performance Analysis in 60 seconds&lt;/a&gt;, and &lt;a href="https://netflixtechblog.com/netflix-at-velocity-2015-linux-performance-tools-51964ddb81cf"&gt;Linux Perfomrance Tools&lt;/a&gt;. They have great value when I was in a urgency to spot performance issues. The articles cover the essential tools for performance troubleshooting, including:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Check out load averages: w or uptime&lt;/li&gt;&#10;&lt;li&gt;Print kernel ring buffer: dmesg -T&lt;/li&gt;&#10;&lt;li&gt;Virtual memory status: vmstat 1&lt;/li&gt;&#10;&lt;li&gt;Multiple processor staticstics: mpstat -P ALL 1&lt;/li&gt;&#10;&lt;li&gt;Task status: pidstat 1&lt;/li&gt;&#10;&lt;li&gt;CPU and I/O status: iostat -xz 1&lt;/li&gt;&#10;&lt;li&gt;Free memory check: free -m&lt;/li&gt;&#10;&lt;li&gt;Network Activity record: sar -n DEV 1&lt;/li&gt;&#10;&lt;li&gt;TCP activity record: sar -n TCP,ETCP 1&lt;/li&gt;&#10;&lt;li&gt;Display processes: top&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;We will dive into each of them in the next section.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-basic-troubleshooting"&gt;Basic Troubleshooting&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The command w is equivalent of uptime (which shows uptime since boot) and who (which shows logged-in users). It also displays load average for the last 1 minute, 5 minutes and 15 minutes. The number of load average reflects the overall system load (CPU + disks), and it is further discussed in this &lt;a href="http://www.brendangregg.com/blog/2017-08-08/linux-load-averages.html"&gt;post&lt;/a&gt; with a simple take away:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;If the averages are 0.0, then your system is idle.&lt;/li&gt;&#10;&lt;li&gt;If the 1 minute average is higher than the 5 or 15 minute averages, then load is increasing.&lt;/li&gt;&#10;&lt;li&gt;If the 1 minute average is lower than the 5 or 15 minute averages, then load is decreasing.&lt;/li&gt;&#10;&lt;li&gt;If they are higher than your CPU count, then you might have a performance problem (it depends).&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;When Linux load averages increase, you know you have higher demand for resources (CPUs, disks, and some locks), but you aren&amp;#8217;t sure which. You will need to switch to other metrics. Brendan recommend don&amp;#8217;t spend more than 5 seconds on these numbers.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;[&lt;/span&gt;dhunch@c7v-ghintapp01 ~&lt;span style="color:#f92672"&gt;]&lt;/span&gt;$ w&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 12:14:10 up &lt;span style="color:#ae81ff"&gt;46&lt;/span&gt; days, 16:41, &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; users, load average: 2.69, 2.44, 2.29&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;dhunch pts/0 w6v-ghas01 24Jun20 3days 0.36s 0.30s ssh c7v-bastion&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;dhunch pts/1 202.95.88.111 12:02 2.00s 0.00s 0.00s w&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;dhunch pts/4 w6v-ghas01 17Jun20 15days 0.15s 0.07s view readme.txt&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Before moving to more insightful metrics, it is also worth a quick look into the kernel ring buffer with dmesg command (dmesg -T | less +G). This will allow us to capture obvious issues such as oom-killer or TCP request dropping.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The vmstat tool reports the statistics of &lt;strong&gt;virtual memory&lt;/strong&gt;. Servers have a fixed amount of physical memory, but they can run a set of applications that use a much larger amount of virtual memory. Application tend to reserve more memory than they need, and they usually operate on only a subset of their memory. In both cases, the operating system can keep the unused parts of memory on disk, and page it into physical memory only if it is needed. For the most part, this kind of memory management works well. But it doesn&amp;#8217;t always with Java applications due to Java heap. Once a system start swapping &amp;#8211; moving pages of data from main memory to disk, and vice versa, the performance tend to be bad. Systems must be configured so that swapping never occurs.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;[&lt;/span&gt;dhunch@c7v-ghintapp01 ~&lt;span style="color:#f92672"&gt;]&lt;/span&gt;$ vmstat &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; r b swpd free buff cache si so bi bo in cs us sy id wa st&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;239360&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;385928&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;36734692&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;200&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;6&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;93&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;239360&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;387732&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;36734704&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;43&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;8017&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;8524&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;14&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;85&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;239360&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;387608&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;36734904&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;57&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;6768&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;7680&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;14&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;86&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ae81ff"&gt;2&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;239360&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;389008&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;36734904&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;44&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;6366&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;7300&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;14&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;86&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;239360&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;421728&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;36700144&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;8141&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;7957&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;13&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;86&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ae81ff"&gt;2&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;239360&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;421984&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;36702048&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;467&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;8994&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;8362&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;14&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;85&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;The tool prints key server statistics each line, with the first line showing the average since boot. Here lists the explanation of some columns:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;strong&gt;r&lt;/strong&gt;: number of processes running on CPU and waiting for a turn. This provides a better signal than load averages for determining CPU saturation, as it does not include I/O. To interpret: an “r” value greater than the CPU count is saturation.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;swpd&lt;/strong&gt;: the amount of virtual memory used. This number should align with the used column for Swap row from free command.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;buff, cache&lt;/strong&gt;: buffer and cache. They should align with the buff/cache column form Mem row from free command.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;free&lt;/strong&gt;: free memory in kilobytes. This number should align with the free column for Mem row from free command. &lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;si, so&lt;/strong&gt;: swap-ins and swap-outs. As mentioned, if these are non-zero, you&amp;#8217;re out of memory.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;bi, bo&lt;/strong&gt;: blocks received from and sent to a blcok device (# of block per second)&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;in, cs&lt;/strong&gt;: number of &lt;a href="https://en.wikipedia.org/wiki/Interrupt"&gt;interrupt&lt;/a&gt;, and &lt;a href="https://en.wikipedia.org/wiki/Context_switch"&gt;context switches&lt;/a&gt; per second.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;us, sy, id, wa, st&lt;/strong&gt;: user, system, idle, wait I/O and stolen times. These are breakdowns of CPU time, on average across all CPUs. They should add up to 100% (or close). stolen time is amount of CPU time needed by a guest virtual machine that is not provided by the host. IO wait time is the CPU time waiting for I/O activity. Idle time could be several things: the process may be waiting for something (e.g. a response from database); the process may be blocked by a thread lock; or the process simply has nothing to do. user and system times are CPU times spent on user tasks and kernel tasks, respectively.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Out of these columns, watch for columns r, free, buff, cache, us, sy, id and wa at minimum. The combination of us and sy confirms if CPUs are busy. A constant degree of wa points to a disk bottleneck with too much time spent on pending disk I/O. The sy (kernel time) is necessary for I/O processing but sy stays high (e.g. constantly over 20%), it becomes interesting. Perhaps the kernel is processing I/O inefficiently.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;For further per-CPU stats, use mpstat command (-P ALL), to prind CPU time breakdowns per CPU and check for imbalance. A single host CPU can be evidence of a single-threaded application. Here is an example output from a system of 16 CPU cores.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;[&lt;/span&gt;dhunch@c7v-ghintapp01 ~&lt;span style="color:#f92672"&gt;]&lt;/span&gt;$ mpstat -P ALL &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Linux 3.10.0-1062.12.1.el7.x86_64 &lt;span style="color:#f92672"&gt;(&lt;/span&gt;c7v-ghintapp01.digihunch.com&lt;span style="color:#f92672"&gt;)&lt;/span&gt; 08/01/20 _x86_64_ &lt;span style="color:#f92672"&gt;(&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;16&lt;/span&gt; CPU&lt;span style="color:#f92672"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:23 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 all 13.77 0.00 0.19 0.00 0.00 0.00 0.00 0.00 0.00 86.05&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; 2.02 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 97.98&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt; 2.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 98.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;2&lt;/span&gt; 2.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 98.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; 98.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 2.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;4&lt;/span&gt; 2.02 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 97.98&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;5&lt;/span&gt; 2.02 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 97.98&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;6&lt;/span&gt; 2.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 98.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;7&lt;/span&gt; 2.94 0.00 0.98 0.00 0.00 0.00 0.00 0.00 0.00 96.08&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;8&lt;/span&gt; 2.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 98.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;9&lt;/span&gt; 2.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 98.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;10&lt;/span&gt; 97.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 3.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;11&lt;/span&gt; 0.99 0.00 0.99 0.00 0.00 0.00 0.00 0.00 0.00 98.02&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;12&lt;/span&gt; 2.02 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 97.98&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;13&lt;/span&gt; 1.98 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 98.02&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;14&lt;/span&gt; 2.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 98.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;13:47:24 &lt;span style="color:#ae81ff"&gt;15&lt;/span&gt; 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;For a per process summary of CPU consumption, use pidstat command. It can be thought of a periodical snapshot of top command, allowing you to watch for patterns. The %CPU column is the total across all CPUs so 5 CPUs have a maximum value of 500.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;If vmstate indicates some I/O issue, iostat tool can help us understand block devices, on both the workload applied and the resulting performance. Key columns are:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;strong&gt;r/s, w/s, rkB/s, wkB/s&lt;/strong&gt;: delivered reads, writes, read Kbytes, and write Kbytes per second to the device. Use these for workload characterization. A performance problem may simply be due to an excessive load applied.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;await&lt;/strong&gt;: the average wait time for I/O in milliseconds. This is the time that the application suffers, as it includes both time queued and time being serviced. Larger than expected average times can be an indicator of device saturation, or malfunction.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;avgqu-sz&lt;/strong&gt;: the average number of requests issued to device. Values greater than 1 can be evidence of saturation (although devices can typically operate on requests in parallel, especially virtual devices which front multiple back-end disks.)&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;%util&lt;/strong&gt;: device utilization. This is really a busy percent, showing the time each second that the device was doing work. Values greater than 60% typically lead to poor performance (which should be seen in await), although it depends on the device. Values close to 100% usually indicate saturation.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;I/O problem may either be inefficiencies in application that issues I/O request, or slowing disk unable to keep up with I/O requests. We review two examples here to illustrate each situation. The first output is as follows:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;% iostat -xm &lt;span style="color:#ae81ff"&gt;5&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;avg-cpu: %user %nice %system %iowait %steal %idle&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 23.45 0.00 37.89 0.10 0.00 38.56&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrq-sz avgqu-sz await r_await w_await svctm %util&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; sda 0.00 11.60 0.60 24.20 0.02 0.14 13.35 0.15 6.06 5.33 6.08 0.42 1.04&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;In the first example, the disk stat loosk up at first glance. The w_await (time to service I/O write) is fairly low at 6.08ms. However, the system is spending 37.89% of its time in the kernel. If all that system time is from the application, it suggest something inefficient is happening. The fact that the system is doing 24.2 writes per second is another clue: that is alot when writing only 0.14 MB per second (MBps). I/O has become a bottleneck, and the next step would be to look into how the application is performing its writes.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The second example output is as follows:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;% iostat -xm &lt;span style="color:#ae81ff"&gt;5&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;avg-cpu: %user %nice %system %iowait %steal %idle&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 35.05 0.00 7.85 47.89 0.00 9.20&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrq-sz avgqu-sz await r_await w_await svctm %util&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; sda 0.00 0.20 1.00 163.40 0.00 81.09 1010.19 142.74 866.47 97.60 871.17 6.08 100.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;In this example, it tells us that processes are spending 47.89% of their time in iowait, and the data to complete the I/O (w_await) is 871ms, the queue size is large, and the disk is writing at 81MB per second. This all points to disk I/O as a problem and that the amount of I/O in the application (or elsewhere in the system) must be reduced.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Bear in mind that poor performing disk I/O isn&amp;#8217;t necessarily an application issue. Many techniques are typically used to perform I/O asynchronously, so that the application doesn&amp;#8217;t block and suffer the latency directly (e.g. read-ahead for reads, and buffering for writes, also refer to &amp;#8220;&lt;a href="https://robertovitillo.com/why-you-should-measure-tail-latencies/"&gt;tail latency&lt;/a&gt;&amp;#8220;). &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Note that the acceptable utilization metric depends on the configuration of block device. If the storage is a logical disk device fronting many back-end disks (e.g. RAID 0), then 100% utilization may just mean that some I/O is being processed 100% of the time, however, the back-end disks may be far from being saturated, and may even be able to handle more work.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The free command gives the breakdown of memory usage. The right two columns are:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;strong&gt;buffers&lt;/strong&gt;: for the buffer cache, used for block device I/O.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;cached&lt;/strong&gt;: for the page cache, used by file systems.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;We just want to check that these aren&amp;#8217;t near-zero in size, which can lead to higher disk I/O (confirm using iostat), and worse performance. Linux uses free memory for the caches, but can reclaim it quickly if applications need it. So in a way the cached memory should be included in the free memory column. In this case, it&amp;#8217;s included in the available column. This &lt;a href="https://www.linuxatemyram.com/"&gt;website &lt;/a&gt;has further details.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;To check interface stat, nicstat is a great tool but it isn&amp;#8217;t available by default in Linux. Instead we can run sar (-n DEV) to retrieve stats. &lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;[&lt;/span&gt;dhunch@c7v-ghintapp01 ~&lt;span style="color:#f92672"&gt;]&lt;/span&gt;$ sar -n DEV &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Linux 3.10.0-1062.12.1.el7.x86_64 &lt;span style="color:#f92672"&gt;(&lt;/span&gt;c7v-ghintapp01.digihunch.com&lt;span style="color:#f92672"&gt;)&lt;/span&gt; 08/01/20 _x86_64_ &lt;span style="color:#f92672"&gt;(&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;16&lt;/span&gt; CPU&lt;span style="color:#f92672"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:51:25 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:51:26 eth0 3089.00 934.00 3815.33 834.61 0.00 0.00 0.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:51:26 lo 464.00 464.00 2289.07 2289.07 0.00 0.00 0.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:51:26 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:51:27 eth0 956.00 586.00 826.66 211.34 0.00 0.00 0.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:51:27 lo 213.00 213.00 196.00 196.00 0.00 0.00 0.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:51:27 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:51:28 eth0 349.00 181.00 52.32 147.19 0.00 0.00 0.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:51:28 lo 244.00 244.00 81.13 81.13 0.00 0.00 0.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Here rxkB/s/s and txkB/s represents receive and transmission throughput, as a measure of workload. If they reach the limit then the interface is the bottleneck.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;On top of interface is the TCP layer, which can be monitored with sar again (-n ECP, ETCP). The key metrics are:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;strong&gt;active/s&lt;/strong&gt;: number of locally-initiated (e.g. via connect()) TCP connections per second&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;passive/s&lt;/strong&gt;: number of remotely-initiated (e.g. via accept()) TCP connections per second&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;retrans/s&lt;/strong&gt;: number of TCP retransmits per second&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The active and passive counts are often useful as a rough measure of server load. It might help to think of active as outbound, and passive as inbound, but this isn&amp;#8217;t strictly true (e.g. consider a localhost to localhost connection). Retransmits are a sign of network or server issue; it may be an unreliable network (e.g. public Internet), or it may be due to a server being overloaded and dropping packets.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;[&lt;/span&gt;dhunch@c7v-ghintapp01 ~&lt;span style="color:#f92672"&gt;]&lt;/span&gt;$ sar -n TCP,ETCP &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Linux 3.10.0-1062.12.1.el7.x86_64 &lt;span style="color:#f92672"&gt;(&lt;/span&gt;c7v-ghintapp01.digihunch.com&lt;span style="color:#f92672"&gt;)&lt;/span&gt; 08/01/20 _x86_64_ &lt;span style="color:#f92672"&gt;(&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;16&lt;/span&gt; CPU&lt;span style="color:#f92672"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:52:29 active/s passive/s iseg/s oseg/s&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:52:30 0.00 1.00 28.00 35.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:52:29 atmptf/s estres/s retrans/s isegerr/s orsts/s&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:52:30 0.00 0.00 0.00 0.00 0.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:52:30 active/s passive/s iseg/s oseg/s&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:52:31 8.00 8.00 200.00 317.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:52:30 atmptf/s estres/s retrans/s isegerr/s orsts/s&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;16:52:31 0.00 1.00 1.00 0.00 3.00&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Last but not least is our favourite command top, which includes many of the metrics covered in previous tools. The downside to top is it is harder to see patterns over time, which may be more clear in tools like vmstat and pidstat, both of which produce rolling output.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Several tools introduced here involves sar, which is a great monitoring tool on its own that we need to be familiar with.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-system-activity-report-sar"&gt;System Activity Report (SAR)&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Further to the basic tools, the sar command is very helpful as it stores historical stat every 10 minutes. Sar keeps 18 types of reports, all stored in /var/log/sa/. When viewing the report file, you may pipe the result to less command so it only prints header once. For example, if you would like to print CPU report for the 2nd of the month:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# sar -u -f /var/log/sa/sar02 | less&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;If you check NFS client statistics for the 31st&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; # sar -n NFS -f /var/log/sa/sar31&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;If you need to check network server statistics for today&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# sar -n NFS -f /var/log/sa/sar31&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Below are all types of reports:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;-u CPU utilization&lt;/li&gt;&#10;&lt;li&gt;-w task creation and system switching activity&lt;/li&gt;&#10;&lt;li&gt;-W swapping statistics&lt;/li&gt;&#10;&lt;li&gt;-B report paging&lt;/li&gt;&#10;&lt;li&gt;-b report I/O and transfer rate statistics&lt;/li&gt;&#10;&lt;li&gt;-R report memory statistics&lt;/li&gt;&#10;&lt;li&gt;-r memory utilization&lt;/li&gt;&#10;&lt;li&gt;-S swap space utilization&lt;/li&gt;&#10;&lt;li&gt;-H huge pages utilization statistics&lt;/li&gt;&#10;&lt;li&gt;-v inode&lt;/li&gt;&#10;&lt;li&gt;-q queue length and load average&lt;/li&gt;&#10;&lt;li&gt;-y TTY device activity&lt;/li&gt;&#10;&lt;li&gt;-d activity for each block device&lt;/li&gt;&#10;&lt;li&gt;-n network statistics, DEV (per interface)&lt;/li&gt;&#10;&lt;li&gt;-n network statistics, EDEV (error per interface)&lt;/li&gt;&#10;&lt;li&gt;-n network statistics, NFS (NFS client)&lt;/li&gt;&#10;&lt;li&gt;-n network statistics, NFSD (NFS server)&lt;/li&gt;&#10;&lt;li&gt;-n network statistics, SOCK (socket usage)&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 class="wp-block-heading" id="h-berkeley-packet-filter-bpf-compiler-collection-bcc-tools"&gt;Berkeley Packet Filter (BPF) Compiler Collection (bcc) tools&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;For advanced, low-level performance troubleshooting, the BCC tools provide a suite of tools. Here we only cover the installation of it.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In CentOS, install bcc-tools package with yum. When you try to run a command, such as cachestat, if you come across this error:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-bash: cachestat: command not found&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Then you will need to add its path to default:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;export PATH=$PATH:/usr/share/bcc/tools&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Now if you run into this error:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;chdir(/lib/modules/3.10.0-1062.12.1.el7.x86_64/build): No such file or directory&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Traceback (most recent call last):&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;The file listed is a symbolic link, and if it is missing, you just need to install kernel-headers that matches the kernel version:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;yum install kernel-headers&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Then you may use tools in /usr/share/bcc/tools. For example, cachestat help you display page cache hit ratio; gethostlatency shows DNS resolution latency; tcpconnect prints out active tcp connections (made via connect system call):&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[root@dhunch ~]# /usr/share/bcc/tools/tcpconnect -t -P 8080 | gawk &amp;#39;{ print strftime(&amp;#34;%F %T  &amp;#34;), $0 }&amp;#39;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;2020-06-13 00:16:57   TIME(s)  PID    COMM         IP SADDR            DADDR            DPORT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;2020-06-13 02:16:57   0.000    15241  QNetworkAcce 4  10.100.22.21    10.101.84.10    8080&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;2020-06-13 02:16:57   0.064    15241  QNetworkAcce 4  10.100.22.21    10.101.84.10    8080&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;2020-06-13 02:16:57   0.438    15241  QNetworkAcce 4  10.100.22.21    10.101.84.10    8080&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;The command above outputs a&amp;nbsp;time and pid stamped log line every time&amp;nbsp;a TCP connection is made to port 8080; tcpaccept traces passive tcp connections (via accept system call). These tools are not as intrusive as tcpdump.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;It is beyond the purpose of this article to get into details of each tool in the BFP suite. The tools are covered in detail in books &amp;#8220;&lt;a href="https://amzn.to/3fEWNkq"&gt;BPF Performance Tools&lt;/a&gt;&amp;#8221; and &amp;#8220;Linux Observability with BPF&amp;#8221;.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2020/06/network-analyzer-capture-filter-and-display-filter/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Capture filter and Display filter in Network Analyzer&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2020/06/iterate-through-cassandra-table-with-datastax-python-driver/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;DataStax Python Driver&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Capture filter and Display filter in Network Analyzer</title><link>https://www.digihunch.com/2020/06/network-analyzer-capture-filter-and-display-filter/</link><pubDate>Wed, 10 Jun 2020 21:21:18 -0400</pubDate><guid>https://www.digihunch.com/2020/06/network-analyzer-capture-filter-and-display-filter/</guid><description>&lt;p class="wp-block-paragraph"&gt;Capture filter is set before collecting packets. It is applied at the time of data acquisition and it impacts the size of the capture. It does not have as many variations as display filter and is usually not aware of protocols above TCP/UDP layer. A common form of capture filter is BPF (Berkerly Packet Filter) which is used in Linux Socket Filtering (e.g. &lt;a href="https://www.digihunch.com/2018/02/tcpdump-and-wireshark/"&gt;tcpdump&lt;/a&gt;).&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Basic form is:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;[tcp|udp] [src|dst] host 192.168.1.2 port 1234&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;For example:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;#39;tcp dst port 8080 and src host 147.206.160.9&amp;#39;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Display filter is set after packet collection. It is applied at the time of data manipulation. It does not impact the size of capture, but it controls how the data is presented (typically for analysis purpose). Display filter may support a variety of expressions that are interpreting data at TCP/UDP layer or above, for example HTTP. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Here are some examples:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;(tcp.flags.syn == 1) || (tcp.flags.reset == 1)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;(tcp.flags.reset == 1) || (http.request.method==GET) ||&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;(tcp.flags.reset == 1)||(http.request.uri contains &amp;#34;/box/url/string&amp;#34;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;||(http.response.code == 200)&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;&lt;a href="https://wiki.wireshark.org/DisplayFilters"&gt;Here&lt;/a&gt; are some further examples provided by Wireshark.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;For more details about the usage of capture filter and display filter, here is a page with &lt;a href="https://packetlife.net/blog/2008/oct/18/cheat-sheets-tcpdump-and-wireshark/"&gt;cheatsheet&lt;/a&gt;. Example for tcpdump on the left and wireshark in the middle and on the right.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;To view http packet in shell terminal, there is also a helpful tool called httpry. You can applied BPF styled filter for capture, and organize display column. The drawback is there is no display filter so you&amp;#8217; would have to use grep. Here is an example:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;httpry -i eth0 &amp;#39;tcp dst port 8080 and src host 147.206.160.9&amp;#39; -m GET -f Timestamp,x-correlation-id,x-userid,Request-URI | grep -v -P &amp;#39;\t\-\t&amp;#39;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2020/06/wsl2-environment-on-windows-10/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Setup WSL2 (and Docker) on Windows 10&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2020/06/performance-analysis-tools/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Performance Analysis&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Networking Basics 3 of 3 – common network protocols and technologies</title><link>https://www.digihunch.com/2019/12/networking-basics-3-of-3-common-network-technologies/</link><pubDate>Fri, 20 Dec 2019 10:28:00 -0400</pubDate><guid>https://www.digihunch.com/2019/12/networking-basics-3-of-3-common-network-technologies/</guid><description>&lt;p class="wp-block-paragraph"&gt;The 5 layer TCP/IP model (or its more rigorously defined alternative OSI model) leads to a whole world of network protocols. Understanding these new protocols requires one to map it out agains the network layers (e.g. at Layer 4 whether it is TCP or UDP, etc) .&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;VPN is a whole family of technologies with many flavours of implementation. The previous posting covered some basics of the idea, as well as the two common forms (remote access VPN and site-to-site VPN). The VPN implementation protocols vary a lot. &lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;PPTP(Point-to-Point Tunnelling Protocol) is outdated and less secure&amp;nbsp;&lt;/li&gt;&lt;li&gt;IPSec (Internet Protocol Security)&lt;/li&gt;&lt;li&gt;L2TP (Layer 2 Tunnelling Protocol) replacement of PPTP, more secure, more overhead and slightly slower.&lt;/li&gt;&lt;li&gt;OpenVPN &amp;#8211; very secure, and reliable and supported by communities all over the world.&lt;/li&gt;&lt;li&gt;TLS/SSL and SSH connections may be considered VPN as well.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Phone service protocols&lt;/strong&gt;:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;VoIP (voice over IP, operating at network layer)&lt;/strong&gt; &amp;#8211; allows one to make and receive phone calls over the network. Communication on the IP network is perceived as less reliable in contrast to the circuit-switched public telephone network because it does not provide a network-based mechanism to ensure that data packets are not lost, and are delivered in sequential order. It is a best-effort network without fundamental Quality of Service (QoS) guarantees. Voice, and all other data, travels in packets over IP networks with fixed maximum capacity. This system may be more prone to data loss in the presence of congestion[a] than traditional circuit switched systems; a circuit switched system of insufficient capacity will refuse new connections while carrying the remainder without impairment, while the quality of real-time data such as telephone conversations on packet-switched networks degrades dramatically. Therefore, VoIP implementations may face problems with latency, packet loss, and jitter.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;SIP (session initiation protocol, operating at application layer)&lt;/strong&gt; &amp;#8211; a VOIP signaling protocol responsible for the creation and tearing down of media connections. So it supports all types of media.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;ALG (application layer gateway, aka proxy server)&lt;/strong&gt; &amp;#8211; a software component that manages specific application protocols such as SIP and FTP. An ALG acts as an intermediary between the Internet and an application server that can understand the application protocol. ALG proxies connection to destination on behalf of client. This adds &lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/12/image-5.png" alt="" class="wp-image-561" width="505" height="213"/&gt;&lt;figcaption&gt;Application Layer Gateway&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;DDNS&lt;/strong&gt; (dynamic domain name service) &amp;#8211; a router service that assigns your device a fixed domain name even though you are using dynamic IP.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;NAT&lt;/strong&gt; &amp;#8211; another family of technologies, usually implemented in the following&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;Port preservation: source port chosen by a client is the same port used by the router&amp;nbsp;&lt;/li&gt;&lt;li&gt;Port forwarding: NAT application redirects a communication request from one address and port number combination to another while the packets are traversing a network gateway, such as a router or firewall. &lt;/li&gt;&lt;li&gt;Port triggering: a dynamic form of the port forwarding model. Generally, port triggering is used when the user needs to use port forwarding to reach multiple local computers. Port are close when they aren&amp;#8217;t in use (more secure) protocol used is UPnP&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;DMZ&lt;/strong&gt; &amp;#8211; a physical or logical subnet that contains external facing service to untrusted network (e.g. Internet). The purpose is to add an additional layer of security so an external network can assess what is exposed in DMZ while the rest of network remains firewalled.&amp;nbsp;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;VPN passthrough&lt;/strong&gt; &amp;#8211; a feature that allows any device connected to the router to establish outbound VPN connections. Most modern router already have this built in.&amp;nbsp;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;WAN optimization&lt;/strong&gt; &amp;#8211; a collection of techniques for increasing data transfer efficiencies across wide-area networks.&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;Deduplication&lt;/li&gt;&lt;li&gt;Compression&lt;/li&gt;&lt;li&gt;Latency optimization&lt;/li&gt;&lt;li&gt;Caching/proxy&lt;/li&gt;&lt;li&gt;Protocol spoofing&lt;/li&gt;&lt;li&gt;Traffic shaping&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Network performance tuning&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Performance tuning in network covers a variety of skills. It is important to understand in which layer the problem occurs. Anything above layer 4 is more likely to be an application issue. For ethernet performance tuning, I found this &lt;a href="https://cromwell-intl.com/open-source/performance-tuning/ethernet.html"&gt;page&lt;/a&gt; and this &lt;a href="https://www.coverfire.com/articles/queueing-in-the-linux-network-stack/"&gt;page&lt;/a&gt; to be helpful in my practices.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/12/tcp-ip-basics-2-of-3-layer-4-and-common-technologies/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Networking basics 2 of 3 – Layer 4 and common network configurations&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2020/01/nginx-as-a-reverse-proxy-for-nifi/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Nginx as a reverse proxy for Nifi web UI and Kibana&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Networking basics 2 of 3 – Layer 4 and common network configurations</title><link>https://www.digihunch.com/2019/12/tcp-ip-basics-2-of-3-layer-4-and-common-technologies/</link><pubDate>Sat, 07 Dec 2019 23:19:00 -0400</pubDate><guid>https://www.digihunch.com/2019/12/tcp-ip-basics-2-of-3-layer-4-and-common-technologies/</guid><description>&lt;h3 class="wp-block-heading" id="h-transport-layer"&gt;Transport Layer&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Transport Layer handles multiplexing &amp;amp; de-multiplexing through ports. Port is more or less a virtual concept. Source port is usually ephemeral. Two dominant protocols are TCP and UDP.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;TCP relies on acknowledgement. TCP control flags are SYN, ACK, FIN, URG, PSH, RST, ECE, CWR. TCP connection is established by 3-way handshake and torn down by 4-way termination.&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="1223" height="502" src="https://www.digihunch.com/wp-content/uploads/2019/12/image.png" alt="" class="wp-image-515"/&gt;&lt;figcaption class="wp-element-caption"&gt;TCP handshake and termination&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Socket &amp;#8211; the instantiation of an end-point in a potential TCP connection. A socket can be in one of the following states:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;LISTEN: a TCP socket is ready and listening for incoming connections;&lt;/li&gt;&#10;&lt;li&gt;SYN_SENT: a SYNC request has been sent but connection hasn&amp;#8217;t been established yet;&lt;/li&gt;&#10;&lt;li&gt;SYN_RECEIVED: a socket previously in a LISTEN state has received a SYNC request and sent a SYN/ACK back;&lt;/li&gt;&#10;&lt;li&gt;ESTABLISHED: connection is up;&lt;/li&gt;&#10;&lt;li&gt;FIN_WAIT: FIN sent, ACK hasn&amp;#8217;t been received yet;&lt;/li&gt;&#10;&lt;li&gt;CLOSE_WAIT: connection has been closed at the TCP layer but the application that opened the socket hasn&amp;#8217;t release the hold on the socket yet;&lt;/li&gt;&#10;&lt;li&gt;CLOSED: connection fully terminated;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-full"&gt;&lt;img loading="lazy" decoding="async" width="403" height="306" src="https://www.digihunch.com/wp-content/uploads/2023/01/tcp-format.gif" alt="" class="wp-image-7811"/&gt;&lt;figcaption class="wp-element-caption"&gt;TCP packet format&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;TCP is a connection-oriented protocol&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Transport layer is responsible for re-sending data if data is lost&lt;/li&gt;&#10;&lt;li&gt;Sequence # is important because packet may arrive out of sync but receiver reassemble them in order&lt;/li&gt;&#10;&lt;li&gt;There is a lot of overhead (acknowledgement, establish connection first, tear down connection afterwards)&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;On the other hand, UDP is connectionless. A good example is video streaming, where it is okay to lose a few packet along the way, in exchange of bandwidth saving.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Firewall may operate at different layers but it is most commonly used at transport layer, to block traffic based on port.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-application-layer"&gt;Application Layer&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;There is no dominant protocol at this layer. IIS, Nginx and Apache are examples of applications operating at this layer.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-basic-network-configurations"&gt;Basic network configurations&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Standard modern network configuration involves: IP address, subnet mask, gateway and DNS server. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;DNS &lt;/strong&gt;&amp;#8211; global and highly distributed network service that resolves domain name into IP address. There are &lt;a href="https://www.golinuxhub.com/2014/01/how-does-dns-query-works-when-you-type.html"&gt;many steps in DNS resolution&lt;/a&gt;. DNS service listens on port 53. Two famous free public DNS servers are 8.8.8.8 and 8.4.4.4. DNS servers have five categories:&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&#10;&lt;li&gt;Caching name servers: store known domain name lookups in cache. TTL today can be a few hours, much shorter than what it used to be in early days;&lt;/li&gt;&#10;&lt;li&gt;Recursive name servers: perform full DNS resolution request;&lt;/li&gt;&#10;&lt;li&gt;Root name servers;&lt;/li&gt;&#10;&lt;li&gt;TLD name servers;&lt;/li&gt;&#10;&lt;li&gt;Authoritative name servers;&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img decoding="async" src="https://1.bp.blogspot.com/-JqjgddtqOiw/U6ESNhWETCI/AAAAAAAADXM/JpwsJeSpCg8/s1600/dnsquery.png" alt="" style="width:433px;height:357px"/&gt;&lt;figcaption class="wp-element-caption"&gt;DNS resolution steps&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;DNS uses UDP protocol and it can generate a lot of traffic (TCP is impractical. If implemented in TCP, it would have required 44 packet for a DNS query, which is very expensive considering DNS query is just a precursor of the real traffic)&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Anycast DNS&lt;/strong&gt; &amp;#8211; any one of a number of DNS servers can respond to DNS queries, and typically the one that is geographically closest will provide the response. This reduces latency, improves uptime for the DNS resolving service and provides protection against DNS flood DDoS attacks.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;DNS record types&lt;/strong&gt;:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;A record: domain name to IP address. DNS service round robin across multiple A records&lt;/li&gt;&#10;&lt;li&gt;AAAA (quad A) record: domain name to IPv6 address&lt;/li&gt;&#10;&lt;li&gt;CNAME: redirect traffic from one domain to another (e.g. test.com to www.test.com so you can minimize IP references)&lt;/li&gt;&#10;&lt;li&gt;MX record&lt;/li&gt;&#10;&lt;li&gt;SRV record&lt;/li&gt;&#10;&lt;li&gt;TXT record: originally for human consumption, freeform text for configuration purpose.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;A FQDN (fully qualified domain name) can have up to 127 domains, but only three in most cases. (i.e. subdomain.domain.topleveldomain)&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;DNS zones&lt;/strong&gt; &amp;#8211; allow for easier control over multiple levels of a domain. DNS zones are configured in zone files. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Domains vs zones&lt;/strong&gt; &amp;#8211; Domains are broken into zones for which individual DNS servers are responsible. A domain represents the entire set of names/machines that are contained under an organizational domain name. For example, all domain names ending with &amp;#8220;.com&amp;#8221; are part of the &amp;#8220;com&amp;#8221; domain. A &amp;#8220;zone&amp;#8221; is a domain less any sub-domains delegated to other DNS servers. A DNS server could be responsible (authoritative) for all records under the &amp;#8220;xyz.com&amp;#8221; domain, but by defining NS-records for &amp;#8220;abc.xyz.com&amp;#8221;, this part of the domain is delegated to other DNS servers &amp;#8211; and possibly a different company/entity. A zone contains exactly one SOA-record describing the general properties of the zone, and any number of other DNS records. Entire zones can transferred from a primary DNS server to secondary DNS servers through Zone Transfers. A domain administrator would be responsible for creating zones, and delegating responsibility for these zones to an administrator and DNS server.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-full"&gt;&lt;img loading="lazy" decoding="async" width="597" height="529" src="https://www.digihunch.com/wp-content/uploads/2024/07/DNS-Zones-Illustration.jpg" alt="" class="wp-image-11546" srcset="https://www.digihunch.com/wp-content/uploads/2024/07/DNS-Zones-Illustration.jpg 597w, https://www.digihunch.com/wp-content/uploads/2024/07/DNS-Zones-Illustration-300x266.jpg 300w" sizes="auto, (max-width: 597px) 100vw, 597px" /&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Reverse DNS lookup&lt;/strong&gt; &amp;#8211; query for FQDN by IP. This is commonly used by email servers where anti-spam mechanism on the receiver needs to validate that sender&amp;#8217;s IP is associated with a domain as claimed. This is also used in logging application to convert IP into human-readable domains in the log data. Reverse DNS lookups query DNS server for a PTR (pointer reserve record). If the server does not have a PTR record, it cannot resolve a reverse lookup.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;DHCP&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;DHCP operates at application layer and helps you to configure&amp;nbsp; IP automatically with a lease, through automatic allocation, or fixed allocation based on MAC, etc. DHCP process involves address allocation, renewal, and release. Address allocation takes four steps:&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&#10;&lt;li&gt;Client sends a broadcast to discover DHCP server;&lt;/li&gt;&#10;&lt;li&gt;DHCP server broadcast a DHCP offer;&lt;/li&gt;&#10;&lt;li&gt;Client requests IP address from the DHCP server;&lt;/li&gt;&#10;&lt;li&gt;Server acknowledged the DHCP request;&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Here is an illustration of DHCP address allocation.&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-full"&gt;&lt;img loading="lazy" decoding="async" width="713" height="527" src="https://www.digihunch.com/wp-content/uploads/2024/07/DHCP-address-allocation.gif" alt="" class="wp-image-11548"/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;DHCP can also be used to set NTP address.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;NAT&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Network Address Translation (NAT), can be implemented in many different ways in different OS. Essentially, it is a technology that allows a gateway, usually a router or firewall, to rewrite the source IP of an outgoing IP datagram while retaining the original IP in order to rewrite it into the response.&amp;nbsp; Two categories of NAT are:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Basic NAT: provides a one-to-one translation of IP addresses, aka one-to-one NAT. Basic NATs can be used to interconnect two IP networks that have incompatible addressing.&lt;/li&gt;&#10;&lt;li&gt;One-to-many NAT: maps multiple private hosts to one publicly exposed IP address, aka IP masquerading. This can be a security measure so that no external host can establish to your computer without knowing your actual IP. Source port conflict can be managed in two ways:&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;port preservation: When making outgoing connection, NAT preserves the ephemeral port number used by internal client that initiates the connection; if two clients happen to use the same ephemeral port, then NAT picks a random port to initiate outgoing TCP connection;&lt;/li&gt;&#10;&lt;li&gt;port forwarding (port mapping): Forward traffic to certain destination based on the port of incoming request that NAT receives. &lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img decoding="async" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Internet_port_forwarding.png/800px-Internet_port_forwarding.png" alt="File:Internet port forwarding.png" style="width:521px;height:293px"/&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Proxy&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Proxy refers to a concept rather than a specific implementation. It exists on almost every layer in the network model, and act on behalf of a client in order to access other service. For example, &lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Web proxy used to be used to cache web traffic data in slow Internet but it is not necessary any more because 1) there is not much speed benefit; 2) website today is much more dynamic. &lt;/li&gt;&#10;&lt;li&gt;Reverse proxy is a popular architecture of web server, such as Nginx, to act as a front end of web servers, as well as point of decryption so web servers are free to just serve the content.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;VPN&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;VPN &amp;#8211; allows for extension of a private or local network to host that might not be on that local private network by using encrypted tunnel. There are many flavours of implementation for many purposes. It is a general concept rather than a specific protocol (just like NAT). VPN client provisions the computer with a &lt;span style="text-decoration: underline;"&gt;virtual interface&lt;/span&gt; with an IP that matches the address space of the private network, and establish a VPN tunnel to it. Most VPNs work by using the payload section of transport layer to carry an encrypted payload that actually contains an entire second set of packets: the network, the transport and the application layers of a packet intended to traverse a network. Basically, this payload is carried to the VPN&amp;#8217;s endpoint where all the other layers are stripped away and discarded. Then, the payload is unencrypted, leaving the VPN server with the top three layers of a new packet. This gets encapsulated with the proper datalink layer information and sent across the network. This process is completed in the inverse in the opposite direction. VPN usually requires strict authentication procedures and encryption. VPN can also be used to establish site-to-site connection (aka point-to-point VPN) where individual user doesn&amp;#8217;t have to establish connections on their own. Both sites needs specialized hardware to achieve this. Site-to-site VPN is a good alternative to WAN when two site don&amp;#8217;t need to transfer large amount of data for very fast speed.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;WAN&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Wide Area Network &amp;#8211; act like a single network, but span across multiple physical locations, it requires that you contract the link across the internet with ISP. ISP handles data link from one site to another.&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="586" height="160" src="https://www.digihunch.com/wp-content/uploads/2019/12/image-4.png" alt="" class="wp-image-533"/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Wireless Network&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Wireless protocol (802.11 family) defines how Wifi operates at physical and data link layer. Wifi networks operates on 2.4GHz and 5GHz frequency bands. Wireless frame is fairly different from Ethernet frame due to the nature of wireless transmission.&lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img decoding="async" src="http://static1.squarespace.com/static/55e6d56ee4b0139f372acc16/t/57597dd259827ef6e49d01cf/1465482710010/?format=1500w" alt="Image result for wireless frame&amp;quot;"/&gt;&lt;figcaption class="wp-element-caption"&gt;Wireless frame&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Wireless access point is a device that bridges the wireless and wired portions of a network. A single wired network might have many wireless access points to cover a large area.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Wireless network can be configured in a few main ways:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Ad-hoc network &amp;#8211; nodes all directly speak to each other. No supporting infrastructure is needed but not most common. It can be powerful tool during disasters.&lt;/li&gt;&#10;&lt;li&gt;Wireless LAN (WLAN) &amp;#8211; one or more access points act as abridge between wireless and wired network. This is the most common type in business world where the wired LAN provides link to the Internet.&lt;/li&gt;&#10;&lt;li&gt;Mesh networks &amp;#8211; a hybrid of the two above&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Wireless Security&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Wireless transmission is across the air so encryption is more important. The number of bit in the encryption key corresponds to how secure the encryption is.&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;WEP (encryption technology) provides low level of privacy (40-bit encryption) and it is not preferred today;&lt;/li&gt;&#10;&lt;li&gt;WPA provides 128-bit key encryption; &lt;/li&gt;&#10;&lt;li&gt;WPA2 provides 256-bit key encryption and is most common today.&lt;/li&gt;&#10;&lt;li&gt;MAC filtering also help security in wireless&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Basic networking troubleshooting&lt;/strong&gt;&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;ICMP ping to test general quality of connection;&lt;/li&gt;&#10;&lt;li&gt;traceroute discovers the path between two nodes and give you the information along the way;&lt;/li&gt;&#10;&lt;li&gt;netcat checks port and host address (telnet is retiring);&lt;/li&gt;&#10;&lt;li&gt;nslookup: very powerful in interactive mode for resolution tools;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;IPv6 &lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;IPv4 address running out in November 2019 is a major crisis. IPv6 becomes more critical to implement for many organizations. IPv6 address is very long with numbers. Numbers represents a natural way that computer thinks and operates, but not for human. So IPv6 comes with two rules to shorten the address:&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="289" height="159" src="https://www.digihunch.com/wp-content/uploads/2019/12/image-2.png" alt="" class="wp-image-520"/&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;You may remove any leading 0;&lt;/li&gt;&#10;&lt;li&gt;Any number of consecutive groups can be replaced with two colons;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;IPv6 header looks like below:&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" width="742" height="458" src="https://www.digihunch.com/wp-content/uploads/2019/12/image-3.png" alt="" class="wp-image-521" style="width:523px;height:323px"/&gt;&lt;figcaption class="wp-element-caption"&gt;IPv6 header&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Coexistence &amp;#8211; the optimal approach for existing networks is to focus not on transition but on coexistence. Coexistence may live a long period with these phases: 1) Turn on IPv6 routing in their existing IPv4 networks and start using it; 2) Contract IPv6 service with their upstream, peer, and downstream neighbours; 3) Use the IPv6 protocol in addition to IPv4 in their applications and services both on server equipment and on their clients; 4) turn off IPv4 at some point when it is no longer a business requirement.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/11/storage-nitty-gritty-5-of-5-replication/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Storage Nitty-Gritty 5 of 5 – Replication&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/12/networking-basics-3-of-3-common-network-technologies/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Networking Basics 3 of 3 – common network protocols and technologies&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Storage Nitty-Gritty 5 of 5 – Replication</title><link>https://www.digihunch.com/2019/11/storage-nitty-gritty-5-of-5-replication/</link><pubDate>Tue, 19 Nov 2019 00:10:23 -0400</pubDate><guid>https://www.digihunch.com/2019/11/storage-nitty-gritty-5-of-5-replication/</guid><description>&lt;h4 class="wp-block-heading"&gt;Replication Terms&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;PIT (point in time) replica&lt;/strong&gt; &amp;#8211; snapshot of the source at some specific timestamp;&lt;br&gt;&lt;strong&gt;Continuous Replica&lt;/strong&gt; &amp;#8211; always in-sync with the production data;&lt;br&gt;&lt;strong&gt;Recoverability &lt;/strong&gt;&amp;#8211; enables restoration of data from the replica to the source if data loss or corruption occurs;&lt;br&gt;&lt;strong&gt;Restartability&lt;/strong&gt; &amp;#8211; enables restarting business operations using the replicas;&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading"&gt;Local Replication &lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Use Case&lt;/strong&gt;:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;Alternative source for backup&lt;/li&gt;&lt;li&gt;Fast recovery&lt;/li&gt;&lt;li&gt;Decision-support activities such as data warehousing&lt;/li&gt;&lt;li&gt;Testing platform&lt;/li&gt;&lt;li&gt;Data migration&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Consistency in file system replication &lt;/strong&gt;&lt;br&gt;File systems buffer the data in the host memory to improve the application response time. The buffered data is periodically written to the disk. In UNIX operating systems, &lt;span style="text-decoration: underline;"&gt;sync daemon&lt;/span&gt; is the process that flushes the buffers to the disk at set intervals. In some cases, the replica is created between the set intervals, which might result in the creation of an inconsistent replica. Therefore, host memory buffers must be flushed to ensure data consistency on the replica, prior to its creation.&lt;br&gt;&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="545" height="346" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-64.png" alt="" class="wp-image-413"/&gt;&lt;figcaption&gt;Flushing the file system buffer&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;br&gt;In the illustration above, If the host memory buffers are not flushed, the data on the replica will not contain the information that was buffered in the host. If the file system is unmounted before creating the replica, the buffers will be automatically flushed and the data will be consistent on the replica.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Consistency in database replication&lt;/strong&gt;&lt;br&gt;When a database is replicated while it is online, changes made to the database at this time must be applied to the replica to make it consistent. A consistent replica of an online database is created by using the dependent write I/O principle or by holding I/Os momentarily to the source before creating the replica.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;A dependent write I/O principle is inherent in many applications and database management systems (DBMS) to ensure consistency. According to this principle, a write I/O is not issued by an application until a prior related write I/O has completed. For example, a data write is dependent on the successful completion of the prior log write.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;For a transaction to be deemed complete, databases require a series of writes to have occurred in a particular order. These writes will be recorded on the various devices or file systems.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Another way to ensure consistency is to make sure that the write I/O to all&lt;br&gt;source devices is held for the duration of creating the replica. This creates a&lt;br&gt;consistent image on the replica. However, databases and applications might time out if the I/O is held for too long.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Local Replication Technologies&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Host-based Local Replication&lt;/strong&gt;&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;LVM-based replication: logical volume manager (LVM) is responsible for creating and controlling the host-level logical volumes. Each logical block in a logical volume is mapped to two physical blocks on two different physical volumes. LVM-based replication is part of operating system and comes without additional license cost. However, every write generated by application translates into two writes on the disk, and thus, an additional burden is placed on the host CPU. This can degrade application performance. Presenting an LVM-based logical replica to another host is usually not possible because the replica will still be part of the volume group, which is accessed by one host at any given time. You can&amp;#8217;t track changes on LVMs either so it does not support incremental resynchronization.&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;File system snapshot: a pointer-based replica that requires a fraction of the space used by the production FS. This snapshot can be implemented by either FS or by LVM. It uses the Copy on First Write (CoFW) principle to create snapshot. When a snapshot is created, a bitmap and blockmap are created in the metadata of the Snap FS. The bitmap is used to keep track of blocks that are changed on the production FS after the snap creation. The blockmap is used to indicate the exact address from which the data is to be read when the data is accessed from the Snap FS. Immediately after the creation of the FS snapshot, all reads from the snapshot are actually served by reading the production FS. In a CoFW mechanism, if a write I/O is issued to the production FS for the fi rst time after the creation of a snapshot, the I/O is held and the original data of production FS corresponding to that location is moved to the Snap FS. Then, the write is allowed to the production FS. The bitmap and blockmap are updated accordingly. Subsequent writes to the same location do not initiate the CoFW activity. To read from the Snap FS, the bitmap is consulted. If the bit is 0, then the read is directed to the production FS. If the bit is 1, then the block address is obtained from the blockmap, and the data is read from that address on the Snap FS. Read requests from the production FS work as normal.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="560" height="384" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-68.png" alt="" class="wp-image-417"/&gt;&lt;figcaption&gt;File system snapshot&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Storage Array-based local replication&lt;/strong&gt;&lt;br&gt;the array-operating environment performs the local replication process. The host resources, such as the CPU and memory, are not used in the replication process. Consequently, the host is not burdened by the replication operations. The replica can be accessed by an alternative host for other business operations.&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;Full-Volume Mirroring&lt;/strong&gt; &amp;#8211; the target is attached to the source and established as a mirror of the source. After all the data is copied and both the source and the target contain identical data, the target can be considered as a mirror of the source. After the synchronization is complete, the target can be detached from the source and made available for other business operations. The target becomes a point-in-time (PIT) copy of the source. After detachment, changes made to both the source and replica can be tracked at some predefined granularity. This enables incremental resynchronization (source to target) or incremental restore (target to source). The granularity of the data change can range from 512 byte blocks to 64 KB blocks or higher.&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="493" height="482" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-69.png" alt="" class="wp-image-418"/&gt;&lt;figcaption&gt;Full volume mirroring&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;Pointer-based, Full-Volume Replication&lt;/strong&gt; &amp;#8211; the target is immediately accessible by the BC host after the replication session is activated. Therefore, data synchronization and detachment of the target is not required to access it.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;Pointer-based, Virtual Replication&lt;/strong&gt; &amp;#8211; at the time of the replication session activation, the target contains pointers to the location of the data on the source. The target does not contain data at any time. Therefore, the target is known as a virtual replica. the target is immediately accessible after the replication session activation. A protection bitmap is created for all data blocks on the source device. Granularity of data blocks can range from 512 byte blocks to 64 KB blocks or greater.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Network-based local replication&lt;/strong&gt;: the replication occurs at the network layer between host and storage arrays. By offloading replication from servers and arrays, network-based replication can work across a large number of server platforms and storage arrays, making it ideal for highly heterogeneous environments.&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;Continuous Data Protection&lt;/strong&gt;: CDP provides the ability to restore data to any previous PIT. In CDP, data changes are continuously captured and stored in a separate location from the primary storage. With CDP, recovery from data corruption poses no problem because it allows going back to a PIT image prior to the data corruption incident. CDP uses a journal volume to store all data changes on the primary storage. The journal volume contains all the data that has changed from the time the replication session started. The amount of space that is configured for the journal determines how far back the recovery points can go. CDP appliance is an intelligent hardware platform that runs the CDP software and manages local and remote data replications. Write splitters intercept writes to the production volume from the host and split each write into two copies. Write splitting can be performed at the host, fabric, or storage array.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;CDP Local Replication Operation&lt;/strong&gt;: before the start of replication, the replica is synchronized with the source and then the replication process starts. After the replication starts, all the writes to the source are split into two copies. One of the copies is sent to the CDP appliance and the other to the production volume. When the CDP appliance receives a copy of a write, it is written to the journal volume along with its timestamp. As a next step, data from the journal volume is sent to the replica at predefi ned intervals.&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-70.png" alt="" class="wp-image-419" width="385" height="361"/&gt;&lt;figcaption&gt;Continuous Data Protection&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Tracking Changes to Source and Replica&lt;/strong&gt;&lt;br&gt;Changes can occur on the replica device if it is used for other business operations. To enable incremental resynchronization or restore operations, changes to both the source and replica devices after the PIT should be tracked.&lt;br&gt;This is typically done using bitmaps, where each bit represents a block of data. For example, if the block size is 32 KB, then a 1-GB device would require 32,768 bits (1 GB divided by 32 KB). The size of the bitmap would be 4 KB. If the data in any 32 KB block is changed, the corresponding bit in the bitmap is flagged. If the block size is reduced for tracking purposes, then the bitmap size increases correspondingly.&lt;br&gt;The bits in the source and target bitmaps are all set to 0 (zero) when the replica is created. Any changes to the source or replica are then fl agged by setting the appropriate bits to 1 in the bitmap. When resynchronization or restore is required, a logical OR operation between the source bitmap and the target bitmap is performed. The bitmap resulting from this operation references all blocks that have been modifi ed in either the source or replica.&lt;br&gt;This enables an optimized resynchronization or a restore operation because it eliminates the need to copy all the blocks between the source and the replica. The direction of data movement depends on whether a resynchronization or a restore operation is performed.&lt;br&gt;If resynchronization is required, changes to the replica are overwritten with the corresponding blocks from the source. If a restore is required, changes to the source are overwritten with the corresponding blocks from the replica.&lt;br&gt;If a restore is required, changes to the source are overwritten with the corresponding blocks from the replica.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="486" height="522" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-71.png" alt="" class="wp-image-420"/&gt;&lt;figcaption&gt;Tracking Changes&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="561" height="354" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-72.png" alt="" class="wp-image-421"/&gt;&lt;figcaption&gt;Comparison of local replication technologies&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Local Replication in a Virtualized Environment&lt;/strong&gt;&lt;br&gt;Typically, local replication of VMs is performed by the hypervisor at the compute level. However, it can also be performed at the storage level using array-based local replication, similar to the physical environment. In the array-based method, the LUN on which the VMs reside is replicated to another LUN in the same array. VM Snapshot captures the state and data of a running virtual machine at a specifi c point in time. The VM state includes VM files, such as BIOS, network confi guration, and its power state (powered-on, powered-off, or suspended). The VM data includes all the files that make up the VM, including virtual disks and memory. A VM Snapshot uses a separate delta file to record all the changes to the virtual disk since the snapshot session is activated. Snapshots are useful when a VM needs to be reverted to the previous state in the event of logical corruptions. Reverting a VM to a previous state causes all settings confi gured in the guest OS to be reverted to that PIT when that snapshot was created. There are some challenges associated with the VM Snapshot technology. It does not support data replication if a virtual machine accesses the data by using raw disks. Also, using the hypervisor to perform snapshots increases the load on the compute and impacts the compute performance.&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading"&gt;Remote Replication&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Synchronous remote replication &amp;#8211; writes must be committed to the source and remote replica (or target), prior to acknowledging &amp;#8220;write complete&amp;#8221; to the host. Additional writes on the source cannot occur until each preceding write has been completed and acknowledged. This ensures that data is identical on the source and replica at all times. Further, writes are transmitted to the remote site exactly in the order in which they are received at the source. Therefore, write ordering is maintained. If a source-site failure occurs, synchronous remote replication provides zero or near-zero RPO. However, application response time is increased with synchronous remote replication because writes must be committed on both the source and target before sending the “write complete” acknowledgment to the host. The degree of impact on response time depends primarily on the distance between sites, bandwidth, and quality of service (QOS) of the network connectivity infrastructure.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="507" height="334" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-73.png" alt="" class="wp-image-422"/&gt;&lt;figcaption&gt;Synchronous replication&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In asynchronous remote replication, a write is committed to the source and immediately acknowledged to the host. In this mode, data is buffered at the source and transmitted to the remote site later. Asynchronous replication eliminates the impact to the application’s response time because the writes are acknowledged immediately to the source host. This enables deployment of asynchronous replication over distances ranging from several hundred to several thousand kilometers between the primary and remote sites.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="462" height="324" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-74.png" alt="" class="wp-image-423"/&gt;&lt;figcaption&gt;Asynchronous replication&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Below are the bandwith requirement for both:&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="503" height="297" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-75.png" alt="" class="wp-image-424"/&gt;&lt;figcaption&gt;Bandwidth requirement for synchronous replication&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="538" height="269" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-76.png" alt="" class="wp-image-425"/&gt;&lt;figcaption&gt;Bandwidth requirement for asynchonous replication&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Asynchronous replication implementation can also take advantage of locality of reference (repeated writes to the same location). If the same location is written multiple times in the buffer prior to transmission to the remote site, only the final version of the data is transmitted. This feature conserves link bandwidth.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Remote Replication Technologies&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Host-Based Remote Replication&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;LVM-based remote replication&lt;/strong&gt;: performed and managed at the volume group level. Writes to the source volumes are transmitted to the remote host by the LVM. The LVM on the remote host receives the writes and commits them to the remote volume group.&lt;br&gt;LVM-based remote replication supports both synchronous and asynchronous modes of replication. LVM-based remote replication is independent of the storage arrays and therefore supports replication between heterogeneous storage arrays.&lt;br&gt;The replication process adds overhead on the host CPUs. CPU resources on the source host are shared between replication tasks and applications. Because the remote host is also involved in the replication process, it must be continuously up and available.&lt;br&gt;&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="563" height="351" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-77.png" alt="" class="wp-image-426"/&gt;&lt;figcaption&gt;LVM based remote replication&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Host-Based Log Shipping&lt;/strong&gt;&lt;br&gt;Database replication via log shipping is a host-based replication technology supported by most databases. Transactions to the source database are captured in logs, which are periodically transmitted by the source host to the remote host. The remote host receives the logs and applies them to the remote database.&lt;br&gt;RPO at the remote site is fi nite and depends on the size of the log and the frequency of log switching. Available network bandwidth, latency, rate of updates to the source database, and the frequency of log switching should be considered when determining the optimal size of the log file. Host-based log shipping requires low network bandwidth because it transmits only the log fi les at regular intervals.&lt;br&gt;&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="562" height="358" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-78.png" alt="" class="wp-image-427"/&gt;&lt;figcaption&gt;Host based log shipping&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Storage Array-Based Remote Replication&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Synchronous replication mode&lt;br&gt;To optimize the replication process and to minimize the impact on application response time, the write is placed on cache of the two arrays. The intelligent storage arrays destage these writes to the appropriate disks later.&lt;br&gt;If the network links fail, replication is suspended; however, production work can continue uninterrupted on the source storage array. The array operating environment keeps track of the writes that are not transmitted to the remote storage array. When the network links are restored, the accumulated data is transmitted to the remote storage array. During the time of network link outage, if there is a failure at the source site, some data will be lost, and the RPO at the target will not be zero.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="561" height="309" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-79.png" alt="" class="wp-image-428"/&gt;&lt;figcaption&gt;Array-based remote synchronous replication&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Asynchronous replication mode Fig 12-8&lt;br&gt; Data is buffered at the source and transmitted to the remote site later. The source and the target devices do not contain identical data at all times. The data on the target device is behind that of the source, so the RPO in this case is not zero. Asynchronous replication writes are placed in cache on the two arrays and are later destaged to the appropriate disks. Some implementations of asynchronous remote replication maintain write ordering. A timestamp and sequence number are attached to each write when it is received by the source. Writes are then transmitted to the remote array, where they are committed to the remote replica in the exact order in which they were buffered at the source. This implicitly guarantees consistency of data on the remote replicas.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="580" height="297" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-80.png" alt="" class="wp-image-429"/&gt;&lt;figcaption&gt;Array-based asynchronous replication&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Disk-buffered replication mode: a combination of local and remote technologies. A consistent PIT local replica of the source device is fi rst created. This is then replicated to a remote replica on the target array.&lt;br&gt; At the beginning of the cycle, the network links between the two arrays are suspended, and there is no transmission of data. While production application runs on the source device, a consistent PIT local replica of the source device is created. The network links are enabled, and data on the local replica in the source array transmits to its remote replica in the target array.&lt;br&gt;&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="566" height="337" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-81.png" alt="" class="wp-image-430"/&gt;&lt;figcaption&gt;Disk buffered remote replication&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Network-based Remote Replication&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;CDP remote replication&lt;br&gt; Fig 12-10&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Three site replication&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;Cascade/Multihop: data fl ows from the source to the intermediate storage array, known as a bunker, in the fi rst hop, and then from a bunker to a storage array at a remote site in the second hop. Replication between the source and the remote sites can be performed in two ways: synchronous + asynchronous or synchronous + disk buffered. Replication between the source and bunker occurs synchronously, but replication between the bunker and the remote site can be achieved either as disk-buffered mode or asynchronous mode.&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="561" height="479" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-82.png" alt="" class="wp-image-431"/&gt;&lt;figcaption&gt;Three-site remote replication cascade/multihop&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;Triangle/Multitarget: data at the source storage array is concurrently replicated to two different arrays at two different sites. The source-to-bunker site (target 1) replication is synchronous with a near-zero RPO. The source-to-remote site (target 2) replication is asynchronous with an RPO in the order of minutes. The distance between the source and the remote sites could be thousands of miles. The key benefit of three-site triangle/multitarget replication is the ability to failover to either of the two remote sites in the case of source-site failure, with disaster recovery (asynchronous) protection between the bunker and remote sites.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="561" height="474" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-83.png" alt="" class="wp-image-432"/&gt;&lt;figcaption&gt;Three-site replication triangle/multitarget&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Data migration solutions&lt;br&gt;Data mobility refers to moving data between heterogeneous storage arrays for cost, performance, or any other reason. It helps implement a tiered storage strategy. &lt;br&gt;Data migration refers to moving data from one storage array to other heterogeneous storage arrays for technology refresh, consolidation, or any other reason. The array performing the replication operations is called the control array.&lt;br&gt;Data migration solutions perform push and pull operations for data movement.&lt;br&gt;These terms are defined from the perspective of the control array. In the push operation, data is moved from the control array to the remote array.&lt;br&gt;The control device, therefore, acts like the source, while the remote device is the target.&lt;br&gt;In the pull operation, data is moved from the remote array to the control array.&lt;br&gt;The remote device is the source, and the control device is the target.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The push and pull operations can be either hot or cold. These terms apply to the control devices only. In a cold operation the control device is inaccessible to the host during replication. Cold operations guarantee data consistency because both the control and the remote devices are offl ine. In a hot operation the control device is online for host operations. During hot push and pull operations, changes can be made to the control device because the control array can keep track of all changes and thus ensure data integrity.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Remote replication and migration in a virtualized environment&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In hypervisor-to-hypervisor VM migration, the entire active state of a VM is moved from one hypervisor to another. This method involves copying the contents of virtual machine memory from the source hypervisor to the target and then transferring the control of the VM’s disk fi les to the target hypervisor. Because the virtual disks of the VMs are not migrated, this technique requires both source and target hypervisor access to the same storage.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-84.png" alt="" class="wp-image-433" width="353" height="267"/&gt;&lt;figcaption&gt;Hypervisor-to-hypervisor VM migration&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In array-to-array VM migration, virtual disks are moved from the source&lt;br&gt; array to the remote array. This approach enables the administrator to move VMs across dissimilar storage arrays. Array-to-array migration starts by copying the metadata about the VM from the source array to the target. The metadata essentially consists of configuration, swap, and log files. After the metadata is copied, the VM disk file is replicated to the new location.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-85.png" alt="" class="wp-image-434" width="402" height="371"/&gt;&lt;figcaption&gt;Array-to-array VM migration&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading"&gt;Related Postings&lt;/h4&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/03/storage-nitty-gritty-1-5/"&gt;Disk and RAID&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/05/storage-nitty-gritty-2-5/"&gt;SAN&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/07/storage-nitty-gritty-3-of-5-nas-and-object-storage/"&gt;NAS and Object Storage&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/10/storage-nitty-gritty-4-of-5-backup-and-archive-solutions/"&gt;Backup and Archive Solution&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/11/networking-basics-layer-1-and-layer-2/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Networking Basics 1 of 3 – Layer 1 through Layer 3&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/12/tcp-ip-basics-2-of-3-layer-4-and-common-technologies/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Networking basics 2 of 3 – Layer 4 and common network configurations&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Networking Basics 1 of 3 – Layer 1 through Layer 3</title><link>https://www.digihunch.com/2019/11/networking-basics-layer-1-and-layer-2/</link><pubDate>Sun, 10 Nov 2019 20:18:00 -0400</pubDate><guid>https://www.digihunch.com/2019/11/networking-basics-layer-1-and-layer-2/</guid><description>&lt;p class="wp-block-paragraph"&gt;What layer model works the best? Back in university my textbook was based on OSI 7-layer model. It is rigorously defined and often used in academics. When it comes to day-to-day operation, the 5-layer TCP/IP model is more useful. It combines Application, Presentation and Session layers in OSI model into a single Application layer.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&#10;&lt;table id="tablepress-1" class="tablepress tablepress-id-1"&gt;&#10;&lt;thead&gt;&#10;&lt;tr class="row-1"&gt;&#10;&#9;&lt;th class="column-1"&gt;Layer&lt;/th&gt;&lt;th class="column-2"&gt;Name&lt;/th&gt;&lt;th class="column-3"&gt;Protocol&lt;/th&gt;&lt;th class="column-4"&gt;Protocol Data Unit&lt;/th&gt;&lt;th class="column-5"&gt;Addressing&lt;/th&gt;&lt;th class="column-6"&gt;Device&lt;/th&gt;&lt;th class="column-7"&gt;Description&lt;/th&gt;&#10;&lt;/tr&gt;&#10;&lt;/thead&gt;&#10;&lt;tbody class="row-striping row-hover"&gt;&#10;&lt;tr class="row-2"&gt;&#10;&#9;&lt;td class="column-1"&gt;5&lt;/td&gt;&lt;td class="column-2"&gt;Application&lt;/td&gt;&lt;td class="column-3"&gt;HTTP, FTP, etc&lt;/td&gt;&lt;td class="column-4"&gt;Message&lt;/td&gt;&lt;td class="column-5"&gt;N/A&lt;/td&gt;&lt;td class="column-6"&gt;N/A&lt;/td&gt;&lt;td class="column-7"&gt;&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr class="row-3"&gt;&#10;&#9;&lt;td class="column-1"&gt;4&lt;/td&gt;&lt;td class="column-2"&gt;Transport&lt;/td&gt;&lt;td class="column-3"&gt;TCP and UDP&lt;/td&gt;&lt;td class="column-4"&gt;Segment&lt;/td&gt;&lt;td class="column-5"&gt;Port Number&lt;/td&gt;&lt;td class="column-6"&gt;Gateway&lt;/td&gt;&lt;td class="column-7"&gt;Sort out which application on the same host receives incoming data&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr class="row-4"&gt;&#10;&#9;&lt;td class="column-1"&gt;3&lt;/td&gt;&lt;td class="column-2"&gt;Network&lt;/td&gt;&lt;td class="column-3"&gt;IP&lt;/td&gt;&lt;td class="column-4"&gt;Datagram&lt;/td&gt;&lt;td class="column-5"&gt;IP address&lt;/td&gt;&lt;td class="column-6"&gt;Router and (layer-3) switch&lt;/td&gt;&lt;td class="column-7"&gt;Allows devices across different networks to talk to each other&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr class="row-5"&gt;&#10;&#9;&lt;td class="column-1"&gt;2&lt;/td&gt;&lt;td class="column-2"&gt;Data Link&lt;/td&gt;&lt;td class="column-3"&gt;Ethernet, WiFi&lt;/td&gt;&lt;td class="column-4"&gt;Frame&lt;/td&gt;&lt;td class="column-5"&gt;MAC address&lt;/td&gt;&lt;td class="column-6"&gt;Bridge and (layer-2) Switch&lt;/td&gt;&lt;td class="column-7"&gt;Defines common way of interpreting signals so devices in the network can communicate&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr class="row-6"&gt;&#10;&#9;&lt;td class="column-1"&gt;1&lt;/td&gt;&lt;td class="column-2"&gt;Physical&lt;/td&gt;&lt;td class="column-3"&gt;10baseT, 802.11&lt;/td&gt;&lt;td class="column-4"&gt;bit&lt;/td&gt;&lt;td class="column-5"&gt;N/A&lt;/td&gt;&lt;td class="column-6"&gt;Hub&lt;/td&gt;&lt;td class="column-7"&gt;Hardware: cables, signal connector&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;!-- #tablepress-1 from cache --&gt;&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-physical-layer"&gt;Physical Layer&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Crosstalk &lt;/strong&gt;&amp;#8211; electrical pulse on one wire is accidentally detected on another wire. This was a common challenge when the industry started. The most common cable is &lt;a href="https://networkencyclopedia.com/unshielded-twisted-pair-utp-cabling/"&gt;UTP &lt;/a&gt;(Unshielded Twisted Pair) cable such as Cat 5, Cat 5e cables.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Hub &lt;/strong&gt;&amp;#8211; a physical layer device that allow for connectivity from many computers at once. It is up to each device to determine if incoming data is for them, or to ignore it. Because this slows down transmission, hubs are hardly used any more. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Collision domain&lt;/strong&gt; &amp;#8211; A network segment where only one device can communicate at a time. The device sending signal is occupying the entire media, within its time-sharing window. All devices connected to a hub are in the same collision domain. Ethernet nodes use CSMA/CD to detect collisions and re-transmit when the wire becomes available again. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Wireless Channels&lt;/strong&gt; &amp;#8211; individual, smaller sections of the overall frequency band used by a wireless network. Collision is very common in wireless communication. So the channel selection should minimize collision. &lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-data-link-layer"&gt;Data Link Layer&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In a LAN, NICs talk to each other via MAC address (first 3 octets is organization unique identifier; the last 3 octets are assigned by vendor). Two NICs communicate through twisted pair cable in one of the following modes:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Simplex: data is sent in one directly only; &lt;/li&gt;&#10;&lt;li&gt;Half duplex: one line and transmission in each direction takes turns; &lt;/li&gt;&#10;&lt;li&gt;Full duplex: two lines, one for each direction, simultaneous; &lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Network Switch &lt;/strong&gt;&amp;#8211; connects to many devices as well but it determines which device the data is intended for and only send that data to that device. Switch is a layer-2 device. (However today as a network device, many switches have layer-3 capability so it is important to be specific when talking about switch)&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Ethernet Frame Format&lt;/strong&gt;&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="600" height="395" src="https://www.digihunch.com/wp-content/uploads/2019/12/ethernet-header-600x395-1.png" alt="" class="wp-image-494"/&gt;&lt;figcaption class="wp-element-caption"&gt;Ethernet Frame&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Ethernet address types&lt;/strong&gt;:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Unicast address: points to one receiving end; it contains a unique MAC address the frame is intended for;&lt;/li&gt;&#10;&lt;li&gt;Multicast address: multicast frame is identified by FF as the first 8-bit, followed by a 4-bit flag field, a 4-bit scope field, and a 112-bit group ID.&lt;/li&gt;&#10;&lt;li&gt;Broadcast address: for special destination such as ARP; it contains all Fs in the destination address.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Ethernet frame types&lt;/strong&gt; include, but not limited to:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Ethernet II frame (most common type in use today used directly by the Internet Protocol)&lt;/li&gt;&#10;&lt;li&gt;Novell raw IEEE 802.3 non-standard variation frame&lt;/li&gt;&#10;&lt;li&gt;IEEE 802.2 Logical Link Control (LLC) frame&lt;/li&gt;&#10;&lt;li&gt;IEEE 802.2 Subnetwork Access Protocol (SNAP) frame&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Virtual LAN&lt;/strong&gt; &amp;#8211; any broadcast domain that is partitioned and isolated in a computer network at the data link layer. It is a technique that allows you to have multiple logical LANs operating on the same physical equipment, to segregate traffic.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-network-layer"&gt;Network Layer&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Router &lt;/strong&gt;connects between LANs. A router needs at least two NICs. The steps to route are:&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&#10;&lt;li&gt;Receive data packet&lt;/li&gt;&#10;&lt;li&gt;Examines destination IP&lt;/li&gt;&#10;&lt;li&gt;Look up IP destination network in routing table&lt;/li&gt;&#10;&lt;li&gt;Forward traffic to destination;&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Routing can be complex but it is mostly handled by ISPs now. A routing table may have millions of rows (use route command to check). Here is an example of &lt;strong&gt;routing tables&lt;/strong&gt;. &lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="712" height="346" src="https://www.digihunch.com/wp-content/uploads/2019/12/Capture.png" alt="" class="wp-image-503"/&gt;&lt;figcaption class="wp-element-caption"&gt;Example of routing table&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Autonomous system&lt;/strong&gt; &amp;#8211; a collection of networks that fall under the control of a single network operator (i.e. large corporation)&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Routing protocol&lt;/strong&gt; &amp;#8211; specifies how routers communicate with each other, distributing information that enables them to select routes between any two nodes on a computer network. Interior Gateway Protocols are used by routers to share routing information within a single autonomous system. Exterior Gateway protocols are used across autonomous system. &lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Interior Gateway Protocol (link-state routing): OSPF, IS-IS&lt;/li&gt;&#10;&lt;li&gt;Interior Gateway Protocol (distance-vector): RIP, RIPv2, IGRP&lt;/li&gt;&#10;&lt;li&gt;Exterior Gateway Protocol: BGP (Border Gateway Protocol) &amp;#8211; allows routers (e.g. Internet) to learn from each other about the most optimal paths to forward traffic. &lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;IP datagram&lt;/strong&gt;&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="500" height="334" src="https://www.digihunch.com/wp-content/uploads/2019/12/ip.jpg" alt="" class="wp-image-504"/&gt;&lt;figcaption class="wp-element-caption"&gt;IP datagram (payload at the bottom)&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;An IP datagram contains a lot more compared to Ethernet frames. One place called type of service field (8-bits) specifies priority. QoS technologies are mostly built on this field, to allow routers to determine which datagram is more important.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;IP Fragmentation&lt;/strong&gt;: an Internet Protocol (IP) process that breaks packets into smaller pieces (fragments), so that the resulting pieces can pass through a link with a smaller maximum transmission unit (MTU) than the original packet size. The fragments are reassembled by the receiving host. If a receiving host receives a fragmented IP packet, it has to reassemble the packet and pass it to the higher protocol layer. Reassembly is intended to happen in the receiving host but in practice it may be done by an intermediate router, for example, network address translation (NAT) may need to reassemble fragments in order to translate data streams.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;IP address class&lt;/p&gt;&#10;&lt;figure class="wp-block-gallery aligncenter has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex"&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="575" height="356" data-id="505" src="https://www.digihunch.com/wp-content/uploads/2019/12/ipclass.png" alt="" class="wp-image-505"/&gt;&lt;/figure&gt;&#10;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Non-routable IPv4 address spaces&lt;/strong&gt; belong to no one. Any one can use them in their &lt;a href="https://www.arin.net/reference/research/statistics/address_filters/"&gt;private network&lt;/a&gt;:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;192.168.0.0/16&lt;/li&gt;&#10;&lt;li&gt;172.16.0.0/12&lt;/li&gt;&#10;&lt;li&gt;10.0.0.0/8&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Subnetting&lt;/strong&gt; &amp;#8211; splitting large network into smaller ones. Incorrect subnetting setups are a common problem you might run into as an IT support. Each subnet has their ingress routers, subnet ID and subnet mask. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;CIDR &lt;/strong&gt;is a better way to describe subnet because router only need one entry in their routing table to know where to deliver the traffic.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;NAT &lt;/strong&gt;allows communicate between non-routable addresses.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;ARP &lt;/strong&gt;(address resolution protocol) table &amp;#8211; maps IP address to MAC address. It is kept on each device (run arp -a to check) and expires after short period of time.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/10/clean-up-your-git-repository/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Clean up Git repository&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/11/storage-nitty-gritty-5-of-5-replication/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Storage Nitty-Gritty 5 of 5 – Replication&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Clean up Git repository</title><link>https://www.digihunch.com/2019/10/clean-up-your-git-repository/</link><pubDate>Sat, 26 Oct 2019 20:33:00 -0400</pubDate><guid>https://www.digihunch.com/2019/10/clean-up-your-git-repository/</guid><description>&lt;p class="wp-block-paragraph"&gt;A BitBucket repo has a hard limit of 2GB in size, and soft limit of 1GB. This is&amp;nbsp;&lt;a href="https://confluence.atlassian.com/bitbucket/what-kind-of-limits-do-you-have-on-repository-file-size-273877699.html"&gt;not expandable&lt;/a&gt;&amp;nbsp;as per&amp;nbsp;Bitbucket and contributors will start receiving warnings once soft limit is reached. We can tell the usage of a repo from the landing page of the repo in BitBucket.&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2020/03/git.png" alt="" class="wp-image-694" width="202" height="300"/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Git is a distributed version control system for source code management, which implies the followings:&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&#10;&lt;li&gt;It is intended for source code, or configuration code; but not for storing build artifacts, or installers;&lt;/li&gt;&#10;&lt;li&gt;Git remembers every single commit, including the ones associated with large files;&lt;/li&gt;&#10;&lt;li&gt;Even a contributor deletes a large file (&amp;#8220;git rm filename&amp;#8221;) after commit, the large file is only removed from the HEAD. The historical commit still stores the file. After all, the whole point of version control is to survive crazy deletion.&lt;/li&gt;&#10;&lt;li&gt;distributed means that those large files will be pulled down to contributors laptop (waste everybody&amp;#8217;s space although up to 2G:);&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p class="wp-block-paragraph"&gt;With all these implications, shrinking the size of a repo isn&amp;#8217;t as straightforward as just removing large files from current commit. We&amp;#8217;d have to&amp;nbsp;rewrite the commit history. Here are the steps we should take once repo size grows over the soft limit.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-clean-up-remote-orphaned-branches"&gt;Clean up remote orphaned branches&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Removing these branches (remotes/origin/branchname) per se does not free up space. It simplifies the branch structure, leaving /remote/origin/HEAD the only branch left to cleanse for the rest of the steps.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# git push origin --delete branchname&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 class="wp-block-heading" id="h-remove-useless-files-in-current-commit-head"&gt;Remove useless files in current commit (HEAD)&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In this step we remove useless files in current commit. Again we should not expect much space freed because all file committed previously, even deleted, are still stored. They are just now showing up in the working directory. For this step, we can create a separate local dir on Mac:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;mkdir -p /Users/digihunch/repo-cleanup&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;cd /Users/digihunch/repo-cleanup&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Now within the new directory, we create a bare repo and then the full repo:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;git clone --mirror https://gh@bitbucket.org/digihunch/source.git&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;git clone https://gh@bitbucket.org/digihunch/source.git&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Then we dive into the full repo and identify the large files:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;find . -type f -size +1000k -exec ls -lh {} \; |awk &amp;#39;{print $9&amp;#34;:&amp;#34; $5}&amp;#39;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;We can run &amp;#8220;git rm &amp;#8221; against the files identified as too large or deletable. Then commit and push to remote repo. This removes large files from current commit.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-remove-large-file-and-the-relevant-commits-in-the-history"&gt;Remove large file and the relevant commits in the history&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;As previously mentioned, we have to re-write the history so history forget about the large files. After this step, the historical commits that large files are associated with will all be deleted. Compare the two charts below to understand what the effect is:&lt;/p&gt;&#10;&lt;figure class="wp-block-gallery aligncenter has-nested-images columns-default is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex"&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="1206" height="1038" data-id="695" src="https://www.digihunch.com/wp-content/uploads/2020/03/git1.png" alt="" class="wp-image-695"/&gt;&lt;/figure&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="1234" height="852" data-id="700" src="https://www.digihunch.com/wp-content/uploads/2020/03/git2-1.png" alt="" class="wp-image-700"/&gt;&lt;/figure&gt;&#10;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;We can use the bare repo created in the last step, with &amp;#8220;git filter-branch&amp;#8221; tool to cleanse the branch tree. Some advocate as a faster third party tool&amp;nbsp;&lt;a href="https://rtyley.github.io/bfg-repo-cleaner/"&gt;BFG Repo-Cleaner&lt;/a&gt;&amp;nbsp;as a faster, third-party alternative but I usually lean towards native tool.&amp;nbsp;This&amp;nbsp;&lt;a href="https://www.nicoespeon.com/en/2014/04/clean-git-repo-like-a-boss/"&gt;article&lt;/a&gt;&amp;nbsp;explains the command switches.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;git filter-branch -f --tree-filter &amp;#34;rm -rf \large_file.zip&amp;#34; --prune-empty -- --all&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;After this steps the repo should be cleansed. According to this&amp;nbsp;&lt;a href="https://confluence.atlassian.com/bitbucket/reduce-repository-size-321848262.html"&gt;guide&lt;/a&gt;&amp;nbsp;from BitBucket, we still need to contact their support to run a garbage collection for us in order to see the size change. It even takes time for the size to be reflected after garbage collection. This&amp;nbsp;&lt;a href="https://www.saschawillems.de/blog/2017/09/10/how-to-shrink-down-a-github-repository/"&gt;reference&lt;/a&gt;&amp;nbsp;also does great job explaining what we need to do.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-other-contributors-re-sync-history"&gt;Other contributors re-sync history&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;It is important to understand that the step above modifies history. Although the commit hash did not change, they are assigned with different commit-ids and you can tell from the commit history where it displays former commit id.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;This activity only affects remote repository. Each contributor&amp;#8217;s local repository still stores the old commits and should be sync&amp;#8217;ed with the remote origin by deleting the entire repo and run &amp;#8220;git clone&amp;#8221; again. Although not welcomed by every individual contributors, but it is a necessary evil and better approached with explicit instruction.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Because this activity takes higher risks, changes each commit, involves vendor support and requires activities by each contributor, the support team should focus on preventing this from happening instead of fixing it.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-configure-pre-commit-hook-as-a-preventive-measure"&gt;Configure pre-commit hook as a preventive measure&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;As we have more Ansible tasks related, working directory becomes complicated and sometimes contributors accidentally committed large unwanted files (and pushed into the remote repo).&amp;nbsp;Down the road, the best practice is to prevent contributors from committing junks.&amp;nbsp;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The best spot to detect this should be a pre-receive hook on the server side, which is only available with self-hosted Bitbucket Server. Unfortunately, this is not a viable option for&amp;nbsp;&lt;a href="https://community.atlassian.com/t5/Bitbucket-questions/Does-Bitbucket-Cloud-support-git-pre-receive-hooks/qaq-p/950235"&gt;Bitbucket cloud&lt;/a&gt;. Our best bet is client-side pre-commit hook, in which a script&amp;nbsp;performs size check when contributors run &amp;#8220;git commit&amp;#8221;. The purpose is to fail the commit if total file size is over the limit (20M), and the hook itself should be version controlled as well. Compared to (server side) pre-receive hook, the drawback of (client side) pre-commit hook is it requires initial client configuration. The upside is it captures large files before commit.&amp;nbsp;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;This hook can be a shell script as simple as this:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;commitsizelimit&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;20&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;stagedfilelist&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;$(&lt;/span&gt;git diff --name-only --cached&lt;span style="color:#66d9ef"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;stagedfilecnt&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;`&lt;/span&gt;echo &lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;$stagedfilelist&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;| sed &lt;span style="color:#e6db74"&gt;&amp;#39;/^\s*$/d&amp;#39;&lt;/span&gt; |wc -l&lt;span style="color:#e6db74"&gt;`&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; &lt;span style="color:#f92672"&gt;[[&lt;/span&gt; $stagedfilecnt -gt &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#f92672"&gt;]]&lt;/span&gt;; &lt;span style="color:#66d9ef"&gt;then&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; totalcommitsize&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;$(&lt;/span&gt;du -cm $stagedfilelist | tail -1 | cut -f 1&lt;span style="color:#66d9ef"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;# Redirect output to stderr.&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; exec 1&amp;gt;&amp;amp;&lt;span style="color:#ae81ff"&gt;2&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; &lt;span style="color:#f92672"&gt;[[&lt;/span&gt; $totalcommitsize &amp;gt; $commitsizelimit &lt;span style="color:#f92672"&gt;]]&lt;/span&gt;; &lt;span style="color:#66d9ef"&gt;then&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; echo &lt;span style="color:#e6db74"&gt;&amp;#34;Warning: Total size of all files in staging area is &amp;#34;&lt;/span&gt;$totalcommitsize&lt;span style="color:#e6db74"&gt;&amp;#34;MB, exceeding the limit of &amp;#34;&lt;/span&gt;$commitsizelimit&lt;span style="color:#e6db74"&gt;&amp;#34;MB.&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; echo &lt;span style="color:#e6db74"&gt;&amp;#34; To list files by size, run &amp;#39;du -ch \$(git diff --name-only --cached)&amp;#39;&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; echo &lt;span style="color:#e6db74"&gt;&amp;#34; To drop large ones from staging area with &amp;#39;git rm -f filename&amp;#39;&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; echo &lt;span style="color:#e6db74"&gt;&amp;#34; To bypass this limit, use &amp;#39;git commit --no-verify&amp;#39;&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; exit &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;fi&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fi&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;In the repo we will have a .githook directory to store hooks (e.g. ~/source/.githooks/pre-commit) and point to the hooks directory using the following command:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;git config core.hooksPath .githooks&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/10/storage-nitty-gritty-4-of-5-backup-and-archive-solutions/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Storage Nitty-Gritty 4 of 5 – Backup and Archive Solutions&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/11/networking-basics-layer-1-and-layer-2/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Networking Basics 1 of 3 – Layer 1 through Layer 3&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Storage Nitty-Gritty 4 of 5 – Backup and Archive Solutions</title><link>https://www.digihunch.com/2019/10/storage-nitty-gritty-4-of-5-backup-and-archive-solutions/</link><pubDate>Mon, 14 Oct 2019 19:42:00 -0400</pubDate><guid>https://www.digihunch.com/2019/10/storage-nitty-gritty-4-of-5-backup-and-archive-solutions/</guid><description>&lt;h4 class="wp-block-heading"&gt;Business Continuity&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Information Availability IA&lt;/strong&gt; = MTBF/(MTBF+MTTR), where&lt;br&gt;* MTBF (Mean Time Between Failure) &amp;#8211; average time available for a system or component to perform its normal operations between failures.&lt;br&gt;* MTTR (Mean Time to Repair) &amp;#8211; the average time required to repair a failed component.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Disaster Recovery&lt;/strong&gt; &amp;#8211; the coordinated process of restoring systems, data, and the infrastructure required to support ongoing business operations after a disaster occurs. It is the process of restoring a previous copy of the data and applying logs or other necessary processes to that copy to bring it to a known point of consistency.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Recovery-Point Objective (RPO)&lt;/strong&gt; &amp;#8211; the point in time to which systems&lt;br&gt; and data must be recovered after an outage. It defi nes the amount&lt;br&gt; of data loss that a business can endure. A large RPO signifi es high tolerance&lt;br&gt; to information loss in a business.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Recovery-Time Ojbective (RTO)&lt;/strong&gt; &amp;#8211; The time within which systems and applications must be recovered after an outage. It defi nes the amount of downtime that a business can endure and survive. Businesses can optimize disaster recovery plans after defi ning the RTO for a given system.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="557" height="191" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-55.png" alt="" class="wp-image-401"/&gt;&lt;figcaption&gt;Strategies to meet RTO and RPO&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Data Vault&lt;/strong&gt;: a repository at a remote site where data can be periodically or continuously copied so a copy is always available in that site.&lt;br&gt;&lt;strong&gt;Hot site&lt;/strong&gt;: A backup site running all the time.&lt;br&gt;&lt;strong&gt;Cold site&lt;/strong&gt;: A backup site with minimum infrastructure, to be activated for operation in the event of disaster.&lt;br&gt;&lt;strong&gt;Server Clustering&lt;/strong&gt;: a group of servers and relevant resources coupcled to operate as a single syste. Clusters can ensure high availability and load balancing.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Single Point of Failure&lt;/strong&gt; &amp;#8211; failure of a component that can terminate the availability of the entire system or IT service. To mitigate single point of failure, systems are designed with redundancy. This includes:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;redundant HBA on server &lt;/li&gt;&lt;li&gt;NIC teaming&lt;/li&gt;&lt;li&gt;redundant switch&lt;/li&gt;&lt;li&gt;multiple storage array ports&lt;/li&gt;&lt;li&gt;RAID and hot spare configuration&lt;/li&gt;&lt;li&gt;Redundant storage array&lt;/li&gt;&lt;li&gt;server clustering (e.g. clustered servers exchange heartbeat to inform each other about their health. If one of the servers fails, other server can take up the workload.&lt;/li&gt;&lt;li&gt;VM Fault Tolerance&lt;/li&gt;&lt;li&gt;Multipathing software: If one path fails, I/O does not reroute unless the system recognizes that it has an alternative path. Multipathing software provides the functionality to recognize and utilize alternative I/O paths to data. Multipathing software also managees the load balancing by distributing I/Os to all available, active paths.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;h4 class="wp-block-heading"&gt;Backup &lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Backup &lt;/strong&gt;is an additional copy of production data created and retained for the sole purpose of recovering lost or corrupted data. Backup are typically performed for the following purposes:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;Disaster recovery&lt;/strong&gt;. e.g. the backup copies are used for restoring data at an alternate site, when the primary site is incapacitated due to disaster.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Operational recovery&lt;/strong&gt;. e.g. accidental deletion, file corruption&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Archival&lt;/strong&gt;. e.g. data is not changed or accessed any more.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Common considerations for backup includes: time interval between two backups (to meet RPO), retention period, media type (to meet RTO), granularity, compression and deduplication&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Backup Granularity&lt;/strong&gt;&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;Full backup&lt;/strong&gt;: backup of the complete data on the production volumes.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Incremental backup&lt;/strong&gt;: copies the data that has changed since the last full or incremental backup, whichever occurred more recently.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Cumulative backup&lt;/strong&gt;: copies the data that has changed since the last full backup.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Backup Methods&lt;/strong&gt;&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;hot backup/online backup&lt;/strong&gt;: backup is completed while application is up and running;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;cold backup/offline backup&lt;/strong&gt;: backup is completed while the application is shutdown for the backup window.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The hot backup of online production data is challenging because data is actively used and changed. If a file is open, it is normally not backed up during the backup process. In such situations, an open file agent is required to back up the open file. These agents interact directly with the operating system or application and enable the creation of consistent copies of open files. In database environments, To ensure a consistent database backup, all files need to be backed up in the same state. That does not necessarily mean that all files need to be backed up at the same time, but they all must be synchronized so that the database can be restored with consistency. The disadvantage associated with a hot backup is that the agents usually affect the overall application performance. If this is not acceptable, PIT (point-in-time) copy method can be utilized to create a PIT copy from the production volume and use it as the source for the backup. PIT copy method can reduce impact on production volume.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Typical Backup Architecture &lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-58.png" alt="" class="wp-image-404" width="353" height="302"/&gt;&lt;figcaption&gt;Typical Backup Architecture&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="555" height="300" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-59.png" alt="" class="wp-image-405"/&gt;&lt;figcaption&gt;Typical Backup steps&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="554" height="296" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-60.png" alt="" class="wp-image-406"/&gt;&lt;figcaption&gt;Typical Restore steps&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Backup topologies&lt;/strong&gt;&lt;br&gt;&lt;strong&gt;Direct-attached backup:&lt;/strong&gt; the storage node is configured on a backup client, and the backup device is attached directly to the client;&lt;br&gt;&lt;strong&gt;LAN-based backup&lt;/strong&gt;: the clients, backup server, storage node, and backup device are connected to the LAN;&lt;br&gt;&lt;strong&gt;SAN-based backup (LAN-free):&lt;/strong&gt; The SAN-based backup topology is the most appropriate solution when a backup device needs to be shared among clients;&lt;br&gt;&lt;strong&gt;Mixed topology:&lt;/strong&gt; mix of LAN-based and SAN-based topologies;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;NDMP protocol &lt;/strong&gt;is for backup in NAS environment&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Backup media&lt;/strong&gt;&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;Tape&lt;/strong&gt;: for long-term offsite storage due to low cost. data access is sequential which implies slowness for both backup and restore. Tapes are susceptible to wear and tear.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Disk&lt;/strong&gt;: fast backup and retrieve to improve RPT and RTO. No offsite capability.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Virtual Tape&lt;/strong&gt;: virtual taps are disk drives emulated and presented as tapes to the backup software. VTL (virtual tape library) has the same components as that of a physical tape library.&lt;br&gt; Fig 10-18&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Data deduplication&lt;/strong&gt; &amp;#8211; identify and eliminate redundant data to reduce backup window and size. Common data deduplication methods:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;file-level deduplication&lt;/strong&gt; (aka. single-instance storage) detects and removes redundant copies of identical files. It enables storing only one copy of the file; the subsequent copies are replaced with a pointer that points to the original file.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;subfile deduplication&lt;/strong&gt; breaks file into smaller chunks and then uses a specialized althorithm to detect redundant data within and across the file. This eliminates duplicate data across files. This has two forms:&lt;br&gt; * &lt;strong&gt;fixed-length block deduplication&lt;/strong&gt; &amp;#8211; divides the files into fi xed length blocks and uses a hash algorithm to fi nd the duplicate data. &lt;br&gt; *&lt;strong&gt; variable-length segment deduplication&lt;/strong&gt; &amp;#8211; if there is a change in the segment, the boundary for only that segment is adjusted, leaving the remaining segments unchanged.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Data deduplication implementation&lt;/strong&gt;&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;source-based data deduplication&lt;/strong&gt; &amp;#8211; eliminates redundant data at the source before it&lt;br&gt; transmits to the backup device. This requires less bandwidth and shortens backup window. It increases the overhead on the backup client and could impact the performance of the backup and application running on the client.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;target-based data deduplication&lt;/strong&gt; &amp;#8211; deduplication occurs at the backup device, which offloads the backup client from the deduplication process. This takes two forms:&lt;/li&gt;&lt;li&gt;&lt;strong&gt;inline deduplication&lt;/strong&gt; &amp;#8211; performs deduplication on the backup data before it is stored on the backup device. this reduces storage need, but introduces time overhead to identify and remove duplication. best for large backup window&lt;/li&gt;&lt;li&gt;&lt;strong&gt;post-process deduplication&lt;/strong&gt; &amp;#8211; enables backup data to be stored on backup device first, and then deduplicate later. This is suitable for tighter backup windows, but requires more storage.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In virtualized environments, backup agent can be installed on the hypervisor, where the VMs appear as a set of files to the agent. VM files can be backed up by performing a file system backup from a hypervisor. For example, Image-based backup operates at hypervisor level and essentially takes a snapshot of the VM. It creates a copy of the guest OS and all the data associated with it (snapshot of VM disk files), including the VM state and application configurations. The backup is saved as a single file (an image) and mounted on a separate server as proxy, which acts as backup client. &lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="536" height="294" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-62.png" alt="" class="wp-image-409"/&gt;&lt;figcaption&gt;Image Based Backup&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;h4 class="wp-block-heading"&gt;Data archive&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Archive &lt;/strong&gt;&amp;#8211; a repository where fixed content is stored. Fixed content can be data that were changed but will not be changed anymore.&lt;br&gt;&lt;strong&gt;Online archive&lt;/strong&gt;: A storage device directly connected to a host that makes&lt;br&gt; the data immediately accessible.&lt;br&gt;&lt;strong&gt;Nearline archive&lt;/strong&gt;: A storage device connected to a host, but the device where the data is stored must be mounted or loaded to access the data.&lt;br&gt;&lt;strong&gt;Offline archive&lt;/strong&gt;: A storage device not ready to use. Manual intervention is required to connect, mount or load the storage device before data can be accessed.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;An &lt;strong&gt;archiving agent&lt;/strong&gt; is software installed on application server. The agent is responsible for identify data that can be archvied based on policy. After the data is identified for archiving, the agent sends the data to the archiving server. Then the original data on the application server is replaced with a stub file, which contains the address of the archived data. &lt;br&gt;&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-63.png" alt="" class="wp-image-410" width="373" height="313"/&gt;&lt;figcaption&gt;Archiving Solution Architecture&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;br&gt;An &lt;strong&gt;archiving serve&lt;/strong&gt;r is software installed on a host that enables administrators to configure the policies for archiving data. An archiving storage device stores fixed content.&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading"&gt;Related Postings&lt;/h4&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/03/storage-nitty-gritty-1-5/"&gt;Disk and RAID&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/05/storage-nitty-gritty-2-5/"&gt;SAN&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/07/storage-nitty-gritty-3-of-5-nas-and-object-storage/"&gt;NAS and Object Storage&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/11/storage-nitty-gritty-5-of-5-replication/"&gt;Replication&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/10/personal-vim-cheatsheet/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Personal Vim cheatsheet&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/10/clean-up-your-git-repository/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Clean up Git repository&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Cryptography basics 2 of 2</title><link>https://www.digihunch.com/2019/09/cryptographic-concepts-for-busy-it-professionals-2-of-2/</link><pubDate>Sun, 08 Sep 2019 21:21:41 -0400</pubDate><guid>https://www.digihunch.com/2019/09/cryptographic-concepts-for-busy-it-professionals-2-of-2/</guid><description>&lt;p class="wp-block-paragraph"&gt;My previous &lt;a href="https://www.digihunch.com/2019/07/practical-cryptography-for-it-professional/"&gt;post&lt;/a&gt; outlines several core concepts around cryptography, such as asymmetric key encryption, digital certificate, the encoding formats and relevant file extensions. In this article, we continue to explore cryptography use cases, where these concepts are connected and put into application.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The most important use case is TLS handshake. I cannot stress enough how paramount this scenario is. This use case and its variation can be found in almost every situation where connection needs to be secured.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;TLS handshake&lt;/strong&gt;: the process in which client and server establish secure connection. During the handshake, two parties agree on TLS version, decide on cipher suite, authenticate the identity of each other (although client identity authentication is less common), and generate session key for symmetric encryption after the handshake. Details steps are very important. &lt;a href="https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_7.1.0/com.ibm.mq.doc/sy10660_.htm"&gt;Here&lt;/a&gt; is a fairly thorough reference, and here is a great diagram:&lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img loading="lazy" decoding="async" width="1496" height="792" src="https://www.digihunch.com/wp-content/uploads/2019/10/TLS.png" alt="" class="wp-image-152"/&gt;&lt;figcaption class="wp-element-caption"&gt;TLS handshake&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Secure browser connection&lt;/strong&gt;: The most widespread use of TLS handshake is to secure browser connection with HTTPS:&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&#10;&lt;li&gt;Browser initiates connection to the server;&lt;/li&gt;&#10;&lt;li&gt;Server sends browser its certificate (public key + digital signature signed by CA);&lt;/li&gt;&#10;&lt;li&gt;Browser has preloaded public key of CA and uses it to decrypt digital signature and get the digest of public key;&amp;nbsp;&lt;/li&gt;&#10;&lt;li&gt;Browser calculate digest of received public key and compares it against the digest from the previous step;&lt;/li&gt;&#10;&lt;li&gt;If the result is the same, public key is trusted, a green lock is displayed; otherwise, a warning is displayed;&lt;/li&gt;&#10;&lt;li&gt;proceed to the rest of the steps in TLS handshake.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Secure connection in Java&lt;/strong&gt;: Java applications manages keys and certificates through two classes: java.security.KeyStore and java.security.TrustStore. Suppose a Java application client initiates TLS connection to server. The server application will present its certificates from server&amp;#8217;s Key Store. The client will use certificates stored in client&amp;#8217;s Trust Store to verify the identity of the server. Once validated, the client then presents certificates stored in client&amp;#8217;s Key Store back to the server for validation.&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;A KeyStore keeps keys and certificates for your own application. Typically, you store a KeyPair in a KeyStore file.&lt;/li&gt;&#10;&lt;li&gt;A TrustStore keeps the certificates of external systems that your application trusts.&amp;nbsp;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Below is a great diagram:&lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img loading="lazy" decoding="async" width="1362" height="956" src="https://www.digihunch.com/wp-content/uploads/2019/10/JavaJKS.png" alt="" class="wp-image-153"/&gt;&lt;figcaption class="wp-element-caption"&gt;Secure Java application in TLS&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;JKS file &lt;/strong&gt;is Java&amp;#8217;s version of PKCS#12 (private key + certificate, password protected). Entries in a JKS file must have an &amp;#8220;alias&amp;#8221; that is unique. The JKS file type can be used for both Key Store and Trust Store. When it&amp;#8217;s used in Key Store, it contains a certificate and private key for the Java application. When it&amp;#8217;s used in Trust Store, it only contains certificate from external trusted applications. Note that JKS is the default keystore format until Java 8. Since Java 9 the default keystore format is PKCS12.&amp;nbsp;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Finally, we can introduce some tools:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Command line Tools&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;openssl &lt;/strong&gt;is a versatile tool for cryptography and keytool is a similar tool for Java applications.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;keytool &lt;/strong&gt;is for store keys/certificates in Java Key Store or Trust Store.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;I do not include any openssl or keytool command in this article in order to remain theoretical. However, once through the conceptual hurdles, one should become fairly comfortable picking up the tools and understand why each command is needed to achieve its purpose.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/08/aws-certified-devops-engineer-exam-tips/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;AWS Certified DevOps Engineer Exam Tips&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/10/personal-vim-cheatsheet/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Personal Vim cheatsheet&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>AWS Certified DevOps Engineer Exam Tips</title><link>https://www.digihunch.com/2019/08/aws-certified-devops-engineer-exam-tips/</link><pubDate>Sat, 17 Aug 2019 23:07:59 -0400</pubDate><guid>https://www.digihunch.com/2019/08/aws-certified-devops-engineer-exam-tips/</guid><description>&lt;p class="wp-block-paragraph"&gt;The last 30 days have been exhausting for me. I studied hard on the new AWS Certified DevOps Engineer exam and thank goodness I passed (750 out of 1000 is required). This was the hardest professional certification I ever worked on. The exam was re-launched recently in March 2019 so there is still a shortage of information around the community. I was hoping to share my experience to help demystify this new exam. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;I had a somewhat solid background to begin with, having taken the AWS Certified Solution Architect Professional exam (before the 2019 update), and worked quite a bit on CloudFormation, automation and Git. However, I still did not anticipate the exam to be this difficult until I was halfway through and already had the exam and materials paid for.&lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img loading="lazy" decoding="async" width="1469" height="518" src="https://www.digihunch.com/wp-content/uploads/2019/08/image.png" alt="" class="wp-image-127"/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Without clear guideline on study material other than the white papers, I first skimmed through the ACloudGuru course, which helped me form a high level sense of exam coverage. Nonetheless it does not cover any topic in-depth and therefore by no means makes an essential part of my study. I checked out &lt;strong&gt;LinuxAcademy course&lt;/strong&gt; and they are much more in-depth for the major topics indeed. I like the course material in Lucid chart. However, the LinuxAcademy course along does not cover everything you need to know.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;What I found extremely helpful is the free training videos from the &lt;a href="https://www.aws.training"&gt;official training website&lt;/a&gt;. I strongly recommend the 7-hour course &lt;strong&gt;Exam Readiness: AWS Certified DevOps Engineer – Professional&lt;/strong&gt;. The instructor did a great job outlining the services and knowledge areas in the assessment . The course also comes with quality sample questions with answers and explanations on what the thinkings are behind the correct answers or why some choices are obviously wrong. I went through these questions twice and feel much better at not only understanding the question, but also understanding the intent of the question.&lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img loading="lazy" decoding="async" width="833" height="156" src="https://www.digihunch.com/wp-content/uploads/2019/08/image-1.png" alt="" class="wp-image-129"/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Apart from the Exam Readiness course, other &lt;strong&gt;free introductory courses&lt;/strong&gt; from the official training website are helpful as well especially for those services that you only need to know the basics. Most of those courses are 5 ~ 10 minutes long, with brief but sufficient introduction and a demo session. The other extremely helpful resource is the &lt;strong&gt;official practice questions&lt;/strong&gt;. The practice exam is harder than the actual exam but they closely resemble the actual question style in the exam. Unfortunately, no answer is provided but they made me spend time finding answers across the documentations and blogs. It is worth-noting that the AWS blogs provides plenty of use cases that are covered in the questions.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;When it comes to the real exam, it covers a lot more topics than its predecessor. Many questions are long and confusing. And I wish I could run a diff command to highlight the differences between choices. During exam preparation you really need to train yourself on reading efficiently. I found myself sometimes eyeball through all four choices at the same time, which get my mind scattered.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;During my study, I divide all services into three categories based on the level of familiarity, and here is my list:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Category 1. Know these services very well, in and out:&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;AWS ElasticBeanstalk, OpsWorks Stacks, OpsWorks Chef Automate, CloudFormation, CloudWatch, CodeBuild, CodeCommit, CodeDeploy, CodePipeline, CodeStar, Lambda, API Gateway, Config, Trusted Advisor, CloudTrail, Systems Manager, Autoscaling Group in EC2, DynamoDB&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Category 2. Know these services well, but not necessarily down to every single detail:&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Amazon Kinesis Firehose, Kinesis Analytics, Kinesis Streams, Step Functions, Elastic Load Balancer, Secrets Manager, Serverless Application Model (SAM), Route53, RDS, Certificate Manager, ElasticSearch, ECS, ECR&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Category 3. Know about these services at a high level, but do not skip any:&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;AWS Organization, X-Ray, GuardDuty, Macie, Inspector, Service Catalog, KMS, Batch, Athena, Single-Sign-On, Data LifeCycle Manager, CloudSearch, Health Dashboard, Glue, QuickSight, LightSail&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Although I did not mention much about the white papers, I want to highlight their importance again. I would not attempt the exam without reading and understanding the required white papers. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;If you aspire to take the AWS certified DevOps Engineer exam I hope this helps you a little bit. Good luck.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/07/storage-nitty-gritty-3-of-5-nas-and-object-storage/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Storage Nitty-Gritty 3 of 5 – NAS and Object Storage&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/09/cryptographic-concepts-for-busy-it-professionals-2-of-2/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Cryptography basics 2 of 2&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Storage Nitty-Gritty 3 of 5 – NAS and Object Storage</title><link>https://www.digihunch.com/2019/07/storage-nitty-gritty-3-of-5-nas-and-object-storage/</link><pubDate>Sat, 13 Jul 2019 23:31:00 -0400</pubDate><guid>https://www.digihunch.com/2019/07/storage-nitty-gritty-3-of-5-nas-and-object-storage/</guid><description>&lt;h4 class="wp-block-heading" id="h-nas-network-attached-storage"&gt;&lt;strong&gt;NAS (network attached storage)&lt;/strong&gt;&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;NAS server is dedicated to file-serving. NAS device runs its own specialized operating system that is optimized for file I/O, integrated hardware and software component that meets specific file-service needs, and performs file I/O better than a general-purpose server. NAS device can serve more clients than general-purpose servers and provide the benefit of server consolidation (centralized storage).&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;NAS uses network and file-sharing protocols to provide access to the file data. These protocols include TCP/IP for data transfer, and Common Internet File System (CIFS) and Network File System (NFS) for network file service.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Network File Sharing&lt;/strong&gt; &amp;#8211; user who creates a file determines the type of access to be given to other user. When multiple users try to access a shared file at the same time, a locking scheme is required to maintain data integrity and, at the same time, make this sharing possible. Examples of file sharing method (FTP, DFS, NFS, CIFS, P2P)&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Components of NAS&lt;/strong&gt; &amp;#8211; NAS head (CPU, memory, NIC, optimized OS, ports, applications that supports CIFS/NFS) and Storage Array&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-42.png" alt="" class="wp-image-379" width="502" height="279"/&gt;&lt;figcaption class="wp-element-caption"&gt;Typical NAS components&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;NAS I/O operation&lt;/strong&gt;:&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&#10;&lt;li&gt;Client packages an I/O request into TCP/IP and forwards it through network stack. NAS head receives this request from network;&lt;/li&gt;&#10;&lt;li&gt;NAS head converts the I/O request into an appropriate physical storage request, which is a block-level I/O, and then performs the operation on the physical storage;&lt;/li&gt;&#10;&lt;li&gt;When NAS head receives data from the storage array, it processes and repackages the data into an appropriate NFS/CIFS response;&lt;/li&gt;&#10;&lt;li&gt;NAS head packages this response into TCP/IP again and forwards it to the client through the network&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="1128" height="452" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-43.png" alt="" class="wp-image-380"/&gt;&lt;figcaption class="wp-element-caption"&gt;NAS I/O operation&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;NAS implementation&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Unified NAS&lt;/strong&gt; &amp;#8211;&amp;nbsp; consolidate NAS-based and SAN-based data access within a unified storage platform and provides a unified management interface for managing both the environments. &lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-44.png" alt="" class="wp-image-381" width="464" height="456"/&gt;&lt;figcaption class="wp-element-caption"&gt;Unified NAS connectivity&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Gateway implementation&lt;/strong&gt; &amp;#8211; similar to unified NAS, the storage is shared with other applications that use block-level I/O. The gateway NAS is more scalable compared to unified NAS because NAS heads and storage arrays can be independently scaled up when required. For example, NAS heads can be added to scale up the NAS device performance.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;When the storage limit is reached, it can scale up, adding capacity on the SAN, independent of NAS heads. Similar to a unified NAS, a gateway NAS also enables high utilization of storage capacity by sharing it with the SAN environment.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-45.png" alt="" class="wp-image-382" width="547" height="366"/&gt;&lt;figcaption class="wp-element-caption"&gt;Gateway NAS connectivity&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Scale-out NAS&lt;/strong&gt; &amp;#8211; enables grouping multiple nodes together to construct a clustered NAS system. A scaled-out NAS provides the capability to scale its resources by simply adding nodes to a clustered NAS architecture. The cluster works as a single NAS device and is managed centrally. Scaled-out NAS creates a single file system that runs on all nodes in the cluster. All information is shared among nodes, so the entire file system is accessible by clients connecting to any node in the cluster. Scale-out NAS stripes data across all nodes in a cluster along with mirror or parity protection. As data is sent from clients to the cluster, the data is divided and allocated to different nodes in parallel. When a client sends a request to read a file, the scale-out NAS retrieves the appropriate blocks from multiple nodes, recombines the blocks into a file, and presents the file to the client. As nodes are added, the file system grows dynamically and data is evenly distributed to every node. Each node added to the cluster increases the aggregate storage, memory, CPU, and network capacity. Hence, cluster performance also increases.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Scale-out NAS use separate internal and external networks for back-end and front-end connectivity, respectively. The internal network offers high throughput and low-latency and uses high-speed networking technology, such as InfiniBand or Gigabit Ethernet.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-46.png" alt="" class="wp-image-383" width="475" height="247"/&gt;&lt;figcaption class="wp-element-caption"&gt;Scale-out NAS with dual internal and single external networks&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;NFS protocol &lt;/strong&gt;&amp;#8211; originally based on UDP, uses RPC as a method of inter-process communication between two computers. NFS provides a set of RPCS to access remote file system for the following operations:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Searching files and directories&lt;/li&gt;&#10;&lt;li&gt;Opening, reading, writing to and closing a file&lt;/li&gt;&#10;&lt;li&gt;Changing file attributes&lt;/li&gt;&#10;&lt;li&gt;Modifying file links and directories&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;NFSv3&lt;/strong&gt; and earlier is stateless protocol. Each call provides a full set of arguments to access files on the server. NFSv3 is most commonly used version, based on UDP or TCP.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;NFSv4&lt;/strong&gt; uses TCP and is based on stateful protocol design.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;CIFS&lt;/strong&gt; &amp;#8211; a public, or open variation of SMB protocol. Filenames in CIFS are encoded using unicode characters. It is stateful protocol because the server maintain connection information regarding every connected client. If a network failure or CIFS server failure occurs, the client receives a disconnection notification. If application has embedded intelligence to restore the connection, then the storage solution is fault tolerant. If the embedded intelligence is missing, the user must take steps to reestablish the CIFS connection.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;NAS Performance&lt;/strong&gt; &amp;#8211; network congestion is one of the most significant sources of latency in NAS environment. Other factors&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&#10;&lt;li&gt;number of hops&lt;/li&gt;&#10;&lt;li&gt;authentication with AD&lt;/li&gt;&#10;&lt;li&gt;Retransmission &amp;#8211; speed and duplex settings on the network devices and NAS heads must match&lt;/li&gt;&#10;&lt;li&gt;Over-utilized routers and switches&lt;/li&gt;&#10;&lt;li&gt;File system lookup and metadata request &amp;#8211; deep directory structure could cause delay.&lt;/li&gt;&#10;&lt;li&gt;&lt;span style="text-decoration: underline;"&gt;Over-utilized NAS devices&lt;/span&gt; &amp;#8211; client accessing multiple files can cause high utilization levels on a NAS device&lt;/li&gt;&#10;&lt;li&gt;&lt;span style="text-decoration: underline;"&gt;Over-utilized clients&lt;/span&gt; &amp;#8211; if a client is busy itself, it requires a longer time to process the request and responses.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="988" height="664" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-47.png" alt="" class="wp-image-385"/&gt;&lt;figcaption class="wp-element-caption"&gt;NAS latency&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;NFS server manages privilege and does not require username and password from the client at the time of mounting. CIFS share does require username and password.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Common network optimization practices&lt;/strong&gt; for network contestion:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;A &lt;span style="text-decoration: underline;"&gt;VLAN&lt;/span&gt; is a logical segment of a switched network or logical grouping of end devices connected to different physical networks. The segmentation or grouping can be done based on business functions, project teams, or applications. VLAN is a Layer 2 (data link layer) construct and works similar to a physical LAN. A network switch can be logically divided among multiple VLANs, enabling better utilization of the switch and reducing overall cost of deploying a network infrastructure.&amp;nbsp;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The broadcast traffic on one VLAN is not transmitted outside that VLAN, which substantially reduces the broadcast overhead, makes bandwidth available for applications, and reduces the network&amp;#8217;s vulnerability to broadcast storms.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;span style="text-decoration: underline;"&gt;MTU&lt;/span&gt; setting determines the size of the largest packet that can be transmitted without data fragmentation. &lt;span style="text-decoration: underline;"&gt;Path maximum transmission&lt;/span&gt; unit discovery is the process of discovering the maximum size of a packet that can be sent across a network without fragmentation. The default MTU setting for an Ethernet interface card is 1,500 bytes. A feature called &lt;span style="text-decoration: underline;"&gt;jumbo frames&lt;/span&gt; sends, receives or transports Ethernet frames with an MTU of more than 1,500 bytes. The most common deployments of jumbo frames have an MTU of 9,000 bytes. However, not all vendors use the same MTU size for jumbo frames. Servers send and receive larger frames more efficiently than smaller ones in heavy network traffic conditions. Jumbo frames ensure increased efficiency because it takes fewer, larger frames to transfer the same amount of data. Larger packets also reduce the amount of raw network bandwidth being consumed for the same amount of payload. Larger frames also help to smooth sudden I/O burst.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The &lt;span style="text-decoration: underline;"&gt;TCP window size&lt;/span&gt; is the maximum amount of data that can be sent at any time for a connection. For example, if a pair of hosts is talking over a TCP connection that has a TCP windows size of 64KB, the sender can send only 64KB of data and must then wait for an acknowledgement from the receiver. If the receiver acknowledges that all the data has been received, then the sender is free to send another 64 KB of data. If the sender receives an acknowledgment from the receiver that only the first 32 KB of data has been received, which can happen only if another 32 KB of data is in transit or was lost, the sender can send only another 32 KB of data because the transmission cannot have more than 64 KB of unacknowledged data outstanding.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In theory, the TCP window size should be set to the product of the available bandwidth of the network and the round-trip time of data sent over the network. For example, if a network has a bandwidth of 100 Mbps and the round-trip time is 5 milliseconds, the TCP window should be as follows:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;100 Mb/s x .005 seconds = 524,288 bits or 65,536 bytes&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The size of the TCP window fi eld that controls the fl ow of data is between 2 bytes and 65,535 bytes&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;span style="text-decoration: underline;"&gt;Link aggregation&lt;/span&gt; is the process of combining two or more network interfaces into a logical network interface, enabling higher throughput, load sharing or load balancing, transparent path failover, and scalability. Due to link aggregation, multiple active Ethernet connections to the same switch appear as one link. If a connection or a port in the aggregation is lost, then all the network traffic on that link is redistributed across the remaining active connections.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;File-level virtualization&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;File-level virtualization eliminates the dependencies between the data accessed at the file level and the location where the files are physically stored. Implementation of file-level virtualization is common in NAS or file-server environments. It provides non-disruptive file mobility to optimize storage utilization.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;It provides user or application independence from the location where the files are stored. File-level virtualization creates a logical pool of storage, enabling users to use a logical path, rather than a physical path, to access files. While the files are being moved, clients can access their files non-disruptively. Clients can also read their files from the old location and write them back to the new location without realizing that the physical location has changed. A global namespace is used to map the logical path of a file to the physical path names.&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="1114" height="682" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-48.png" alt="" class="wp-image-386"/&gt;&lt;figcaption class="wp-element-caption"&gt;File-serving environment before and after file-level virtualization&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;h4 class="wp-block-heading" id="h-object-based-storage"&gt;&lt;strong&gt;Object-based storage&lt;/strong&gt;&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In NAS, metadata are stored as part of the file distributed throughout the environment, which adds to the complexity and latency in searching and retrieving files. Object-based storage, on the other hand, stores file data in the form of objects based on its content and other attributes, rather than the name and location.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-49.png" alt="" class="wp-image-387" width="402" height="240"/&gt;&lt;figcaption class="wp-element-caption"&gt;Hierarchical File System and Flat Address Space&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;OSD &amp;#8211; object-based storage devices&lt;/strong&gt;, stores data in the form of objects using flat address space. There is no hierarchy of directories and file. Object is identified by objectID, which is usually generated using hash function.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In block storage, when file system receives the IO from an application, the file system maps the incoming I/O to the disk blocks. The block interface is used for sending the I/O over the channel or network to the storage device. The I/O is then written to the block allocated on the disk drive. When an application accesses data stored in OSD, the request is sent to the file system user component. The file system user component communicates to the OSD interface, which in turn sends the request to the storage device. The storage device has the OSD storage component responsible for managing the access to the object on a storage device.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Benefit of object storage&lt;/strong&gt;&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;security and reliability: OSD can use special algorithm for strong encryption capacity. Request authentication is performed at the storage device rather than with an external authentication mechanism&lt;/li&gt;&#10;&lt;li&gt;platform independence: standard web access via REST or SOAP&lt;/li&gt;&#10;&lt;li&gt;scalability: Both storage and OSD nodes can be scaled independently in terms of performance and capacity&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-50.png" alt="" class="wp-image-388" width="401" height="445"/&gt;&lt;figcaption class="wp-element-caption"&gt;Block-level access vs object-level access&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;OSD components&lt;/strong&gt;:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;nodes: a server with OSD operating environment to provide services to store, retrieve and manage data. Two key services are metadata service (generating objectID and maintaining the mapping between objectID and file) and storage service (manage a set of disks where data are stored).&lt;/li&gt;&#10;&lt;li&gt;private network: provides node-to-node connectivity and node-to-storage connectivity.&lt;/li&gt;&#10;&lt;li&gt;storage device&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-51.png" alt="" class="wp-image-389" width="518" height="166"/&gt;&lt;figcaption class="wp-element-caption"&gt;OSD system components&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Storage mechanism&lt;/strong&gt;&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&#10;&lt;li&gt;The application server presents the file to be stored to the OSD node.&lt;/li&gt;&#10;&lt;li&gt;The OSD node divides the file into two parts: user data and metadata.&lt;/li&gt;&#10;&lt;li&gt;The OSD node generates the object ID using a specialized algorithm. The algorithm is executed against the contents of the user data to derive an ID unique to this data.&lt;/li&gt;&#10;&lt;li&gt;For future access, the OSD node stores the metadata and object ID using the metadata service.&lt;/li&gt;&#10;&lt;li&gt;The OSD node stores the user data (objects) in the storage device using the storage service.&lt;/li&gt;&#10;&lt;li&gt;An acknowledgment is sent to the application server stating that the object is stored.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-52.png" alt="" class="wp-image-390" width="512" height="334"/&gt;&lt;figcaption class="wp-element-caption"&gt;OSD: object storage&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Retrieval mechanism&lt;/strong&gt;&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&#10;&lt;li&gt;The application server sends a read request to the OSD system.&lt;/li&gt;&#10;&lt;li&gt;The metadata service retrieves the object ID for the requested file.&lt;/li&gt;&#10;&lt;li&gt;The metadata service sends the object ID to the application server.&lt;/li&gt;&#10;&lt;li&gt;The application server sends the object ID to the OSD storage service for object retrieval.&lt;/li&gt;&#10;&lt;li&gt;The OSD storage service retrieves the object from the storage device.&lt;/li&gt;&#10;&lt;li&gt;The OSD storage service sends the file to the application server.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-53.png" alt="" class="wp-image-391" width="525" height="291"/&gt;&lt;figcaption class="wp-element-caption"&gt;OSD object retrieval&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;OSD usage&lt;/strong&gt;: data archival, especially long-term; and cloud storage, storage as service&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;CAS &amp;#8211; content addressed storage&lt;/strong&gt;, a special type of OSD designed for secure online storage and retrieval of fixed content. Data access in CAS differs from other OSD devices. &lt;span style="text-decoration: underline;"&gt;In CAS, the application server access the CAS device only via the CAS API running on the application server&lt;/span&gt;. However, the way CAS stores data is similar to the other OSD systems.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;CAS&lt;/strong&gt; &lt;strong&gt;Use case &lt;/strong&gt;&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Healthcare: storing patient studies &amp;#8211; size of radiology study ranges from 15MB to more than 1GB. Newly acquired studies are retained for 60 days and moved to long term storage.&lt;/li&gt;&#10;&lt;li&gt;Finance: storing financial records &amp;#8211; bank stores images of cheques (~25KB each) for about 90 millions a month. Images are processed in transaction system for 5 days. For the next 60 days images are requested for verifications. After 60 days access requirements drop drastically. Retention policy manages life-cycle of the images.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Unified storage&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Components&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;storage controller: The storage controller provides block-level access to application servers through iSCSI, FC, or FCoE protocols.&lt;/li&gt;&#10;&lt;li&gt;NAS head: a dedicated file server that provides file access to NAS clients&lt;/li&gt;&#10;&lt;li&gt;OSD node: accesses the storage through the storage controller using a FC or FCoE connection.&lt;/li&gt;&#10;&lt;li&gt;Storage&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-54.png" alt="" class="wp-image-392" width="459" height="533"/&gt;&lt;figcaption class="wp-element-caption"&gt;Unified storage platform&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;h4 class="wp-block-heading" id="h-related-postings"&gt;Related Postings&lt;/h4&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/03/storage-nitty-gritty-1-5/"&gt;Disk and RAID&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/05/storage-nitty-gritty-2-5/"&gt;SAN&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/07/storage-nitty-gritty-3-of-5-nas-and-object-storage/"&gt;Backup and Archive Solutions&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/11/storage-nitty-gritty-5-of-5-replication/"&gt;Replication&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/07/practical-cryptography-for-it-professional/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Cryptography Basics 1 of 2&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/08/aws-certified-devops-engineer-exam-tips/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;AWS Certified DevOps Engineer Exam Tips&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Cryptography Basics 1 of 2</title><link>https://www.digihunch.com/2019/07/practical-cryptography-for-it-professional/</link><pubDate>Wed, 10 Jul 2019 20:07:18 -0400</pubDate><guid>https://www.digihunch.com/2019/07/practical-cryptography-for-it-professional/</guid><description>&lt;p class="wp-block-paragraph"&gt;I have been dabbling with OpenSSL commands to achieve what I needed during IT implementation, but I decided to spent some time to overcome the conceptual hurdles around cryptography. In this domain, following other people&amp;#8217;s instructions through the project does not produce much learning value when too many concepts cloud around. Let&amp;#8217;s take the bull by the horn.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;This article is purely conceptual. There are already lots of step-by-step guideline about acquiring a website certificate. The intention is to elucidate the core concepts on IT cryptography, and then connect the dots to form the big picture in cryptography.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;First, let&amp;#8217;s distinguish three basic concepts: encoding, hashing and encryption. They are in essence all mathematical functions, but one does not need to understand the underlying algorithm in order to understand what they are.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Encoding&lt;/strong&gt; &amp;#8211; Transform data into a format so it is readable by external system. Encoding is about interoperability. It is not about security whatsoever. Example: ASCII, BASE64, UNICODE.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Hashing&lt;/strong&gt; &amp;#8211; Mathematic algorithms to generate digest of content. A digest is usually fixed-size, non-reversible and deterministic. You cannot restore content from its digest (non-reversible, one-way calculation). Two different contents results guarantees different digests (deterministic). Digest as a result of hashing is mostly about data integrity. For example, in file download you can calculate MD5 hash and compare the result against the digest given by the source. Another common use, is to hash all password in database. In that sense, hashing has to do with security. Popular algorithms are MD5 and SHA-256.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Encryption&lt;/strong&gt; &amp;#8211; Mathematic algorithms that only succeeds if correct parameter (key) is provided. The function is deterministic and reversible (two-way). The parameter (key) used for calculation (encryption) and reverse calculation (decryption) can either be the same or different. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Cryptography involves all three concepts, but it mainly addresses issues around encryption. We break down encryption into two categories, symmetric key encryption (aka private key encryption) and asymmetric key encryption (aka public key encryption).&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Symmetric Key Encryption&lt;/strong&gt;: using the same key (shared secret) for encryption and decryption. Both parties need to keep it secret. Popular algorithm is AES.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Asymmetric Key Encryption&lt;/strong&gt;: involves a pair of public key and private key. Public key is given out to external systems. Private key is kept secret. Popular algorithm is RSA. You can run some experiments on &lt;a href="https://www.devglan.com/online-tools/rsa-encryption-decryption"&gt;this page&lt;/a&gt;, and I&amp;#8217;ve made some additional notes (all based on RSA algorithm):&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&lt;li&gt;Public Key and Private Key are NOT interchangeable. The size of an RSA private key is usually much larger than its public key;&lt;/li&gt;&lt;li&gt;You can encrypt with either key, and decrypt with the other, so long as you specify the key type at the time of encryption or decryption;&lt;/li&gt;&lt;li&gt;You can generate public key from private key (ssh-keygen -y); but not the other way round;&lt;/li&gt;&lt;li&gt;Using a wrong key to encrypt or decrypt leads to failure, instead of wrong result.&lt;/li&gt;&lt;/ol&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Obviously symmetric key encryption is the original form of encryption and requires both parties to keep the key secret, permanently. This is not realistic in real life between organizations. This challenge leads to the adoption of asymmetric key where the public key can be published, for external party to encrypt outgoing messages, whereas the private key is kept secret within the owner, only to decrypt incoming messages. &lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img decoding="async" src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/f9/Public_key_encryption.svg/1024px-Public_key_encryption.svg.png" alt=""/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Knowing this distinction, we can introduce two concepts that are built on top of asymmetric key encryption.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Digital Signature&lt;/strong&gt;: if an entity signs a document digitally. The digital signature is the digest of the document (hash of the content) encrypted with the signer&amp;#8217;s private key.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Digital Certificate&lt;/strong&gt;: contains owner&amp;#8217;s public key and digital signature of issuer (digest of owner&amp;#8217;s public key encrypted by issuer&amp;#8217;s private key). Client (e.g. browser with CA&amp;#8217;s public key preloaded) should not trust the owner&amp;#8217;s public key until it compares its digest against decryption result of digital signature (using CA&amp;#8217;s public key).&amp;nbsp;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The key difference here is that a digital certificate involves third party. Digital signature by itself cannot address impersonation, which is addressed by digital certificate issued by third party (certified authority). This requires digital certificate must follow some standard, and the most prevalent one is:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;X.509&lt;/strong&gt;: a standard format for digital certificates. It contains:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;a public key&lt;/li&gt;&lt;li&gt;an identity (a hostname, or&amp;nbsp; an organization, or an individual)&lt;/li&gt;&lt;li&gt;a signature (either signed by CA or self-signed)&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Since the advent of certificate, there are tons of global organizations that need to manage keys and certificates. When we create a secure connection now, we only need to get a certificate from an intermediate CA, thanks to existing &lt;a href="https://knowledge.digicert.com/solution/SO16297.html"&gt;certificate chain&lt;/a&gt;. It involves lots of work for large organizations to maintain keys and certificates, which requires:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Public Key Infrastructure (PKI)&lt;/strong&gt;: the IT infrastructure to create, manage, distribute, use, store and revoke digital certificates and public keys.&amp;nbsp;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;One of the important technique to manage keys and certificates is the encoding. Keys and certificates are usually wrapped with different encoding formats based on what need to be done on them. Here is a summary of encoding formats&lt;/p&gt;&#10;&lt;figure class="wp-block-table aligncenter is-style-stripes"&gt;&lt;table class="has-background" style="background-color:#e7f5fe"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Format&lt;/td&gt;&lt;td&gt;Encoding&lt;/td&gt;&lt;td&gt;what is stored&lt;/td&gt;&lt;td&gt;Possible Suffix&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;PEM&lt;/td&gt;&lt;td&gt;DER file (binary content) encoded in Base64. Certificate files typically include clear text statement &amp;#8220;BEGIN CERTIFICATE&amp;#8221; and &amp;#8220;END CERTIFICATE&amp;#8221;&lt;/td&gt;&lt;td&gt;single certificate, certificate chains or private keys&lt;/td&gt;&lt;td&gt;.pem, .crt, .cer, .key&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;DER&lt;/td&gt;&lt;td&gt;Binary format in early days; it&amp;#8217;s complex and don&amp;#8217;t use unless with a specific purpose.&lt;/td&gt;&lt;td&gt;single certificate, certificate chains, or private keys&lt;/td&gt;&lt;td&gt;.der, .cer&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;PKCS#7&lt;/td&gt;&lt;td&gt;Base64 encoded ASCII file, typically include clear text statement &amp;#8220;BEGIN PKCS7&amp;#8221; and &amp;#8220;END PKCS7&amp;#8221;&lt;/td&gt;&lt;td&gt;only certificates or certificate chains; no private keys&lt;/td&gt;&lt;td&gt;.p7b .p7s&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;PKCS#8&lt;/td&gt;&lt;td&gt;Similar to PEM as base64 encoded format but for storing private key only, can be password protected&lt;/td&gt;&lt;td&gt;Private key&lt;/td&gt;&lt;td&gt;.key&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;PKCS#12&lt;/td&gt;&lt;td&gt;a binary format, heavily used by Microsoft products&lt;/td&gt;&lt;td&gt;certificate, certificate chains or private keys; public private key pair&lt;/td&gt;&lt;td&gt;.pfx .p12&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;OpenSSH&lt;/td&gt;&lt;td&gt;used by OpenSSH to store public keys (as specified in RFC4253)&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;.pub&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Note: above are just encoding formats. Just by file extension you cannot tell whether the file is a key or a X.509 certificate. When you are configuring certificates, you may come across the following file extensions as well:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;.key&lt;/strong&gt; this extension can indicate any kind of key, but usually it is a private key (used along with .crt file) &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;.csr&lt;/strong&gt; certificate signing request, including a public key and an identity required by CA. CA needs this file to issue a certificate. CSR could be encoded in Base-64 or DER&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;.cer or .crt&lt;/strong&gt; a certificate, usually in X.509 v3 (public key + identity + signature), the encoding could be PEM or DER. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;.jks&lt;/strong&gt; -&amp;gt; java key store file type. It can be either a key store (private key along with certificate) or trust store (certificate) for Java application. Refer to the section for Java applications.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In the &lt;a href="https://www.digihunch.com/2019/09/cryptographic-concepts-for-busy-it-professionals-2-of-2/"&gt;next article&lt;/a&gt;, we will examine some use case involving the concepts introduced in this post.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt; &lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/06/git-explained-2-of-2/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Git Explained 2 of 2&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/07/storage-nitty-gritty-3-of-5-nas-and-object-storage/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Storage Nitty-Gritty 3 of 5 – NAS and Object Storage&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Git Explained 2 of 2</title><link>https://www.digihunch.com/2019/06/git-explained-2-of-2/</link><pubDate>Tue, 18 Jun 2019 17:06:00 -0400</pubDate><guid>https://www.digihunch.com/2019/06/git-explained-2-of-2/</guid><description>&lt;p class="wp-block-paragraph"&gt;This is a continuation from &lt;a href="https://www.digihunch.com/2019/06/git-explained-1-of-2/"&gt;Git Explained 1 of 2 &lt;/a&gt;where the fundamental concepts are covered. In this article we introduce some tools for customization and maintenance.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;As for Git configuration, there are two files to dictate your Git configuration. ~/.gitconfig and .git/config in project directory. Running `git config &amp;#8211;list &amp;#8211;show-origin` shows all config entries and where they are from. For example you can custom your Git hooks location. Neither of the two files are being version controlled, so the configuration is only effective in the client environment,&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;&lt;strong&gt;Server side Git hooks&lt;/strong&gt;&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Git implementation supports server side hooks (pre-receive, update, post-receive). They are bash scripts placed in .git/hooks with specific names, fired upon event occurrence. Exit code of 1 from the scripts fails the event. Since server side Git hook consumes server resources, many repository hosting vendors (e.g. &lt;a href="https://community.atlassian.com/t5/Bitbucket-questions/Does-Bitbucket-Cloud-support-git-pre-receive-hooks/qaq-p/950235"&gt;BitBucket Cloud&lt;/a&gt;) do not support it. You will need to enable it in self-hosted servers (e.g. BitBucketServer).&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;&lt;strong&gt;Client side Git hooks&lt;/strong&gt;&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Since server side hooks are not widely supported in every vendor, client-side Git hooks is good alternative places to implement functions such as code style check, commit size check, etc&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The default directory for hooks is .git/hooks/ under the project directory is not version controlled and not easy to share with the team. If the hook needs to be shared among project contributors, we can place hooks files in .githooks/ under project directory. This will make the hook files version controlled. In addition, we need to point the hooks to this directory in configuration, by running `git config core.hooksPath .githooks` from project directory.&lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img loading="lazy" decoding="async" width="1020" height="767" src="https://www.digihunch.com/wp-content/uploads/2019/10/git-hooks.png" alt="" class="wp-image-211"/&gt;&lt;/figure&gt;&#10;&lt;h3 class="wp-block-heading"&gt;&lt;strong&gt;Web hooks &lt;/strong&gt;&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Web hooks can be thought of as an event notification mechanism. It is a common feature provided by VCS repository hosting providers. If a certain type of event occurs to the repo, web hook will fire an RESTful API call. The HTTP Endpoint, authentication secret and event payload are pre-configured in the repo settings. Web hooks are commonly supported by Git-based repo implementation, such as &lt;a href="https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html"&gt;BitBucket cloud&lt;/a&gt;, &lt;a href="https://developer.github.com/webhooks/"&gt;GitHub&lt;/a&gt;, &lt;a href="https://docs.gitlab.com/ee/user/project/integrations/webhooks.html"&gt;GitLab&lt;/a&gt; or &lt;a href="https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-notify.html"&gt;AWS CodeCommit&lt;/a&gt;. It can also be enabled in self hosted Git repo. Web hook is a powerful tool to drive downstream event, such as Jenkins to start building the code. The major difference between server side hook and web hook is web hook is RESTful API driven, whereas server side hook is executing a script.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-pipelines"&gt;&lt;strong&gt;Pipelines&lt;/strong&gt;&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Some repo hosting vendor also provide a feature named pipeline. BitBucket has &lt;a href="https://confluence.atlassian.com/bitbucket/get-started-with-bitbucket-pipelines-792298921.html"&gt;Pipeline&lt;/a&gt; as a CI/CD tool, AWS has &lt;a href="https://aws.amazon.com/codepipeline/"&gt;AWS Code Pipeline&lt;/a&gt;, and GitLab offers &lt;a href="https://docs.gitlab.com/ee/ci/pipelines/"&gt;CI/CD pipeline&lt;/a&gt; as well. These pipelines are usually in the form of a YAML file in the repo with a special name. The YAML spell out the steps to perform along the pipeline.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;&lt;strong&gt;Squash&lt;/strong&gt; Commits&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;For small projects I was in the habit of committing to main branch. I often need to squash a number of commits into one to &amp;#8220;clean up&amp;#8221;. Usually a Pull Request (e.g. in GitHub) or Merge Request (e.g. in GitLab) have such option during approval. We can squash a few commits with git command as well (suppose we want to squash the most recent 16 commits):&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;git rebase -i HEAD~16&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;git push origin +main&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;The command will open text editor to allow you to mark what to do with each commit. You can mark all except one commit as squash. For the commit to keep, mark it as pick. Then save the text editor. Git rebase will perform the squash for you. However, since this is a rebase, do not do this if there are other collaborators working on the same branch.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;&lt;strong&gt;Cleanse a repository&lt;/strong&gt;&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Take BitBucket cloud for example, the size of a remote repo has a &lt;a href="https://confluence.atlassian.com/bitbucket/what-kind-of-limits-do-you-have-on-repository-file-size-273877699.html"&gt;non-expandable hard limit&lt;/a&gt; of 2GB, and a soft limit of 1GB. Once the soft limit is reached, a warning will be displayed on Bitbucket&amp;#8217;s landing page as well as when contributors pushes changes. Once the hard limit is reached, the entire repo will turn read-only mode.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Space consumption can be caused by accidental committing of large file. As covered in the &lt;a href="https://www.digihunch.com/2019/06/git-explained-1-of-2/"&gt;previous post&lt;/a&gt;, files are stored as blob objects in .git directory. If a file was deleted by `git rm` command, it simply means it is de-referenced from the next commit and on. After all, Git as a distributed version control system, has the ability to magically restore the deleted file when we want. The cost of that magic, is that deleted file is permanently stored in the repo, in the form of blob object, although not present in the working directory. It consumes space not only in remote repo, but also in the local repo of each contributor.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The purpose of Git repository is to store source code which are fairly small texts. However if a contributor pushed in large files, it can be tricky to cleanse a Git repo on the remote side. Here is some guidelines:&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&#10;&lt;li&gt; Before cleansing, identify large unwanted files in current working directory, delete them with `git rm` and then commit this change in master branch. &lt;/li&gt;&#10;&lt;li&gt;Consolidate branches (e.g. delete useless remote branches with `git push origin &amp;#8211;delete branch_name`). This step itself does not free up space in remote repo but it simplifies the branches;&lt;/li&gt;&#10;&lt;li&gt;Remove large blob objects and commit objects that reference them. This step essentially is re-writing the commit history of repo. Given the risk, it is recommended to perform this step from a separate local project directory with bare repo only without working directory. &lt;a href="https://www.nicoespeon.com/en/2014/04/clean-git-repo-like-a-boss/"&gt;This article&lt;/a&gt; presents some good advices and illustrations. The command recommended is `git filter-branch -f &amp;#8211;tree-filter &amp;#8220;rm -rf \large_file.zip&amp;#8221; &amp;#8211;prune-empty &amp;#8212; &amp;#8211;all` ; and if that is too slow &lt;a href="https://rtyley.github.io/bfg-repo-cleaner/"&gt;here&lt;/a&gt; is an alternative named BFG Repo-Cleaner.&lt;/li&gt;&#10;&lt;li&gt;After this step, each commit will have a new hash id. For the repo size to reduce, either wait until the next garbage collection on the server side, or request cloud vendor to run a manual garbage collection.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/06/git-explained-1-of-2/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Git Explained 1 of 2&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/07/practical-cryptography-for-it-professional/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Cryptography Basics 1 of 2&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Git Explained 1 of 2</title><link>https://www.digihunch.com/2019/06/git-explained-1-of-2/</link><pubDate>Sat, 08 Jun 2019 22:39:00 -0400</pubDate><guid>https://www.digihunch.com/2019/06/git-explained-1-of-2/</guid><description>&lt;p class="wp-block-paragraph"&gt;In a nutshell, Git is a distributed version control system, commonly used as source control management. It places files in one of three logical areas (working dir, staging, repo) below depending where it is in its lifecycle. &lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img loading="lazy" decoding="async" width="1618" height="992" src="https://www.digihunch.com/wp-content/uploads/2019/10/image.png" alt="" class="wp-image-178"/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;There are many cheetsheets out there but this article will just sort through some concepts unique to Git. To understand how Git works it is crucial to think in terms of Git data model.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Working directory&lt;/strong&gt; a single checkout of one version of the project. These files are pulled out of the object database in the Git directory (upon checkout) and placed in the project directory on disk, for you to use or modify;&amp;nbsp;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Index&lt;/strong&gt; a file contained in your Git directory (stored as binary data in file .git/index) that keeps information about what will go into your next commit.&amp;nbsp;To display what&amp;#8217;s in the index, run `git ls-files &amp;#8211;stage`. Read &lt;a href="https://hackernoon.com/https-medium-com-zspajich-understanding-git-data-model-95eb16cc99f5"&gt;this post&lt;/a&gt; for further details&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Repository&lt;/strong&gt;: where Git stores the metadata and &lt;code&gt;&lt;span style="text-decoration: underline;"&gt;object database&lt;/span&gt;&lt;/code&gt; for your project.&amp;nbsp;The local repository is in .git/ under the project directory.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Add&lt;/strong&gt; &amp;#8211; register one or more modified files to staging area. You may edit several files with only a few needed registered for future commit. Add activity ensures the file edited are recorded in the index (as a preview of next commit). You technically need to run add against each file. But the command syntax with * or . allows you to capture all edits in the same directory or under.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Commit&lt;/strong&gt; &amp;#8211; persist the staged file edits to the repository (so they are stored in Git object database). A commit represents all the file edits that were staged by add command in previous steps.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Branch&lt;/strong&gt; &amp;#8211; a branch is simply a movable pointer to a commit. Default branch name created by git init is called &amp;#8220;master&amp;#8221;. Other than the name, there is nothing special about master branch. Everytime you commit, the master branch pointer moves forward automatically. Branch pointers are kept in .git/refs directory. Read &lt;a href="https://hackernoon.com/understanding-git-branching-2662f5882f9"&gt;this post&lt;/a&gt; for further details.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;HEAD&lt;/strong&gt; &amp;#8211; the pointer to the current branch reference, which is in turn a pointer to the last commit made on that branch. Git use HEAD pointer to know what branch you&amp;#8217;re currently on. HEAD will be the parent of the upcoming commit.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Tag&lt;/strong&gt; &amp;#8211; an annotated tag contains the SHA of the commit being tagged. Alias of a commit.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Merge&lt;/strong&gt; &amp;#8211; choose current commit of other branch and apply it onto your branch.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Rebase&lt;/strong&gt; &amp;#8211; copy all commits from other branch to your branch. Compared to merge, rebasing forms a cleaner commit history.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Cherrypick&lt;/strong&gt; &amp;#8211; choose a previous commit from other branch and apply it onto your branch.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Stash&lt;/strong&gt; &amp;#8211; &amp;nbsp;temporarily stashes changes you&amp;#8217;ve made to working tree so you can work on something else, and then come back and re-apply them later on.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Reset&lt;/strong&gt; &amp;#8211; at a high level, reset is to revert some operations. After pulling code, developer usually follow three steps: editing-&amp;gt;add-&amp;gt;commit. reset is to reverse these steps, based on different modes. The Pro Git reference has further details on the &lt;a href="https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified"&gt;three different modes&lt;/a&gt;:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;strong&gt;soft mode&lt;/strong&gt; (reverse operation of commit): based on what branch HEAD points to, move where that branch points to (e.g. from latest commit, to a different commit several steps up the link);&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;mixed mode&lt;/strong&gt; (default; reverse operation of commit and add) &amp;#8211; in addition to soft mode, also update index;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;hard mode&lt;/strong&gt; (reverse operation of commit, add and file editing)- in addition to mixed mode, also update working directory. Edit on files are discarded.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Git object model&lt;/strong&gt; &amp;#8211; In Git database, files, commits and directories are stored as objects, In Git &lt;a href="https://shafiul.github.io/gitbook/1_the_git_object_model.html"&gt;object model&lt;/a&gt;, there are three types (to tell object type, run `git cat-file -t`). Read &lt;a href="https://hackernoon.com/https-medium-com-zspajich-understanding-git-data-model-95eb16cc99f5"&gt;this post&lt;/a&gt; for further details:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;strong&gt;blob object&lt;/strong&gt; &amp;#8211; stores file data with metadata; use `git show` to examine blob object;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;tree object&lt;/strong&gt; &amp;#8211; represents a directory. It references other tree objects (sub-directories) or blob objects (files under the directory, of a certain version); use `git ls-tree` to examine tree object;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;commit object&lt;/strong&gt; &amp;#8211; represents a commit. It references its parent commit, as well as a tree object that represents the entire project directory. use `git cat-file -p` to inspect commit object;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;This &lt;a href="https://git-scm.com/book/en/v2/Git-Internals-Git-Objects"&gt;diagram&lt;/a&gt; from from Git Pro outlines the interactions amongst these types of objects.&lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img decoding="async" src="https://git-scm.com/book/en/v2/images/data-model-3.png" alt="All the reachable objects in your Git directory."/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;For more details&lt;/strong&gt;, the&amp;nbsp;&lt;a href="https://git-scm.com/book/en/v2"&gt;official documentation&lt;/a&gt;&amp;nbsp;is actually the most helpful reference with illustrations. In addition, I find on Hakcermoon three excellent articles with thorough explanation on&amp;nbsp;&lt;a href="https://hackernoon.com/https-medium-com-zspajich-understanding-git-data-model-95eb16cc99f5"&gt;data model&lt;/a&gt;,&amp;nbsp;&lt;a href="https://hackernoon.com/understanding-git-branching-2662f5882f9"&gt;branching&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://hackernoon.com/understanding-git-index-4821a0765cf"&gt;index&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/05/automation-with-ansible-a-primer/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Set up automation with Ansible&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/06/git-explained-2-of-2/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Git Explained 2 of 2&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Storage Nitty-Gritty 2 of 5 – SAN</title><link>https://www.digihunch.com/2019/05/storage-nitty-gritty-2-5/</link><pubDate>Mon, 06 May 2019 22:06:02 -0400</pubDate><guid>https://www.digihunch.com/2019/05/storage-nitty-gritty-2-5/</guid><description>&lt;p class="wp-block-paragraph"&gt;In &lt;strong&gt;direct attached storage (DAS)&lt;/strong&gt;, storage is server centric and the host owns the storage. The storage is fully dedicated to the server that owns it.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-20.png" alt="" class="wp-image-353" width="346" height="122"/&gt;&lt;figcaption class="wp-element-caption"&gt;With DAS, storage is server-centric&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Storage has evolved into information centric model. In this model, when a new server is deployed in the environment, storage is assigned from the same shared storage pool to the new server.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-21.png" alt="" class="wp-image-354" width="332" height="329"/&gt;&lt;figcaption class="wp-element-caption"&gt;Network based centralized storage solution&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;A network-based storage solution is the centralized storage pool. No single host owns the entire storage pool. The storage solution consists of two categories based on the interface with the host: &lt;strong&gt;SAN (storage area network)&lt;/strong&gt; and &lt;strong&gt;NAS (network attached storage)&lt;/strong&gt;. To a client OS on the host, SAN typically appears as a local disk, allowing block-level access from the client OS, and therefore is more suited for structured workload such as database storage. It operates on its own storage network independent of the host network. NAS on the other hand, typically appears as a file share to the client OS, identified by an IP address and path. This is because NAS operates on the same TCP/IP network where the hosts are operated on. The client has file level access to storage, therefore NAS is better for unstructured data such as video and medical images. It is very important to understand the difference between SAN and NAS.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;SAN deployment consists of two categories based on the connection technology. FC SAN is based on Fibre Channel network; and IP SAN is based on Internet protocol (iSCSI, FCIP, FCoE).&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading" id="h-fibre-channel-san"&gt;&lt;strong&gt;Fibre Channel SAN&lt;/strong&gt;&lt;/h4&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Cable types: &lt;strong&gt;MMF&lt;/strong&gt; (multimode fibre, usually for short distance within data centre because of signal attenuation due to modal dispersion) and &lt;strong&gt;SMF&lt;/strong&gt; (single mode fibre, carries a single ray of light, used for long-distance cable runs;&lt;/li&gt;&#10;&lt;li&gt;Connector: standard connector (SC), lucent connector (LC) and straight tip connector (ST);&lt;/li&gt;&#10;&lt;li&gt;Interconnect device&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;FC hub &amp;#8211; for FC-AL implementation, but no longer in use&lt;/li&gt;&#10;&lt;li&gt;FC switch &amp;#8211; directly route data from one physical port to another (more intelligent than hub)&lt;/li&gt;&#10;&lt;li&gt;Director &amp;#8211; high end switches with redundant components to provide high availability&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;FC connectivity&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;point-to-point: two devices connected directly to each other;&lt;/li&gt;&#10;&lt;li&gt;arbitrated loop (FC-AL): devices are attached to a shared loop;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-23.png" alt="" class="wp-image-356" width="349" height="256"/&gt;&lt;figcaption class="wp-element-caption"&gt;FC- AL (rarely used today)&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;switched fabric (FC-SW): uses switches that can switch data traffic between nodes directly through switch ports. Frames are routed between source and destination by the fabric&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-22.png" alt="" class="wp-image-355" width="458" height="357"/&gt;&lt;figcaption class="wp-element-caption"&gt;Fibre Channel Switched Fabric&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Protocol: &lt;strong&gt;Fibre Channel Protocol (FCP)&lt;/strong&gt;: defines protocol stack (five layers, FC-0 through FC-4), addressing, identification (world wide name), frame, data structure, flow control, fabric services&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-24.png" alt="" class="wp-image-357" width="382" height="231"/&gt;&lt;figcaption class="wp-element-caption"&gt;Fibre Channel Protocol stack&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-25.png" alt="" class="wp-image-358" width="370" height="184"/&gt;&lt;figcaption class="wp-element-caption"&gt;FC frame&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Topology: mesh topology and core-edge fabric topology&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Block-level virtualization&lt;/strong&gt;: aggregates block storage devices (LUNs) and enables provisioning of virtual storage volumes, independent of underlying physical storage. The virtualization layer maps the virtual volumes to the LUNs on the individual arrays. &lt;span style="text-decoration: underline;"&gt;Block-level storage virtualization not only enables extending the storage volumes online; it consolidates heterogeneous storage arrays and enables transparent volume access. It also provides the advantage of non-disruptive data migration, where the virtualization layer handles the back-end migration of data, which enables the LUNs to remain online during migration.&lt;/span&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-27.png" alt="" class="wp-image-360" width="405" height="386"/&gt;&lt;figcaption class="wp-element-caption"&gt;Block-level virtualization (classic)&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-29.png" alt="" class="wp-image-362" width="480" height="450"/&gt;&lt;figcaption class="wp-element-caption"&gt;Federation of block storage across data centers (new generation)&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Virtual SAN (VSAN, aka virtual fabric) &amp;#8211; a logical fabric on an FC SAN, which enables communication among a group of nodes regardless of physical location in the fabric.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h4 class="wp-block-heading" id="h-ip-san"&gt;&lt;strong&gt;IP SAN&lt;/strong&gt;&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;iSCI (one of the IP SAN protocols)&lt;/strong&gt; &amp;#8211; an IP based protocol that establishes and manages connections between host and storage over IP. iSCSI encapsulates SCSI commands and data into an IP packet and transport them using TCP/IP. It is relatively inexpensive and easy to implement so widespread in environments without FC SAN.&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Topology&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Native connectivity (without FC components)&lt;/li&gt;&#10;&lt;li&gt;Bridged connectivity (including FC components in the configuration)&lt;/li&gt;&#10;&lt;li&gt;Combined connectivity (most common because a storage array usually comes with both FC and iSCSI ports)&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-30.png" alt="" class="wp-image-365" width="429" height="554"/&gt;&lt;figcaption class="wp-element-caption"&gt;iSCSI topologies&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Protocol&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;stack: &lt;span style="text-decoration: underline;"&gt;SCSI is the command protocol that works at the application layer of OSI model; iSCSI is session-layer protocol that initiates a reliable session between devices that recognize SCSI commands and TCP/IP&lt;/span&gt;. The iSCSI session-layer interface is responsible for handling login, authentication, target discovery, and session management.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-31.png" alt="" class="wp-image-366" width="485" height="320"/&gt;&lt;figcaption class="wp-element-caption"&gt;iSCSI protocol stack&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;iSCSI session and PDU encapsulation&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-32.png" alt="" class="wp-image-367" width="428" height="111"/&gt;&lt;figcaption class="wp-element-caption"&gt;PDU encapsulation&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;iSCSI discovery &amp;#8211; an initiator must discover the location of its targets on the network and the names of the targets available to it before session establishment. Two types are SendTargets discovery and internet Storage Name Service&lt;/li&gt;&#10;&lt;li&gt;iSCSI names:&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;IQN, iSCSI Qualified Name such as &lt;em&gt;iqn.2008-02.com.example:optional_string&lt;/em&gt;;&amp;nbsp;&lt;/li&gt;&#10;&lt;li&gt;EUI, extended unique identifier such as &lt;em&gt;eui.0300732A32598D26&lt;/em&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;iSCSI command sequencing&lt;/strong&gt; &amp;#8211; A command sequence may generate multiple PDUs. A command sequence number (CmdSN) within an iSCSI session is used for numbering all initiator-to-target command PDUs belonging to the session. This number ensures that every command is delivered in the same order in which it is transmitted, regardless of the TCP connection that carries the command in the session.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;FCIP (one of the IP SAN protocols)&lt;/strong&gt; &amp;#8211; transporting FC block data over the IP infrastructure.&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;protocol stack and packet encapsulation&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-38.png" alt="" class="wp-image-373" width="420" height="199"/&gt;&lt;figcaption class="wp-element-caption"&gt;FCIP protocol stack&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-39.png" alt="" class="wp-image-374" width="385" height="157"/&gt;&lt;figcaption class="wp-element-caption"&gt;FCIP encapsulation&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Topology (FCIP gateway involved):&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-40.png" alt="" class="wp-image-375" width="507" height="365"/&gt;&lt;figcaption class="wp-element-caption"&gt;FCIP topology&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;FCoE (one of the IP SAN protocols)&lt;/strong&gt; &amp;#8211; consolidation of LAN and SAN traffic over a single physical interface infrastructure. FCoE helps organizations address the challenges of having multiple discrete network infrastructures.&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;CNA (converged network adapters) replaces both HBAs and NICs in the server and consolidates both the IP and FC traffic&lt;/li&gt;&#10;&lt;li&gt;Special requirement on cables and switches&lt;/li&gt;&#10;&lt;li&gt;protocol stack and encapsulation&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/11/image-41.png" alt="" class="wp-image-376" width="479" height="273"/&gt;&lt;figcaption class="wp-element-caption"&gt;FCoE field mapping&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;CEE (converged enhanced Ethernet, or lossless Ethernet) provides new specification to existing Ethernet standard that eliminates the lossy nature of Ethernet. This makes 10Gb Ethernet a viable storage networking option, similar to FC. It features the following functionalities as part of IEEE 802.1:&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;PFC (priority-based flow control)&lt;/li&gt;&#10;&lt;li&gt;ETS (enhanced transmission selection)&lt;/li&gt;&#10;&lt;li&gt;CN (congestion notification)&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h4 class="wp-block-heading" id="h-related-postings"&gt;Related Postings&lt;/h4&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/03/storage-nitty-gritty-1-5/"&gt;Disk and RAID&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/07/storage-nitty-gritty-3-of-5-nas-and-object-storage/"&gt;NAS and Object Storage&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/10/storage-nitty-gritty-4-of-5-backup-and-archive-solutions/"&gt;Backup and Archive Solution&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://www.digihunch.com/2019/11/storage-nitty-gritty-5-of-5-replication/"&gt;Replication&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/04/application-i-o-characteristics/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Application I/O Characteristics&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/05/automation-with-ansible-a-primer/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Set up automation with Ansible&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Application I/O Characteristics</title><link>https://www.digihunch.com/2019/04/application-i-o-characteristics/</link><pubDate>Sat, 20 Apr 2019 22:09:00 -0400</pubDate><guid>https://www.digihunch.com/2019/04/application-i-o-characteristics/</guid><description>&lt;p class="wp-block-paragraph"&gt;There are many unknown factors and randomness when a solution architect determines storage requirement for an application. However, this process should still be as scientific as it can be and here are some of the important considerations regards application I/O characteristics.&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading"&gt;Random and Sequential&lt;/h4&gt;&#10;&lt;figure class="wp-block-table is-style-regular"&gt;&lt;table class="has-background" style="background-color:#e9fbe5"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;Random I/O&lt;/td&gt;&lt;td&gt;Sequential I/O&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Description&lt;/td&gt;&lt;td&gt;Successive read/write operations from noncontiguous addresses &amp;#8211; accesses that are spread across the addressable capacity of the LUN.&lt;/td&gt;&lt;td&gt;Successive read/write operations from contiguous addresses: one logical block address after another. In sequential I/O access, disk seek time is reduced because the read/write head moves little to access the next block.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Example&lt;/td&gt;&lt;td&gt;Messaging&lt;br&gt;OLTP application&lt;/td&gt;&lt;td&gt;Data Backup&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;h4 class="wp-block-heading"&gt;Reads and Writes&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Another aspect of the I/O workload is the ratio of read I/Os to write I/Os generated by application. The sum of the read and write rate is the I/O rate (number of I/O operations per second). The application&amp;#8217;s I/O rate is one of the important factors that determine the minimum number of disks required for application. In storage systems, cache plays an important role to improve the system performance. The table below summarizes how read I/O and write I/O interact with cache.&lt;/p&gt;&#10;&lt;figure class="wp-block-table"&gt;&lt;table class="has-background" style="background-color:#e9fbe5"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;I/O Type&lt;/td&gt;&lt;td&gt;READ&lt;/td&gt;&lt;td&gt;WRITE&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Random&lt;/td&gt;&lt;td&gt;Hard to effectively cache because of difficulty in predicting prefetch;&lt;br&gt;Requires multiple fast disks for good performance&lt;/td&gt;&lt;td&gt;Caching is effective, resulting in a response time better than disk response time.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Sequential&lt;/td&gt;&lt;td&gt;Caching is extremely effective due to predictability of prefetch;&lt;br&gt;Reads are done at cache speeds;&lt;/td&gt;&lt;td&gt;Caching is effective; cache is flushed quickly because entire disk stripe can be written.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Here are some typical read versus write ratio for common business applications:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;OLTP: 67% reads and 33% writes&lt;/li&gt;&lt;li&gt;DSS (decision support, aka data warehouse or business intelligence): 80%~90% reads to data tables including frequent table scans (sequential reads)&lt;/li&gt;&lt;li&gt;Backup: As long as the file system is not fragmented, file-based backups are sequential&lt;/li&gt;&lt;/ul&gt;&#10;&lt;h4 class="wp-block-heading"&gt;I/O Request Size&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The size of I/O generated by an application may vary depending upon the type of the application. Some of the overhead to execute an I/O is fi xed. If data exists in large chunks, it is more effi cient to transmit larger blocks because a host can move data faster by using larger I/Os than smaller I/Os. The response time of each large transaction is longer than the response time for a single small transaction, but the combined service time of many smaller transactions is greater than a single transaction that contains the same amount of data.&lt;/p&gt;&#10;&lt;figure class="wp-block-table"&gt;&lt;table class="has-background" style="background-color:#e9fbe5"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Application&lt;/td&gt;&lt;td&gt;Seek Type&lt;/td&gt;&lt;td&gt;I/O Request Size&lt;/td&gt;&lt;td&gt;Proportion of I/O as writes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Microsoft Exchange&lt;/td&gt;&lt;td&gt;Random&lt;/td&gt;&lt;td&gt;32KB&lt;/td&gt;&lt;td&gt;Moderate to high&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SAP/Oracle Applications&lt;/td&gt;&lt;td&gt;Random&lt;/td&gt;&lt;td&gt;~8KB&lt;/td&gt;&lt;td&gt;Depends on application&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;RDBMS: Data entry/OLTP&lt;/td&gt;&lt;td&gt;Random&lt;/td&gt;&lt;td&gt;Database or file system page size&lt;/td&gt;&lt;td&gt; Moderate to high &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;RDBMS: Online transaction logs&lt;/td&gt;&lt;td&gt;Sequential&lt;/td&gt;&lt;td&gt;512 byte+&lt;/td&gt;&lt;td&gt;High, except for archiving process&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;RDBMS: Temp Space&lt;/td&gt;&lt;td&gt;Random&lt;/td&gt;&lt;td&gt;Database or file system page size&lt;/td&gt;&lt;td&gt;Very high&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Web file server&lt;/td&gt;&lt;td&gt;75% random, 25% sequential&lt;/td&gt;&lt;td&gt;4KB, 8KB, 64KB&lt;/td&gt;&lt;td&gt;95% read, 5% write&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Web server log&lt;/td&gt;&lt;td&gt;100% sequential&lt;/td&gt;&lt;td&gt;8KB&lt;/td&gt;&lt;td&gt;100% write&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Media Streaming&lt;/td&gt;&lt;td&gt;100% sequential&lt;/td&gt;&lt;td&gt;64KB&lt;/td&gt;&lt;td&gt;98% write; 2% read&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;OS paging&lt;/td&gt;&lt;td&gt;100% sequential&lt;/td&gt;&lt;td&gt;64KB&lt;/td&gt;&lt;td&gt;98% write; 2% read&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/04/build-a-wordpress-site-in-one-hour-with-lightsail/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Lightsail – create a WordPress site in one hour&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/05/storage-nitty-gritty-2-5/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Storage Nitty-Gritty 2 of 5 – SAN&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Lightsail – create a WordPress site in one hour</title><link>https://www.digihunch.com/2019/04/build-a-wordpress-site-in-one-hour-with-lightsail/</link><pubDate>Wed, 10 Apr 2019 01:30:44 -0400</pubDate><guid>https://www.digihunch.com/2019/04/build-a-wordpress-site-in-one-hour-with-lightsail/</guid><description>&lt;p class="wp-block-paragraph"&gt;My challenge with my just revived wordpress.com site is the plug-ins. Even paid premium users cannot install plug-ins for diagram, etc. I don&amp;#8217;t want to upgrade to business plan so I decided to build my own.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;14 years ago in university, I prototyped an intranet site using the Windows, Apache, MySQL, and PHP. It took a few weeks. Nowadays, this is referred to as WAMP stack with WordPress. AWS has a post on the &lt;a href="https://aws.amazon.com/blogs/architecture/wordpress-best-practices-on-aws/"&gt;best practices&lt;/a&gt; for hosting WordPress. However, I just need a single all-in-one server and there are some &lt;a href="https://docs.aws.amazon.com/linux/al2/ug/al2-tutorials.html"&gt;instruction&lt;/a&gt; on that. With Amazon Lightsail it was made a lot easier. The annual cost to host a WordPress site would be $55 in US, given that virtually nobody visits it except myself. The cost consists of:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Domain registration for $13 a year&lt;/li&gt;&#10;&lt;li&gt;Lightsail blueprint for $3.5 a month&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;There are several benefit of using this Lightsail blueprint, such as:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;You can actually SSH into the EC2 instance. This is important to myself in the habit of probing into how things work;&lt;/li&gt;&#10;&lt;li&gt;Resources are all packaged into a fixed price plan. Remember the pesky accidental AWS charges? &lt;/li&gt;&#10;&lt;li&gt;You have the whole LAMP stack pre-installed, with the bitnami image for WordPress;&lt;/li&gt;&#10;&lt;li&gt;Start small but with scalability.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;To start with Lightsail is extremely intuitive. Just click and launch:&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large is-resized"&gt;&lt;img decoding="async" src="https://www.digihunch.com/wp-content/uploads/2019/06/image.png" alt="" style="width:399px;height:450px"/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;There is a good instruction &lt;a href="https://www.youtube.com/watch?v=upZOhKhefAs"&gt;here&lt;/a&gt; on YouTube. Once launched successfully, there are some post configurations:&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&#10;&lt;li&gt;Request a static IP and assign it to the EC2 instance;&lt;/li&gt;&#10;&lt;li&gt;Register a domain (within Lightsail, with Route53 or any other domain registrar) and create an A record referencing the IP address;&lt;/li&gt;&#10;&lt;li&gt;Create a certificate and set up anto-renewal. &lt;a href="https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-using-lets-encrypt-certificates-with-wordpress"&gt;Here &lt;/a&gt;is an instruction but the steps differ if DNS is managed outside of Lightsail;&lt;/li&gt;&#10;&lt;li&gt;Redirect http to https. Refer to the &lt;a href="https://docs.bitnami.com/aws/apps/wordpress-multisite/administration/force-https-apache/"&gt;instruction &lt;/a&gt;from bitnami;&lt;/li&gt;&#10;&lt;li&gt;Export from wordpress.com and import the xml into this little site.&lt;/li&gt;&#10;&lt;li&gt;&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Notice that all services relevant to hosting are packaged into a single service called bitnami. In order to restart service, instead of restarting php, httpd and mysql individually, you can run the following:&lt;/p&gt;&#10;&lt;p&gt;# service bitnami stop&lt;br /&gt;&#10;# service bitnami start&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In fact, in /etc/rc5.d or /etc/init.d, I do not find the individual services for httpd or mysql. There is actually an instance of MySQL database in the Instance:&lt;/p&gt;&#10;&lt;p&gt;# mysql -u root -p&lt;br /&gt;&#10;mysql &amp;gt; show databases;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;There you go! Now the site is live. This little &lt;a href="https://www.digihunch.com/2019/04/build-a-wordpress-site-in-one-hour-with-lightsail/"&gt;instruction&lt;/a&gt; will come in handy for rebuilding when this site is blown away 🙂&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading" id="h-migrate-to-new-lightsail-instance"&gt;Migrate to new LightSail instance&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;I have been using the same LightSail instance for 3.5 years and it&amp;#8217;s been stable. By Dec 2022, the version of PHP (7.2.17) has been outdated and I decided to launch a new LightSail instance based on new version of image, which comes with newer version of PHP (8.1.13). Here is a note of my steps:&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&#10;&lt;li&gt;Create a new LightSail instance with the same SSH key, assign a new static IP to it. As soon as the new instance is created, we can access it by IP on HTTP, using the &lt;a href="https://docs.bitnami.com/aws/faq/get-started/find-credentials/"&gt;initial credential&lt;/a&gt; provided.&lt;/li&gt;&#10;&lt;li&gt;We need the latest version of All-in-One WP Migration plugin to perform the migration. Ensure its latest version is installed on both old and new instance. &lt;/li&gt;&#10;&lt;li&gt;Export site to file using All-in-One WP Migration plugin. It should produce a single file with wpress extension. For this site, the site is 450MB by Dec 2022&lt;/li&gt;&#10;&lt;li&gt;For the new site, try to upload the file and notice that the max size allowed is 80MB. I made the following changes:&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;a href="https://docs.bitnami.com/aws/apps/wordpress-multisite/administration/increase-upload-limit-php/"&gt;Change PHP attributes&lt;/a&gt;. Edit /opt/bitnami/php/etc/php.ini at the following attributes:&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;post_max_size = 512M&lt;/li&gt;&#10;&lt;li&gt;upload_max_filesize = 512M&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://help.servmask.com/2018/10/27/how-to-increase-maximum-upload-file-size-in-wordpress/"&gt;Change WordPress attributes&lt;/a&gt;. Create /opt/bitnami/wordpress/.htaccess with the following attributes:&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;php_value upload_max_filesize 512M&lt;/li&gt;&#10;&lt;li&gt;php_value post_max_size 512M&lt;/li&gt;&#10;&lt;li&gt;php_value memory_limit 512M&lt;/li&gt;&#10;&lt;li&gt;php_value max_execution_time 0&lt;/li&gt;&#10;&lt;li&gt;php_value max_input_time 300&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://docs.bitnami.com/aws/faq/administration/control-services/"&gt;Restart services &lt;/a&gt;related to wordpress &lt;/li&gt;&#10;&lt;li&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;Now upload the .wpress file and it should take less than 5 minutes to upgrade. After the process, the new site is imported. Delete useless plugins.&lt;/li&gt;&#10;&lt;li&gt;Port the certificate files, including keys, certificate and certificate chains. In my case, I had to edit the following files:&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;/opt/bitnami/apache/conf/vhosts/wordpress-https-vhost.conf&lt;/li&gt;&#10;&lt;li&gt;/opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf&lt;/li&gt;&#10;&lt;li&gt;/opt/bitnami/apache/conf/bitnami/bitnami.conf&lt;/li&gt;&#10;&lt;li&gt;/opt/bitnami/apache/conf/bitnami/bitnami-ssl.conf&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;Configure HTTP-&amp;gt;HTTPS redirect on the new server. Revisit the files above.&lt;/li&gt;&#10;&lt;li&gt;Change DNS record to point to the new server.&lt;/li&gt;&#10;&lt;li&gt;Browse the site, check page and posts and pay attention to: images, tables, code blocks.&lt;/li&gt;&#10;&lt;li&gt;One common issue is images do not display. Check the image URL. The URL might have been replaced by bad values during import. Use a plugin (e.g. Go Live Update Urls) to correct the URLs in tables.&lt;/li&gt;&#10;&lt;li&gt;Use a plugin to find out broken links such as image, etc and fix the broken links. This should be an ongoing maintenance activity but is particularly worth doing on newly migrated site.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;h4 class="wp-block-heading"&gt;Other little things&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;There are many little things to fix. For example, I need to give transparent images white background. This is because when the site&amp;#8217;s background is black and the transparent area in the diagram will be black too, making diagrams (authored in white background) illegible. To do this, I have to add the following section to the additional CSS setting of the active theme:&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img decoding="async" src="https://www.digihunch.com/wp-content/uploads/2021/07/image-3.png" alt=""/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;WordPress is dynamic site and if you don&amp;#8217;t edit the site often, and don&amp;#8217;t want to start a static site from scratch (e.g. using &lt;a href="https://gohugo.io/"&gt;Hugo &lt;/a&gt;or &lt;a href="https://jekyllrb.com/"&gt;Jekyll&lt;/a&gt; frameworks), you can use WP2Static plugin. Make sure to configure S3 bucket and CloudFront accordingly. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Now, enjoy blogging.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2019/03/storage-nitty-gritty-1-5/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Storage Nitty-Gritty 1 of 5 – Disk and RAID&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/04/application-i-o-characteristics/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Application I/O Characteristics&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Interesting terms and principles</title><link>https://www.digihunch.com/2019/01/interesting-terms-about-unsuccessful-software-project-management/</link><pubDate>Sat, 26 Jan 2019 18:10:05 -0400</pubDate><guid>https://www.digihunch.com/2019/01/interesting-terms-about-unsuccessful-software-project-management/</guid><description>&lt;p class="wp-block-paragraph"&gt;It is enlightening to find out that several things that I struggled at different times in professional life are actually experienced by many predecessors. Some smart people actually coined terms for these phenomena. Although they are somewhat negative, they won&amp;#8217;t go away simply because not being mentioned. Both technical staff and project management professions should be wary of them. Some came out of software project management and some grew out of behavioural economics context. &lt;/p&gt;&#10;&lt;h2 class="wp-block-heading"&gt;Software Delivery&lt;/h2&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Here we go the terms, mostly excerpts from Wikipedia:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Death march project &lt;/strong&gt;&amp;#8211; a project that the participants feel is destined to fail, or that requires a stretch of unsustainable overwork. The general feel of the project reflects that of an actual death march because project members are forced by their superiors to continue the project against the member&amp;#8217;s better judgement. Death marches of the destined-to-fail type usually are the result of unrealistic or overly optimistic expectations in scheduling, feature scope, or both, and often include lack of appropriate documentation or relevant training and outside expertise that would be needed to accomplish the task successfully. Often the death march will involve desperate attempts to right the course of the project by asking team members to work especially grueling hours, or by attempting to &amp;#8220;throw (enough) bodies at the problem&amp;#8221;, often causing burnout.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Software Peter Principle&lt;/strong&gt; &amp;#8211; in software engineering, software Peter principle describes a dying project which has become too complex to be understood even by its own developers. It is well known in the industry as a silent killer of projects, but by the time the symptoms arise it is often too late to do anything about it. Good managers can avoid this disaster by establishing clear coding practices where unnecessarily complicated code and design is avoided. This term is derived from the Peter Principle &amp;#8211; a theory about incompetence in hierarchical organizations. There are mainly three causes of this:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;strong&gt;Loss of conceptual integrity&lt;/strong&gt;: The conceptual integrity of software is a measure of how well it conforms to a single, simple set of design principles. When done properly, it provides the most functionality using the simplest idioms. It makes software easier to use by making it simple to create and learn. Conceptual integrity is achieved when the software design proceeds from a small number of agreeing individuals. For software to maintain conceptual integrity, the design must be controlled by a single, small group of people who understand the code in depth. In projects without a strong architecture team, the task of design is often combined with the task of implementation and is implicitly delegated among the individual software developers. Under these circumstances, developers are less likely to sacrifice personal interest in favour of the interests of the product. The complexity of the product grows as a result of developers adding new designs and altering earlier ones to reflect changes in fashion and individual taste.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Programmer incompetence&lt;/strong&gt;: the best developer should understand what details need to be communicated with people.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Programmer inexperience&lt;/strong&gt;: programmers sometimes make implementation choices that work but have unintended negative consequences. Over time, many such implementation choices degrade the software&amp;#8217;s design, making it increasingly difficult to understand.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Brooks&amp;#8217; law &lt;/strong&gt;&amp;#8211; an observation about software project management according to which &amp;#8220;adding human resources to a late software project makes it later&amp;#8221;. It was coined by Fred Brooks, according to who, there is an incremental person who, when added to a project, makes it take more, not less time. This is similar to the general law of diminishing returns in economics. Brooks admit the law is an outrageous oversimplification, but it captures the general rule. Brooks points the the main factors:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;It takes some time for the people added to a project to become productive. Brooks calls this the &amp;#8220;ramp up&amp;#8221; time. Software projects are complex engineering endeavours, and new workers on the project must first become educated about the work that has preceded them; this education requires diverting resources already working on the project, temporarily diminishing their productivity while the new workers are not yet contributing meaningfully. New worker may even make negative contributions, for example, if they introduce bugs that move the project further from completion.&lt;/li&gt;&#10;&lt;li&gt;Communication overhead increases as the number of people increase. Due to combinatorial explosion, the number of different communication channels increases rapidly with the number of people. Everyone working on the same task needs to keep in sync, so as more people are added they spend more time trying to find out what everyone else is doing.&lt;/li&gt;&#10;&lt;li&gt;Adding more people to a highly divisible task, such as cleaning rooms in a hotel, decreases the overall task duration (up to the point where additional workers get in each other&amp;#8217;s way). However, other tasks including many specialties in software projects are less divisible; Brooks points out this limited divisibility; Brooks points out this limited divisibility with another example: while it takes one woman nine months to make one baby, nine women can&amp;#8217;t make a baby in one month.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Escalation of commitment&lt;/strong&gt; &amp;#8211; a human behaviour pattern in which an individual or group facing increasingly negative outcomes from a decision, action, or investment, nevertheless continues the behaviour instead of altering course. The actor maintains behaviours that are irrational, but align with previous decisions and actions. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Cowboy coding&lt;/strong&gt; &amp;#8211; the development process where autonomous developers in control of schedule, algorithms, frameworks and coding style work with minimal process or discipline. Usually it occurs when there is little participation by business users or fanned by management that controls only non-development aspects of the project, such as the broad targets, timelines, scope and visuals (the &amp;#8220;what&amp;#8221;, but not the &amp;#8220;how&amp;#8221;)&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Conway&amp;#8217;s law&lt;/strong&gt; &amp;#8211; organizations design systems which mirror their own communication structure. The law is based on the reasoning that in order for a software module to function, multiple authors must communicate frequently with each other. Therefore, the software interface structure of a system will reflect the social boundaries of the organization(s) that produced it, across which communication is more difficult. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Goodhart&amp;#8217;s law&lt;/strong&gt; &amp;#8211; When a measure becomes a target, it ceases to be a good measure.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Murphy&amp;#8217;s law&lt;/strong&gt; &amp;#8211; Anything that can go wrong will go wrong.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;KISS principle&lt;/strong&gt; &amp;#8211; &amp;#8220;Keep it simple, stupid&amp;#8221;, as a design principle, it states that most systems work best if they are kept simple rather than made complicated; therefore, simplicity should be a key goal in design, and unnecessary complicity should be avoided.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Boondoggle &lt;/strong&gt;&amp;#8211; a project that is considered a waste of both time and money, yet is often continued due to extraneous policy or political motivations.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Optimism bias&lt;/strong&gt; &amp;#8211; a cognitive bias that causes someone to believe that they themselves are less likely to experience a negative event. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Planning fallacy&lt;/strong&gt; &amp;#8211; a phenomenon in which predictions about how much time will be needed to complete a future task display an optimism bias and underestimate the time needed. This phenomenon sometimes occurs regardless of the individual&amp;#8217;s knowledge that past tasks of a similar nature have taken longer to complete than generally planned. The bias only affects predictions about one&amp;#8217;s own tasks. When outside observers predict task completion times, they show a pessimistic bias, overestimating the time needed. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Separation of concerns&lt;/strong&gt; &amp;#8211; a design principle for separating a computer program into distinct sections such that each section addresses a separate concern. A concern is a set of information that affects the code of a computer program. A concern can be as general as &amp;#8220;the details of the hardware for an application&amp;#8221;, or as specific as &amp;#8220;the name of which class to instantiate&amp;#8221;. A program that embodies SoC well is called a modular program. Modularity, and hence separation of concerns, is achieved by encapsulating information inside a section of code that has a well-defined interface. Encapsulation is a means of information hiding. Layered designs in information systems are another embodiment of separation of concerns (e.g., presentation layer, business logic layer, data access layer, persistence layer).&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;DRY principle &lt;/strong&gt;&amp;#8211; Don&amp;#8217;t Repeat Yourself. Every piece of knowledge must have a single, unambiguous, authoritative representation within a system. The principle has been formulated by Andy Hunt and Dave Thomas in their book The Pragmatic Programmer. They apply it quite broadly to include &amp;#8220;database schemas, test plans, the build system, even documentation&amp;#8221;.[3] When the DRY principle is applied successfully, a modification of any single element of a system does not require a change in other logically unrelated elements. Additionally, elements that are logically related all change predictably and uniformly, and are thus kept in sync. This principle is aimed at reducing repetition of software patterns, replacing it with abstractions or using data normalization to avoid redundancy.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;YAGNI principle&lt;/strong&gt; &amp;#8211; You Aren&amp;#8217;t Gonna Need It. Always implement things when you actually need them, never when you just foresee that you need them.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Golden Hammer &lt;/strong&gt;&amp;#8211; aka &lt;a href="https://en.wikipedia.org/wiki/Law_of_the_instrument"&gt;Law of Instrument&lt;/a&gt;, a cognitive bias that involves an over-reliance on a familiar tool. It is a form of narrow-minded instrumentalism.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Shturmovshchina&lt;/strong&gt; &amp;#8211; last minute rush, a common Soviet work practice of frantic and overtime work at the end of a planning period in order to fulfill the planned production target. The practice usually give rise too poor quality.&lt;/p&gt;&#10;&lt;h2 class="wp-block-heading" id="h-principles-more-relevant-software-development"&gt;Principles more relevant software development&lt;/h2&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Least Knowledge&lt;/strong&gt; (aka &lt;strong&gt;&lt;a href="https://www.infoworld.com/article/3136224/demystifying-the-law-of-demeter-principle.html#:~:text=The%20Law%20of%20Demeter%20(or,internal%20details%20of%20other%20objects."&gt;Law of demeter&lt;/a&gt;&lt;/strong&gt;): this principle states that an object should never know the internal details of other objects. The dependencies between packages should be in the direction of the stability of the packages. A package should only depend upon packages that are more stable than it is.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Stable Dependencies&lt;/strong&gt;: The dependencies between packages should be in the direction of the stability of the packages. A package should only depend upon packages that are more stable than it is. In &lt;a href="https://wiki.c2.com/?StableDependenciesPrinciple"&gt;Stable Dependencies principle&lt;/a&gt;, &amp;#8220;Stable&amp;#8221; roughly means &amp;#8220;hard to change&amp;#8221;, whereas &amp;#8220;instable&amp;#8221; means &amp;#8220;easy to change&amp;#8221;.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;SOLID&lt;/strong&gt;: &lt;a href="https://www.digitalocean.com/community/conceptual-articles/s-o-l-i-d-the-first-five-principles-of-object-oriented-design"&gt;SOLID&lt;/a&gt; is an acronym for five principles for OOP. The five principles are: Single-responsibility, Open-closed, Liskov Substitution, Interface Segregation, Dependency Inversion. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Inversion of Control (IoC)&lt;/strong&gt;: &lt;a href="https://en.wikipedia.org/wiki/Inversion_of_control"&gt;Inversion of control&lt;/a&gt; (IoC) is a design pattern in which custom-written portions of a computer program receive the flow of control from a generic framework.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Boy Scout Rule&lt;/strong&gt;: Always leave the code better than you found it.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Persistence Ignorance (PI)&lt;/strong&gt;: The &lt;a href="https://deviq.com/principles/persistence-ignorance"&gt;principle of Persistence Ignorance (PI)&lt;/a&gt; holds that classes modeling the business domain in a software application should not be impacted by how they might be persisted. For example, application code should not be affected by the chosen technology for underlying database or persistence storage. Business Logic should be independent of underlying technology for persistent storage.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Bounded Context&lt;/strong&gt;: &lt;a href="https://martinfowler.com/bliki/BoundedContext.html"&gt;Bounded Context&lt;/a&gt; is a concept in domain driven design that is often used in &lt;a href="https://learn.microsoft.com/en-us/azure/architecture/microservices/model/domain-analysis#define-bounded-contexts"&gt;microservice&lt;/a&gt; design. It provides a way of tackling complexity in large applications or organizations by breaking it up into separate conceptual modules. Each conceptual module then represents a context that is separated from other contexts (hence, bounded), and can evolve independently. Each bounded context should ideally be free to choose its own names for concepts within it, and should have exclusive access to its own persistence store.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Cohesion&lt;/strong&gt;: &lt;a href="https://en.wikipedia.org/wiki/Cohesion_(computer_science)#:~:text=In%20computer%20programming%2C%20cohesion%20refers,concept%20served%20by%20that%20class."&gt;cohesion&lt;/a&gt; refers to the degree to which the elements inside a module belong together.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;That&amp;#8217;s it for now. There are some more &lt;a href="https://en.wikipedia.org/wiki/List_of_software_development_philosophies"&gt;software development philosophies&lt;/a&gt; on Wikipedia.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2018/11/the-java-confusions/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Java version confusions&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2019/02/package-repository-management-in-linux/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Package Repository Management for Linux&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Redhat Firewall configuration: from iptables to firewalld</title><link>https://www.digihunch.com/2018/10/redhat-firewall-configuration-firewalld-vs-iptables/</link><pubDate>Fri, 12 Oct 2018 17:56:00 -0400</pubDate><guid>https://www.digihunch.com/2018/10/redhat-firewall-configuration-firewalld-vs-iptables/</guid><description>&lt;h3 class="wp-block-heading"&gt;Tools to manage firewall&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Packet filter rules in Linux Kernel is managed by an user-space application named iptables in CentOS and RedHat. Since CentOS 7, &lt;a href="https://en.wikipedia.org/wiki/Firewalld"&gt;firewalld&lt;/a&gt; is introduced as an alternative to iptables. Firewalld can be installed and executed as a systemd service, and it is supposed to replace iptables. This &lt;a href="https://www.tecmint.com/firewalld-vs-iptables-and-control-network-traffic-in-firewall/"&gt;article&lt;/a&gt; describes how to configure both. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;There are several advantages in firewalld. One is is the support of &lt;a href="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/security_guide/sec-using_zones_to_manage_incoming_traffic_depending_on_source"&gt;zones&lt;/a&gt;. &lt;a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-firewalld-on-centos-7"&gt;Here&lt;/a&gt; are some useful information. Also, iptables involves three different services for IPv4(iptables), IPv6(ip6tables), and software bridging (ebtables), whereas firewalld only involves a single service to manage all three. Firewalld allows user to add or remove rules/ports from running firewall, without restarting firewall. Unless you have specific reason to use iptables, always use firewalld service to manage firewall. Here is an instruction to firewalld service. In this posting however, we will be focusing on iptables to understand firewall managment. We also go through an example of opening a TCP port. &lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;How does iptables work&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;When working with iptables, it is important to understand that its related concepts (&lt;strong&gt;tables-&amp;gt;chains-&amp;gt;rules-&amp;gt;criteria and targets&lt;/strong&gt;) and how the &lt;strong&gt;order of rules&lt;/strong&gt; plays a factor. There are five independent &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;tables&lt;/span&gt;&lt;/strong&gt;, each contains a number of &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;chains&lt;/span&gt;&lt;/strong&gt;, either &lt;em&gt;built-in&lt;/em&gt; or &lt;em&gt;user-defined&lt;/em&gt;. Administrators mostly deals with &lt;em&gt;&lt;span style="text-decoration: underline;"&gt;built-in chains&lt;/span&gt;&lt;/em&gt; in &lt;em&gt;&lt;span style="text-decoration: underline;"&gt;filter&lt;/span&gt;&lt;/em&gt; and &lt;em&gt;&lt;span style="text-decoration: underline;"&gt;nat&lt;/span&gt;&lt;/em&gt; tables. The five tables are:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;filter&lt;/strong&gt;: If -t isn&amp;#8217;t specified, this is the default table. It contains built-in chains:&lt;ul&gt;&lt;li&gt;&lt;strong&gt;INPUT&lt;/strong&gt;: for packet destined to local sockets&lt;/li&gt;&lt;li&gt;&lt;strong&gt;FORWARD&lt;/strong&gt;: for packets being routed through the box&lt;/li&gt;&lt;li&gt;&lt;strong&gt;OUTPUT&lt;/strong&gt;: for locally-generated packets&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;nat&lt;/strong&gt;: this table is consulted when a packet that creates a new connection is encountered. It has three built-in chains:&lt;ul&gt;&lt;li&gt;&lt;strong&gt;PREROUTING&lt;/strong&gt;: for altering packets as soon as they come in&lt;/li&gt;&lt;li&gt;&lt;strong&gt;OUTPUT&lt;/strong&gt;: for altering locally generated packets before routing&lt;/li&gt;&lt;li&gt;&lt;strong&gt;POSTROUTING&lt;/strong&gt;: for altering packets as they are about to go out&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;mangle&lt;/strong&gt;: this table is used for specialized packet alternation, with five built-in chains (since kernel 2.4.18): PREROUTING and OUTPUT, INPUT, FORWARD, and POSTROUTING&lt;/li&gt;&lt;li&gt;&lt;strong&gt;raw&lt;/strong&gt;: this table is mainly for configuring exceptions from connection tracking with two built-in chains: PREROUTING and OUTPUT&lt;/li&gt;&lt;li&gt;&lt;strong&gt;security&lt;/strong&gt;: for Mandatory Access Control (MAC) networking rules, with three built-in chains: INPUT, OUTPUT, and FORWARD.&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Under the table (e.g. filter, nat), each chain (e.g. INPUT, OUTPUT, etc) consists of list of &lt;span style="text-decoration: underline;"&gt;&lt;strong&gt;firewall rules&lt;/strong&gt;&lt;/span&gt;. Each rule is made up of two parts defined for the packets:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;Criteria&lt;/strong&gt;: if the packet does not match the criteria, the next rule in the chain is examined; if it does match, then the next rule is specified by the value of the target.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Target&lt;/strong&gt;: what to do if criteria is met. The target can be:&lt;ul&gt;&lt;li&gt;user-defined chain, &lt;/li&gt;&lt;li&gt;one of the target described in iptables-extensions, or &lt;/li&gt;&lt;li&gt;in most cases, one of the special values ACCEPT, DROP or RETURN&lt;ul&gt;&lt;li&gt;&lt;strong&gt;ACCEPT&lt;/strong&gt; &amp;#8211; let the packet through&lt;/li&gt;&lt;li&gt;&lt;strong&gt;DROP&lt;/strong&gt; &amp;#8211; drop the packet on the floor&lt;/li&gt;&lt;li&gt;&lt;strong&gt;RETURN&lt;/strong&gt; &amp;#8211; stop traversing this chain, and resume at &lt;span style="text-decoration: underline;"&gt;next rule in the previous (calling) chain&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The rules, defined in each chain under their tables, can be found in file /etc/sysconfig/iptables. You can find tables (prefix with asterisk *), chains (prefix with colon :), rules under their chains and a statement COMMIT after each table. The iptables process flow illustrates how a packet interact with all these rules under different chains and tables defined in this file: &lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img decoding="async" src="https://miro.medium.com/max/1000/1*OIoNQkH4RTSm-eY2lUMBcQ.jpeg" alt="IPTables and Docker. In this post I will be talking about… | by Edouard Buschini | Medium"/&gt;&lt;figcaption&gt;iptables Process Flow&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Although this big picture looks formidable, an administrator commonly only deals with the green and purple blocks (filter and nat), with the big picture in mind. Here is an example of /etc/sysconfig/iptables file from a newly installed system:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Generated by iptables-save v1.4.21 on Fri Sep 11 23:15:32 2017&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;*filter&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;:INPUT ACCEPT &lt;span style="color:#f92672"&gt;[&lt;/span&gt;0:0&lt;span style="color:#f92672"&gt;]&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;:FORWARD ACCEPT &lt;span style="color:#f92672"&gt;[&lt;/span&gt;0:0&lt;span style="color:#f92672"&gt;]&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;:OUTPUT ACCEPT &lt;span style="color:#f92672"&gt;[&lt;/span&gt;132:17200&lt;span style="color:#f92672"&gt;]&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -p icmp -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -i lo -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -p tcp -m state --state NEW -m tcp --dport &lt;span style="color:#ae81ff"&gt;22&lt;/span&gt; -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -j REJECT --reject-with icmp-host-prohibited&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A FORWARD -j REJECT --reject-with icmp-host-prohibited&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;COMMIT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Completed on Fri Sep 11 23:15:32 2017&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;The rule simply allows SSH traffic. This file will be loaded up on every reboot (specifically, restart of iptables service). So if you have made some changes to rules and you want the change picked up on reboot. The rules should be saved to this file:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ sudo iptables-save &amp;gt; /etc/sysconfig/iptables&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Other than saving rule for reboot, if you simply want to edit the rules (e.g. order of rules is incorrect), you can save the rules to file, modify the file and restore the rule from file:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ sudo iptables-save &amp;gt; ~/iptables.txt&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ sudo vi ~/iptables.txt&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ sudo iptables-restore &amp;amp;lt; ~/iptables.txt&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/a-deep-dive-into-iptables-and-netfilter-architecture"&gt;Here&lt;/a&gt; is some further reading about iptables architecture.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;Anatomy of a rule&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The man page for iptables species the following synopsis:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;iptables [-t table] {-A|-C|-D} chain rule-specification&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rule-specification = [matches...] [target]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;match = -m matchname [per-match-options]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;target = -j targetname [per-target-options]&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;So when you append (-A), delete (-D), insert (-I) or replace (-R) a rule, you need to specify rule specification. The man page further explains that the following parameters make up a rule specification:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;protocol (-p)&lt;/strong&gt;: the protocol of the rule of the packet to check. value can be tcp, udp, icmp, all or any name defined in /etc/protocols.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;match (-m)&lt;/strong&gt;: specifies the name of a match to use and is followed by match options. The match refers to an extension module that tests for a specific property. Those extension modules are documented in the man page of &lt;a href="https://ipset.netfilter.org/iptables-extensions.man.html"&gt;iptables-extensions&lt;/a&gt;. You may specify -m multiple times for different match names, which together make up the condition under which a target is invoked. Matches are evaluated first to last as specified. We often use extensions &lt;em&gt;tcp&lt;/em&gt; and &lt;em&gt;state&lt;/em&gt;. According to iptables-extensions man page, we can specify &amp;#8211;dport followed by port number for the &lt;em&gt;tcp&lt;/em&gt; extension, and &amp;#8211;state followed by value such as NEW or ESTABLISHED for the &lt;em&gt;state&lt;/em&gt; extension.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;jump (-j)&lt;/strong&gt;: specifies the target of the rule, such as ACCEPT, REJECT or DROP.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;source and destination (-s and -d)&lt;/strong&gt;: source and destination IP address or masks. Hostname will work but not recommended since resolution is needed.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;inbound and outbound interface (-i and -o)&lt;/strong&gt;: name of interface via which the packet was received and is going to be sent.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;goto (-g)&lt;/strong&gt;: processing should continue in a user specified chain&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Other&lt;/strong&gt; parameters: -4/&amp;#8211;ipv4, -6/&amp;#8211;ipv6, -c/&amp;#8211;set-counters, -f/&amp;#8211;fragment&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;When we run iptables command to view rules, we need to specify the table (e.g. filter, nat, etc) followed by -S or &amp;#8211;list-rules:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ iptables -t nat -S&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;If you do not specify -t switch, the default (-t filter) is applied. Be aware that in this case, you&amp;#8217;re only seeing rules under filter table, and not all rules under tall tables!&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In the result, for example one line from command &amp;#8220;iptables -S&amp;#8221; may say:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -p tcp -m state --state NEW -m tcp --dport &lt;span style="color:#ae81ff"&gt;9200&lt;/span&gt; -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;The interpretation: appending a rule to INPUT chain of filter table (implicitly specified). The protocol is tcp. The first match extension is state, and the state value shall be NEW. The second match extension is tcp, and the dport value shall be 9200. If the packet is a match, then the target (action) is ACCEPT.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;Managing rules&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;As mentioned earlier, rules can be dumped to any file or /etc/sysconfig/iptables, in which the rules are assessed in order. Below is a real life iptables file with a nat table as well. &lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# Generated by iptables-save v1.4.21 on Wed Jan 15 13:58:39 2017&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;*filter&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;:INPUT DROP [0:0]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;:FORWARD DROP [0:0]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;:OUTPUT ACCEPT [4:208]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -p icmp -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -i lo -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -s 10.100.160.56/32 -p tcp -m state --state NEW -m tcp --dport 7000:7001 -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -s 10.100.160.56/32 -p tcp -m state --state NEW -m tcp --dport 7199 -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -s 10.100.160.56/32 -p tcp -m state --state NEW -m tcp --dport 9042 -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -s 10.100.160.56/32 -p tcp -m state --state NEW -m tcp --dport 9160 -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -p udp -m state --state NEW -m udp --dport 161 -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -p udp -m state --state NEW -m udp --dport 162 -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -j REJECT --reject-with icmp-host-prohibited&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A FORWARD -j REJECT --reject-with icmp-host-prohibited&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;COMMIT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;*nat&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;:PREROUTING ACCEPT [1:328]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;:INPUT ACCEPT [0:0]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;:OUTPUT ACCEPT [0:0]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;:POSTROUTING ACCEPT [0:0]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A PREROUTING -p tcp -m tcp --dport 2392 -j REDIRECT --to-ports 2398&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A PREROUTING -p tcp -m tcp --dport 2393 -j REDIRECT --to-ports 2398&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A OUTPUT -o lo -p tcp -m tcp --dport 2392 -j REDIRECT --to-ports 2398&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A OUTPUT -o lo -p tcp -m tcp --dport 2393 -j REDIRECT --to-ports 2398&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;COMMIT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# Completed on Wed Jan 15 13:58:39 2017&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;In this example, the nat table defines traffic forwarding: traffic arriving at TCP port 2392 and 2393 are forwarded to port 2398; outgoing traffic to port 2392 and 2393 are also redirected to port 2398. These rules do not overlap each other so the rules probably don&amp;#8217;t matter.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;On the other hand, the tcp filter table lists the rules to open certain TCP and UDP ports. Its block starts with a couple accepting rules and ends with a couple reject rules (regardless of protocols or ports). This is a good way to close a chain of rules with security. However, if you need to add additional rules to open more TCP ports, the new rule should not be appended after the reject rules at the bottom since the order matter here!&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;Correct way to open a TCP port&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;It&amp;#8217;s a common task for developers to open a TCP port simply for the purpose of bring up a web service and make it accessible to client. If we simply add a new rule to existing list, for example:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 9870 -j ACCEPT&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# iptables -S&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-P INPUT ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-P FORWARD ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-P OUTPUT ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -p icmp -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -i lo -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -p tcp -m state --state NEW -m tcp --dport &lt;span style="color:#ae81ff"&gt;22&lt;/span&gt; -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -j REJECT --reject-with icmp-host-prohibited&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -p tcp -m state --state NEW -m tcp --dport &lt;span style="color:#ae81ff"&gt;9870&lt;/span&gt; -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A FORWARD -j REJECT --reject-with icmp-host-prohibited&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# systemctl reload iptables&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;You will notice that the rule is appended to the end of INPUT block, below the INPUT REJECT rule, which will never take effect.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;To address this, you can use iptables-save and iptables-restore to export, edit to correct order and reload the rule, as illustrated above, instead of using iptables command to modify the rule directly. &lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# iptables-save &amp;gt; /tmp/rule.list&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# vi /tmp/rule.list&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# iptables-restore &amp;lt; /tmp/rule.list&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# iptables -S&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-P INPUT ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-P FORWARD ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-P OUTPUT ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -p icmp -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -i lo -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -p tcp -m state --state NEW -m tcp --dport &lt;span style="color:#ae81ff"&gt;22&lt;/span&gt; -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -p tcp -m state --state NEW -m tcp --dport &lt;span style="color:#ae81ff"&gt;9870&lt;/span&gt; -j ACCEPT&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A INPUT -j REJECT --reject-with icmp-host-prohibited&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-A FORWARD -j REJECT --reject-with icmp-host-prohibited&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Alternatively, you could use some advanced iptables command switches to add the new rule to certain line number with &amp;#8211;line-number switch. &lt;a href="https://www.osetc.com/en/linux-iptables-insert-rule-at-a-specific-position-prepend-firewall-rule.html"&gt;Here&lt;/a&gt; is more information.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2018/09/log-shipping-through-elk/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Log shipping through ELK&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2018/11/the-java-confusions/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Java version confusions&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>A review of vSphere virtualization technologies</title><link>https://www.digihunch.com/2018/07/overview-of-vsphere/</link><pubDate>Sat, 21 Jul 2018 15:54:00 -0400</pubDate><guid>https://www.digihunch.com/2018/07/overview-of-vsphere/</guid><description>&lt;p class="wp-block-paragraph"&gt;This post is a summary of VMware&amp;#8217;s white paper Introduction to VMware vSphere.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;ESXi &lt;/span&gt;&lt;/strong&gt;is the hypervisor (virtualization layer) on bare metal servers that abstracts processor, memory, storage and networking resources into multiple virtual machines. It was previously known as ESX and VMware discontinued ESX at version 4.1 so only ESXi is provided at and above version 5.0. &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;vSphere &lt;/span&gt;&lt;/strong&gt;is the platform to view, configure and manage the key aspects of virtualization, including:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;computing and memory resources (hosts, clusters and resource pools)&lt;/li&gt;&lt;li&gt;storage resources (data stores)&lt;/li&gt;&lt;li&gt;networking resources (networks)&lt;/li&gt;&lt;li&gt;virtual machines&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Under vSphere product family, vCenter Server is the central point for configuring, provisioning and managing the virtual environment. vShphere client is a client application to connect remotely to vCenter Server, or ESXi from any Windows PC. There is also vSphere Web Access for users from non-Windows environment.&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="550" height="511" src="https://www.digihunch.com/wp-content/uploads/2020/08/image-8.png" alt="" class="wp-image-1264"/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;For each aspects of virtualization, there is some vSphere features.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;Computing&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;A &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;host &lt;/span&gt;&lt;/strong&gt;is a virtual representation of of the computing and memory resources of a physical machine running ESXi. When two or more physical machines are grouped to work and be managed as a whole, the aggregate computing and memory resources form a &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;cluster&lt;/span&gt;&lt;/strong&gt;. Physical machines can be dynamically added to or removed from a cluster. A cluster acts and can be managed as a single entity. It represents the aggregate computing and memory resources of a group of physical x86 servers sharing the same network and storage arrays. Computing and memory resources from hosts and clusters can be finely partitioned into a hierarchy of &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;resource pools&lt;/span&gt;&lt;/strong&gt;. &lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="441" height="499" src="https://www.digihunch.com/wp-content/uploads/2020/08/image-1.png" alt="" class="wp-image-1253"/&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;You can dynamically change &lt;strong&gt;resource allocation policies&lt;/strong&gt; without shutting down the associated VMs. When reserved resources are not being used by a resource pool or a VM, the resources can be shared. This helps to maximize resource use while also ensuring that reservations are met and resource policies enforced.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;ESXi provides a &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;memory compression cache &lt;/span&gt;&lt;/strong&gt;to improve VM performance when you use memory overcommitment. Memory compression is enabled by default. When a hosts memory becomes overcommitted, ESXi compresses virtual pages and stores them in memory. This is because accessing compressed memory is faster than accessing memory that has been swapped out to disk. Memory compression in ESXi allows you to overcommit memory without hindering performance. When a virtual page needs to be swapped, ESXi first attempts to compress the page. Pages that can be compressed to 2KB or smaller are stored in the VM&amp;#8217;s compression cache, increasing the capacity of the host.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;High Availability&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;VMware vMotion&lt;/span&gt;&lt;/strong&gt; enables the migration of running VMs from one physical server to another without service interruption. The effect is a more efficient assignment of resources across physical servers. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;Storage vMotion&lt;/span&gt;&lt;/strong&gt; enables the migration of VMs from one datastore to another datastore without service interruption. This allows administrators to off-load VMs from one storage array to another. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;VMware DRS (distributed resource scheduler)&lt;/span&gt;&lt;/strong&gt; helps you manage a cluster of physical hosts as a single compute resource. You can configure DRS to execute VM placement, VM migration, and host power actions. When you create a VM on a cluster, DRS places the VM in such a way as to ensure that load across the cluster is balanced, and cluster-wide resource allocation policies (e.g. reservations, priorities, and limits) are enforced. When you add a new physical server to a cluster, DRS enables VMs to immediately take advantage of the new resources. When a VM is powered on, DRS performs an initial placement of the VM on a host. As cluster conditions (e.g. load and available resources) change over time, DRS migrates (using vMotion) VMs to other hosts as necessary.&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="615" height="338" src="https://www.digihunch.com/wp-content/uploads/2020/08/image-3.png" alt="" class="wp-image-1257"/&gt;&lt;figcaption&gt;VMware DRS&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;When &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;DPM (distributed power management)&lt;/span&gt;&lt;/strong&gt; is enabled, the system compares cluster-level and host-level capacity to the demands of VMs running in the cluster. If the resource demands of the running VMs can be met by a subset of hosts in the cluster, DPM migrates the VMs to this subset and powers down the hosts that are not needed. When resource demands increase, DPM powers these hosts back on and migrates the VMs to them. This dynamic cluster right-sizing that DPM performs reduces the power consumption of the cluster, without sacrificing VM performance or availability.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;Storage I/O control congestion management&lt;/span&gt;&lt;/strong&gt; allows cluster-wide storage I/O prioritization and enables administrator to set congestion thresholds for I/O shares.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;VMware HA&lt;/span&gt;&lt;/strong&gt; enables quick automated restart of virtual machines on a different physical server within a cluster if a host fails. HA monitors all physical hosts in a cluster and detects host failures. An agent placed on each physical host maintains a heartbeat with the other hosts in the resource pool. Loss of a heartbeat initiates the process of restarting all affected VMs on that host. HA also provides a VM monitoring feature that monitors the status of VM in an HA cluster. If a VM does not generate heartbeats within a specified time, VM monitoring identifies it as having failed and restarts it. HA is configured centrally through vCenter Server and once configured, it operates continuously and in a distributed manner on every ESXi host without needing vCenter Server to stay up.&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="614" height="362" src="https://www.digihunch.com/wp-content/uploads/2020/08/image-2.png" alt="" class="wp-image-1256"/&gt;&lt;figcaption&gt;VMware HA&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;VMware vLockstep&lt;/span&gt;&lt;/strong&gt; technology and VMware Fault Tolerance provides continuous availability by protecting a VM with a shadow copy that runs in virtual lockstep on a separate host. Inputs and events performed on the primary VM are recorded and replayed on the secondary VM to ensure identical state. The secondary VM in virtual lockstep can take over execution at any point without interruption or loss of data.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;Storage&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;Datastores &lt;/span&gt;&lt;/strong&gt;are virtual representations of combinations of underlying physical storage resources in the data center. These physical storage resources include:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;Local SCSI, SAS, or SATA disks attached to the physical machines&lt;/li&gt;&lt;li&gt;Fibre Channel or iSCSI SAN disk arrays&lt;/li&gt;&lt;li&gt;Network Attached Storage (NAS) arrays&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Storage subsystem appears as a virtual SCSI controller connected to one or more virtual SCSI disks. These virtual controllers (BusLogic Parallel, LSI Logic Parallel, LSI Logic SAS and VMware Paravirtual) are the only types of SCSI controllers that a VM can see and access. The virtual SCSI disks are provisioned from datastore. This datastore abstraction is a model that assigns storage space to VMs while insulating the guest from the complexity of the underlying physical storage technology. The guest VM however, is not exposed to Fibre Channel SAN, iSCSI SAN, direct attached storage or NAS.&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="649" height="687" src="https://www.digihunch.com/wp-content/uploads/2020/08/image-5.png" alt="" class="wp-image-1260"/&gt;&lt;figcaption&gt;Storage Architecture&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Each datastore is a &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;VMFS volume&lt;/span&gt;&lt;/strong&gt; on a storage device. Datastore can span multiple physical storage subsystems.&lt;strong&gt; A single VMFS volume&lt;/strong&gt; can contain &lt;strong&gt;one or more LUNs&lt;/strong&gt; from a local SCSI disk array on a physical host, a Fibre Channel disk farm, or iSCSI SAN disk farm. New LUNs added to any of the physical storage subsystems are detected and made available to all existing new datastores. Storage capacity on a previously created datastore can be extended without powering down physical hosts or storage subsystems. &lt;span style="text-decoration: underline;"&gt;If any of the LUNs within a VMFS volume fails, only VMs that use that LUN are affected.&lt;/span&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Each VM is stored as a set of files in a directory in the datastore. The disk storage associated with each VM is a set of files within the guest&amp;#8217;s directory. You can operate on the guest disk storage as an ordinary file, which can be copied, moved, or backed up. New virtual disks can be added to a virtual machine without powering it down. In that case, a &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;virtual disk file (.vmdk) &lt;/span&gt;&lt;/strong&gt;is created in VMFS to provide new storage for the added virtual disk&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;span style="text-decoration: underline;"&gt;VMFS is a clustered file system that leverages shared storage to allow multiple physical hosts to read and write the same storage simultaneously.&lt;/span&gt; VMFS provides on-disk locking to ensure that the same virtual machine is not powered on by multiple servers at the same time. If a physical host fails, the on-disk lock for each VM is released so that VMs can be restarted on other physical hosts. VMFS also features failure consistency and recovery mechanisms, such as distributed journaling, a failure-consisten VM I/O path, and VM state snapshots. These mechanisms can aid quick identification of the cause and recovery from VM, physical host and storage subsystem failures. VMFS also supports &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;raw device mapping (RDM)&lt;/span&gt;&lt;/strong&gt;, which is a mechanism for a VM to have direct access to a LUN on the physical storage subsystem (Fibre Channel or iSCSI only). An RDM is a symbolic link from a VMFS volume to a raw LUN. The mapping makes LUNs appear as files in a VMFS volume. The mapping file, not the raw LUN, is referenced in the VM configuration. When a LUN is opened for access, the mapping file is read to obtain the reference to the raw LUN. Thereafter, reads and writes go directly to the raw LUN rather than going through the mapping file.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&lt;figure class="aligncenter size-large"&gt;&lt;img loading="lazy" decoding="async" width="462" height="577" src="https://www.digihunch.com/wp-content/uploads/2020/08/image-4.png" alt="" class="wp-image-1259"/&gt;&lt;figcaption&gt;Raw Device Mapping&lt;/figcaption&gt;&lt;/figure&gt;&lt;/div&gt;&#10;&lt;h3 class="wp-block-heading"&gt;Networking&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Each VM has one or more &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;vNICs &lt;/span&gt;&lt;/strong&gt;(virtual network interface cards). The guest OS and application program communicate with a vNIC through either a commonly available device driver or a VMware device driver optimized for the virtual environment. In either case, communication in the guest OS occurs just as it would with a physical device. On the network, the vNIC responds to standard Ethernet protocol as would a physical NIC. An outside agent does not detect that it is communicating with a virtual machine.&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="638" height="408" src="https://www.digihunch.com/wp-content/uploads/2020/08/image-7.png" alt="" class="wp-image-1262"/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;A &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;virtual switch (vSwitch) &lt;/span&gt;&lt;/strong&gt;works like a layer 2 physical switch. Each server has its own virtual switches. One one side of the virtual switch are port groups that connect to virtual machines. On the other side are uplink connections to physical Ethernet adapters on the physical server where the virtual switch resides. VMs connect to the outside world through the physical Ethernet adapters that are connected to the virtual switch uplinks. A virtual switch can connect its uplinks to more than one physical Ethernet adapter to enable NIC teaming.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;Port group&lt;/span&gt;&lt;/strong&gt; is a unique concept in the virtual environment. A port group is a mechanism for setting policies that govern the network connected to it. A vSwitch can have multiple port groups. A VM connects its vNIC to a port group instead of to a particular port on the vSwitch, for better network segmentation.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;A &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;vNetwork Distributed Swtich (vDs)&lt;/span&gt;&lt;/strong&gt; function as a single virtual switch across all associated hosts. This functionality allows VMs to maintain consistent network configuration as they migrate across multiple hosts. Like vSwitch, &lt;span style="text-decoration: underline;"&gt;each VDS is a network hub that VMs can use and it can route traffic internally between VMs or link to an external network by connecting to physical Ethernet adapters&lt;/span&gt;. Each vDS can also hae one or more &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;dvPort groups &lt;/span&gt;&lt;/strong&gt;assigned to it. dvPort groups aggregate multiple ports under a common configuration and provide a stable anchor point for VMs connecting to labeled networks.&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="627" height="439" src="https://www.digihunch.com/wp-content/uploads/2020/08/image-6.png" alt="" class="wp-image-1261"/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;When network resource management is enabled, vDS traffic is divided into six network resource pools: FT traffic, iSCSI traffic, vMotion traffic, management traffic, NFS traffic, and VM traffic. You can control the priority of each of these network resource pools.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;vCenter&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;vCenter Server provides centralized managed for data centers. It communicates with the ESXi host agent through the &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;VMware vSphere API&lt;/span&gt;&lt;/strong&gt;. When you first add a host to vCenter Server sends a vCenter Server agent to run on the host. The &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;vCenter Server agent &lt;/span&gt;&lt;/strong&gt;acts as a small vCenter Server to perform many fundamental management functions.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2018/06/dicom-data-encoding/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;DICOM data encoding&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2018/09/log-shipping-through-elk/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Log shipping through ELK&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>DICOM data encoding</title><link>https://www.digihunch.com/2018/06/dicom-data-encoding/</link><pubDate>Sat, 30 Jun 2018 20:42:36 -0400</pubDate><guid>https://www.digihunch.com/2018/06/dicom-data-encoding/</guid><description>&lt;p class="wp-block-paragraph"&gt;DICOM is a standard for medical imaging exchanges, originally in radiology, but later expanded into other departments where mass imaging data are acquired, such as cardiology. One part of the &lt;a href="http://dicom.nema.org/medical/dicom/current/output/html/part01.html"&gt;DICOM standard&lt;/a&gt; defines how to lay out the data without providing any official code implementation. It is up to each vendor to implement their application and declare what parts of DICOM standard they are compliant to in their individual conformance statement. Therefore it is common that different vendors have different perspectives of whether each other&amp;#8217;s implementation is compliant.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Many arguments of this topic revolves around the encoding of DICOM data (or in strict term, Information Object Definition, IOD). In this article I try to clarify DICOM IOD encoding, best practices from vendor support. A more comprehensive coverage of this topic is chapter 5 of &lt;a href="https://www.springer.com/gp/book/9783642108495"&gt;Oleg Pianykh&amp;#8217;s book&lt;/a&gt;, which discussed the basics such as implicit vs explicit VR, big vs little endian.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The very purpose of standard is to determine a common protocol in which two application communicate with each other. A strong standard leaves no room for ambiguity in implementation and unfortunately, many healthcare IT standards are weak standards. When two devices from two vendors fail to communicate properly, the healthcare provider (device buyer) should take the lead of moderation, because they suffer the most pain from proprietary implementation and they benefit the most from good interoperability. In reality however, healthcare organizations with insufficient technical competency in their information technology team, usually leave it in Vendors&amp;#8217; hands to configure integration, with minimum supervision on standard conformance. This allows vendor to put in technologies that are just made to work, but not fully up to standard. This is not optimal. Remember: Proprietary technology = Vendor Lock-In&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;From vendor&amp;#8217;s perspective, the implementation should just comply with DICOM standard. They should not accommodate to third party application that are incorrectly implemented. Vendor&amp;#8217;s responsibility with customer is simply to proof that the data encoding is compliant with DICOM; or if otherwise is discovered, escalate to engineering with low level technical detail. It is a courtesy in the discretion of vendor&amp;#8217;s support operation, to investigate and advise on the integrity of externally sourced DICOM data. In reality however, vendors are pressured to just make it work.&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading"&gt;DICOM Objects&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In DICOM encoding, an IOD, either in a C-Store or a part 10 file consist of hundreds of data elements. A data element (uniquely identified by a tag) can be either:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;A single item;&lt;/li&gt;&lt;li&gt;A sequence (SQ) of multiple items;&lt;/li&gt;&lt;/ul&gt;&#10;&lt;h4 class="wp-block-heading"&gt;Transfer Syntax&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Below is the table that summarizes the metadata and pixel data encoding under different transfer syntax UID specified in (0020,0010). It is not meant to be a completed list.&lt;/p&gt;&#10;&lt;figure class="wp-block-table"&gt;&lt;table class="has-background" style="background-color:#e9fbe5"&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;transfer syntax UID&lt;/th&gt;&lt;th&gt;transfer syntax name&lt;/th&gt;&lt;th&gt;Metadata encoding&lt;/th&gt;&lt;th&gt;Pixel data encoding&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;1.2.840.10008.1.2&lt;/td&gt;&lt;td&gt;Implicit VR Endian: Default Transfer Syntax for DICOM&lt;/td&gt;&lt;td&gt;Implicit VR Little Endian&lt;/td&gt;&lt;td&gt;Implicit VR Little Endian&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1.2.840.10008.1.2.1&lt;/td&gt;&lt;td&gt;Explicit VR Little Endian&lt;/td&gt;&lt;td&gt;Explicit VR Little Endian&lt;/td&gt;&lt;td&gt;Explicit VR Little Endian&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1.2.840.10008.1.2.4.70&lt;/td&gt;&lt;td&gt;JPEG Lossless, Nonhierarchical, First- Order Prediction&lt;br&gt;(Processes 14 [Selection Value 1]):&lt;br&gt;Default Transfer Syntax for Lossless JPEG Image Compression&lt;/td&gt;&lt;td&gt;Explicit VR Little Endian&lt;/td&gt;&lt;td&gt;JPEG Lossless Compression&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1.2.840.10008.1.2.4.80&lt;/td&gt;&lt;td&gt;JPEG-LS Lossless Image Compression&lt;/td&gt;&lt;td&gt;Explicit VR Little Endian&lt;/td&gt;&lt;td&gt;JPEG-LS Lossless Compression&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Practically, Big Endian encoding is rarely used in DICOM. So is .99 so they are not covered. Little Endian simply refers to the reverse ordering of each pair of bytes. The rest of this article only discusses metadata encoding.&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading"&gt;Encoding of Data Element of single item&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Most DICOM parsers out in the market don&amp;#8217;t have a problem with data elements of single items. However it is important to understand the encoding of single item before trying to understand sequence. Regardless of implicit or explicit VR, big or little endian, a&amp;nbsp;single item is always encoded in the following sequence:&lt;/p&gt;&#10;&lt;figure class="wp-block-table"&gt;&lt;table class="has-background" style="background-color:#e9fbe5"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;&lt;br&gt;&lt;br&gt;&lt;/th&gt;&lt;th&gt;Length&lt;/th&gt;&lt;th&gt;Data format&lt;/th&gt;&lt;th&gt;Example&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Tag&lt;/td&gt;&lt;td&gt;Group number&lt;/td&gt;&lt;td&gt;2-byte&lt;/td&gt;&lt;td&gt;unsigned integer&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Element number&lt;/td&gt;&lt;td&gt;2-byte&lt;/td&gt;&lt;td&gt;unsigned integer&lt;/td&gt;&lt;td&gt;0010,0010&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;VR&lt;br&gt;(present only for explicit VR)&lt;/td&gt;&lt;td&gt;2-byte&lt;/td&gt;&lt;td&gt;2 ASCII characters&lt;/td&gt;&lt;td&gt;PN&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Length of Value&lt;/td&gt;&lt;td&gt;2-byte&lt;/td&gt;&lt;td&gt;an even integer&lt;/td&gt;&lt;td&gt;0x000A&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Value&lt;/td&gt;&lt;td&gt;determined by length of value&lt;/td&gt;&lt;td&gt;determined by VR&lt;/td&gt;&lt;td&gt;Smith^Joe&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Note that in the example, length of value is 10 in decimal, and the value &amp;#8220;Smith^Joe &amp;#8221; contains a trailing space to make up for 10 character length. It is required by DICOM that the length be even number of characters, which sometimes omitted and tolerated by different implementations. The corresponding DICOM&amp;#8217;s guideline is&amp;nbsp;&lt;a href="http://dicom.nema.org/medical/dicom/current/output/html/part05.html#chapter_7"&gt;here&lt;/a&gt;. On this page please understand Figure 7.1-1, Table 7.1-1 and 7.1-2 before reading on.&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading"&gt;Encoding of data element with SQ type&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;When it comes to SQ (sequence), there’s much confusion about what are valid options for sequence encoding. There is also a good chance that a third party DICOM interpreter is incompletely implemented, and mistakenly complains correctly-encoded sequence as bad data. Symptoms include, but not limited to, A-ABORT an association, silence a TCP connection, complaining in their logs that the data is “corrupted”.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;a href="http://dicom.nema.org/medical/dicom/current/output/html/part05.html#sect_7.5"&gt;Here&lt;/a&gt;&amp;nbsp;is the reference to DICOM standard as to the valid options for sequence encoding. The language is fairly abstract and I’m making some addition to elucidate it:&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&lt;li&gt;When determining the sequence encoding, DICOM needs to address two problems:&lt;ol&gt;&lt;li&gt;Define how to start and end a data item;&lt;/li&gt;&lt;li&gt;Define how to start and end the entire sequence;&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;You can explicitly specify the length of a data item, or leave it undefined; Similarly for the entire sequence, you can explicitly specify the length upfront, or leave it undefined. This leads to four possible combinations but one of them is invalid. The following table points to an example of each based on the tables in DICOM document:&lt;/li&gt;&lt;/ol&gt;&#10;&lt;figure class="wp-block-table"&gt;&lt;table class="has-background" style="background-color:#e9fbe5"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Sequence Length is explicit&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Sequence Length is undefined&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Data item length is explicit&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Valid Format A&lt;/strong&gt;&lt;br&gt;Exemplified in Table 7.5-1, when sequence length is explicit, length of each individual data item must be explicit as well.&lt;br&gt;&amp;#8211; Sequence length is 0F00H, 3840 bytes&lt;br&gt;&amp;#8211; Data Item length is 04F8H, 1272 bytes&lt;br&gt;&amp;#8211; No delimiter (FFFE,E0DD or FFFE, E00D) is needed for sequence of data element&lt;br&gt;&amp;#8211; Sum of unit length equals total length: (1272 + 4 + 4 ) x 3 = 3840&lt;br&gt;&lt;br&gt;&lt;br&gt;Even though this particular example is implicit VR, the parser should know this is a sequence by the length calculation&lt;br&gt;a. the length of data element (sequence) is 0F00H &lt;/td&gt;&lt;td&gt;&lt;strong&gt; Valid Format B&lt;/strong&gt;&lt;br&gt;Exemplified in Table 7.5-2, as well as the first Item in Table 7.5-3&lt;br&gt;Sequence length is undefined, marked by (FFFF,FFFF) as the length value of data element&lt;br&gt;Data Item length is explicit defined, as follows:&lt;br&gt;&amp;#8211; 98A5 and B321 for the two items in Table 7.5-2&lt;br&gt;&amp;#8211; 17B6 for the first item in Table 7.5-3&lt;br&gt;&amp;#8211; FFFE,E000 marks the start of a data item&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Data Item length is undefined&lt;/strong&gt;&lt;/td&gt;&lt;td&gt; This is NOT a valid encoding option.&lt;br&gt;It would be error prone, if the total length is explicitly defined but the unit length is not.&amp;nbsp; &lt;/td&gt;&lt;td&gt;&lt;strong&gt;Valid Format C&lt;/strong&gt;&lt;br&gt;Exemplified in the second Item in Table 7.5-3&lt;br&gt;&amp;#8211; Sequence length is undefined, marked by (FFFF,FFFF) as the length value of data element&lt;br&gt;&amp;#8211; Data ltem length is also undefined&lt;br&gt;&amp;#8211; FFFE,E00D followed by 00000000H marks the end of the data item&lt;br&gt;&amp;#8211; FFFE,E0DD followed by 00000000H marks the end of the sequence &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;ol class="wp-block-list"&gt;&lt;li&gt;As shown above, there are multiple valid options (A, B and C) to encode data item in a sequence and the entire sequence. If sequence length is undefined, explicit and undefined data item length can even co-exist within the same sequence. (Table 7.5-3)&lt;/li&gt;&lt;li&gt;if the length is left undefined at the beginning, you must clearly mark the end of the data item, or sequence using one of the special data elements.&lt;/li&gt;&lt;/ol&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Special Data Element used in SQ encoding:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;FFFE,E000&lt;/strong&gt;&amp;nbsp;(Data Item) – marks the start of each data item inside of SQ element; it shall be followed by a 4-byte field to indicate the length of the data item (either an explicit value or FFFFFFFFH to indicate undefined length)&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;FFFE,E00D&lt;/strong&gt;&amp;nbsp;(Item Delimitation) – marks the end of each data item&amp;nbsp;only if&amp;nbsp;the length of that data item is undefined; it shall follow the data item immediately and the length of itself shall be set to 00000000H&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;FFFE,E0DD&lt;/strong&gt;&amp;nbsp;(Sequence Delimitation) – marks the end of an entire sequence&amp;nbsp;only if&amp;nbsp;the length of that sequence is undefined; it shall follow the last item of the SQ element and the length of itself shall be set to 00000000H&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2018/06/text-processing-with-linux-bash/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Linux Admin Basics 3 of 3 – text processing, regex, sed &amp;amp; awk&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2018/07/overview-of-vsphere/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;A review of vSphere virtualization technologies&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>cron and anacron in RedHat Linux (How logrotate works)</title><link>https://www.digihunch.com/2018/05/cron-and-logrotate-in-centos/</link><pubDate>Tue, 15 May 2018 14:11:00 -0400</pubDate><guid>https://www.digihunch.com/2018/05/cron-and-logrotate-in-centos/</guid><description>&lt;h4 class="wp-block-heading"&gt;Cron and anacron&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;We all know cron is a job scheduler. Many admin uses crontab to manage scheduled task. It is also important to know that crontab works at different levels as well, as well as the distinction between cron and anacron. They are similar, but different, managed by different sets of files. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Below is a brief description of how cron works from this &lt;a href="https://www.sitepoint.com/a-comprehensive-crash-course-into-cronjobs/"&gt;article&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;After Cron starts, it searches its spool area to find and load crontab files into the memory. It additionally checks the /etc/crontab and or /etc/cron.d directories for system crontabs.&lt;br&gt;After loading the crontabs into memory, Cron checks the loaded crontabs on a minute-by-minute basis, running the events which are due.&lt;br&gt;In addition to this, Cron regularly (every minute) checks if the spool directory’s modtime (modification time) has changed. If so, it checks the modetime of all the loaded crontabs and reloads those which have changed. That’s why we don’t have to restart the daemon when installing a new cron job.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Basically, in cron, you specify a particular time at which a job will run. These jobs are managed by files in &lt;em&gt;/var/spool/cron/ &lt;/em&gt;directory. In this directory, each file is named by the username that owns the crontab file. These files shall not be edited directly by respective users. Instead, they are edited by crontab by each user. To understand the syntax, one can refer to RedHat document for &lt;a href="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-Automating_System_Tasks"&gt;automating system tasks&lt;/a&gt;. Note that you can specify periodical jobs here with special syntax. For example, */5 at the minute slot indicates every five minutes.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Running cron jobs can be allowed or disallowed for different users. For this purpose, use the &lt;em&gt;/etc/cron.allow&lt;/em&gt; and &lt;em&gt;/etc/cron.deny&lt;/em&gt; files. If the cron.allow file exists, a user must be listed in it to be allowed to use cron If the cron.allow file does not exist but the cron.deny file does exist, then a user must not be listed in the cron.deny file in order to use cron. If neither of these files exists, only the super user is allowed to use cron.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In addition, there is a system-wide crontab file in /etc/crontab, in which you need to not only specify tasks, but also the user to run those tasks. By default, the schedule in this file is empty.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The limitation of cron is it assumes the servers is up all the time, if a script misses the schedule while the server is down, it will not be executed when the server comes back up. This is where anacron comes in handy. Although anacron can only be used by superuser, it doesn&amp;#8217;t expect system to be running 24&amp;#215;7. If a job is scheduled at a time system is down, it starts the job when system comes back up. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Both cron and anacron are run by systemd service named crond.service. Although they require different packages installed (cronie vs cronie-anacron). They are also managed by different sets of files as explained below:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&#10;&lt;table id="tablepress-4" class="tablepress tablepress-id-4 tbody-has-connected-cells"&gt;&#10;&lt;thead&gt;&#10;&lt;tr class="row-1"&gt;&#10;&#9;&lt;th class="column-1"&gt;package&lt;/th&gt;&lt;th class="column-2"&gt;file or directory&lt;/th&gt;&lt;th class="column-3"&gt;purpose&lt;/th&gt;&lt;th class="column-4"&gt;example&lt;/th&gt;&#10;&lt;/tr&gt;&#10;&lt;/thead&gt;&#10;&lt;tbody class="row-striping row-hover"&gt;&#10;&lt;tr class="row-2"&gt;&#10;&#9;&lt;td rowspan="2" class="column-1"&gt;cronie&lt;/td&gt;&lt;td class="column-2"&gt;/var/spool/cron/&lt;/td&gt;&lt;td class="column-3"&gt;this directory accommodates files that represents cron jobs for each individual users.&lt;/td&gt;&lt;td class="column-4"&gt;if a file named digihunch contains a valid line, it means that Linux user digihunch has a scheduled task for the time specified.&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr class="row-3"&gt;&#10;&#9;&lt;td class="column-2"&gt;/etc/crontab&lt;/td&gt;&lt;td class="column-3"&gt;This file keeps system-wide cronjob entries. Each line needs to sepcify users.&lt;/td&gt;&lt;td class="column-4"&gt;if a line specifies schedule, user and command, it means that at the scheduled time, that user will execute the command.&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr class="row-4"&gt;&#10;&#9;&lt;td rowspan="3" class="column-1"&gt;cronie-anacron&lt;/td&gt;&lt;td class="column-2"&gt;/var/spool/anacron/&lt;/td&gt;&lt;td class="column-3"&gt;This directory accommodates files such as cron.daily, in which a timestamp is kept to indicate last execution time.&lt;/td&gt;&lt;td class="column-4"&gt;if cron.daily in this directory reads 20180418, it indicates last daily execution time stamp is 20180418&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr class="row-5"&gt;&#10;&#9;&lt;td class="column-2"&gt;/etc/anacrontab&lt;/td&gt;&lt;td class="column-3"&gt;This file tells anacron where in the file system to go for directories for periodical jobs.&lt;/td&gt;&lt;td class="column-4"&gt;Example:&lt;br /&gt;&#10;&lt;code&gt;&lt;br /&gt;&#10;#period in days delay in minutes job-identifier command&lt;br /&gt;&#10;1 5 cron.daily nice run-parts /etc/cron.daily&lt;br /&gt;&#10;7 25 cron.weekly nice run-parts /etc/cron.weekly&lt;br /&gt;&#10;@monthly 45 cron.monthly nice run-parts /etc/cron.monthly&lt;br /&gt;&#10;&lt;/code&gt;&lt;br /&gt;&#10;The file usually also indicates RANDOM_DELAY and START_HOURS_RANGE&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr class="row-6"&gt;&#10;&#9;&lt;td class="column-2"&gt;/etc/cron.hourly/&lt;br /&gt;&#10;/etc/cron.daily/&lt;br /&gt;&#10;/etc/cron.weekly/&lt;br /&gt;&#10;/etc/cron.monthly/&lt;/td&gt;&lt;td class="column-3"&gt;These directories stores script files that anacron needs to execute at different intervals. this is configured in /etc/anacrontab&lt;/td&gt;&lt;td class="column-4"&gt;if script logrotate is present in /etc/cron.daily/, it means the script is to be executed daily&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;!-- #tablepress-4 from cache --&gt;&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading"&gt;An anacron example: logrotate&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Rotating logs is a common task in Linux that can be done by logrotate. To understand how this works, first, make sure cronie-anacron package is installed and crond.service is up. Then examine the /etc/anacrontab file:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# /etc/anacrontab: configuration file for anacron&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# See anacron(8) and anacrontab(5) for details.&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;SHELL&lt;span style="color:#f92672"&gt;=&lt;/span&gt;/bin/sh&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;PATH&lt;span style="color:#f92672"&gt;=&lt;/span&gt;/sbin:/bin:/usr/sbin:/usr/bin&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;MAILTO&lt;span style="color:#f92672"&gt;=&lt;/span&gt;root&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# the maximal random delay added to the base delay of the jobs&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;RANDOM_DELAY&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;45&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# the jobs will be started during the following hours only&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;START_HOURS_RANGE&lt;span style="color:#f92672"&gt;=&lt;/span&gt;3-22&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#period in days delay in minutes job-identifier command&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;5&lt;/span&gt; cron.daily nice run-parts /etc/cron.daily&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#ae81ff"&gt;7&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;25&lt;/span&gt; cron.weekly nice run-parts /etc/cron.weekly&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;@monthly &lt;span style="color:#ae81ff"&gt;45&lt;/span&gt; cron.monthly nice run-parts /etc/cron.monthly&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;This indicates that daily, weekly and monthly jobs are active. Go into /etc/cron.daily/, and examine script logrotate:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#!/bin/sh&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;EXITVALUE&lt;span style="color:#f92672"&gt;=&lt;/span&gt;$?&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; &lt;span style="color:#f92672"&gt;[&lt;/span&gt; $EXITVALUE !&lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#f92672"&gt;]&lt;/span&gt;; &lt;span style="color:#66d9ef"&gt;then&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; /usr/bin/logger -t logrotate &lt;span style="color:#e6db74"&gt;&amp;#34;ALERT exited abnormally with [&lt;/span&gt;$EXITVALUE&lt;span style="color:#e6db74"&gt;]&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fi&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;exit &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;This indicates that logrotate loads configuration from /etc/logrotate.conf, the man page of logrotate explains how this configuration works, along with an example. If you have any custom application where the log file needs rotated, it can be configured in this file.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2018/04/basics-of-linux-os/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Basics Terms in Linux OS&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2018/06/text-processing-with-linux-bash/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Linux Admin Basics 3 of 3 – text processing, regex, sed &amp;amp; awk&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Basics Terms in Linux OS</title><link>https://www.digihunch.com/2018/04/basics-of-linux-os/</link><pubDate>Tue, 24 Apr 2018 19:16:00 -0400</pubDate><guid>https://www.digihunch.com/2018/04/basics-of-linux-os/</guid><description>&lt;p class="wp-block-paragraph"&gt;These are the things quite confusing or abstract while I was at school but now makes lots of sense after many years working with different flavours of OS.&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading"&gt;&lt;strong&gt;GPL and BSD as software license types&lt;/strong&gt;&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The main difference is that BSD (Berkeley Software Distribution) is a permissive (non-protective) license, while GPL(GNU General Public License) is a copyleft (protective) license.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Permissive licenses do not protect the code from being used in non-open source apps and apply no restrictions on the derivatives, while copyleft licenses force the creator of derivatives or re-distributor of the software to open the modified code. Under GPL you can&amp;#8217;t sub-license, meaning, you can’t change any of the original license terms or introduce any of your own. You’re also required to state all the changes you make to the original code. That is why components licensed under GPL and other copyleft licenses should be avoided in commercial products that would later be distributed under proprietary licenses.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The BSD license family (including the Modified BSD License), on the other hand, doesn’t compel you to do any of the above. They have fairly relaxed redistribution terms.&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading"&gt;&lt;strong&gt;GNU/Linux and BSD as operating systems&lt;/strong&gt;&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Unix &lt;/strong&gt;&amp;#8211; the name of the original system designed at AT&amp;amp;T in the 1970s. At the time, it featured a great deal of novelties such as multi-tasking, multi-user support, time sharing, etc. It was made portable by using C language.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Linux Kernel&lt;/strong&gt; &amp;#8211; a free, open-source, monolithic, Unix-like OS kernel. It was conceived and created in 1991 by Linus Torvalds for his personal computer. The word Linux, technically, is just the kernel. By itself, Linux (Kernel) has no place for user to land (e.g. no apps, no commands)&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;GNU/Linux&lt;/strong&gt; &amp;#8211; GNU project has developed a comprehensive set of free software tools for use with Unix and Linux. GNU/Linux involves the software tools along with the Linux Kernel.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;GNU/Linux distribution&lt;/strong&gt; &amp;#8211; ready-to-use full OS, including Linux Kernel, GNU library and tools, whose developers have made a commitment to follow GNU GFSD, X Window and desktop environment (e.g. KDE, GNOME) and includes many pieces of software. GNU/Linux distro is what many people refer to as &amp;#8220;Linux&amp;#8221;, and it includes Debian, Ubuntu, RedHat and CentOS. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;BSD (Berkeley Software Distribution) &amp;#8211; an OS based on Research Unix, originally developed at Bell Labs, eventually grown into a complete operating system. Today, &amp;#8220;BSD&amp;#8221; often refers to its decendants, such as FreeBSD, OpenBSD, NetBSD, or DragonFly BSD. Each of these are both a kernel and an operating system. Another famous BSD descendant is Darwin, which is what Mac OS X based on.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Comparing &amp;#8220;BSD&amp;#8221; with &amp;#8220;Linux&amp;#8221;&lt;/strong&gt; &amp;#8211; Linux is more popular and tends to support new hardware sooner. Typical users usually don&amp;#8217;t feel the difference between them. FreeBSD as desktop OS uses the same GNOME, KDE, or Xfce desktop environments that many flavours of Linux use as well. Although you need to install the desktop environment yourself. Another important difference is the licensing model as mentioned above between GPL and BSD. This article is a good reference about all the differences bewteen &amp;#8220;BSD&amp;#8221; and &amp;#8220;Linux&amp;#8221;&lt;br&gt; https://www.educba.com/linux-vs-bsd/&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading"&gt;&lt;strong&gt;Swap, Cache and Buffer&lt;/strong&gt;&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Swap &lt;/strong&gt;&amp;#8211; swap file or swap partition. The primary function is to substitute disk space for RAM memory when real RAM fills up and more space is needed. The kernel uses a memory management program that detects blocks, aka pages, of memory in which the contents have not been used recently. The memory management program swaps enough of these relatively infrequently used pages of memory out to a special partition on the hard drive specifically designated for “paging”, or swapping. This frees up RAM and makes room for more data to be entered into your spreadsheet. Those pages of memory swapped out to the hard drive are tracked by the kernel’s memory management code and can be paged back into RAM if they are needed.&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;&lt;strong&gt;Swapping &lt;/strong&gt;moves entire process between main memory and secondary storage; this is the original Unix method and can cause severe performance loss;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Paging &lt;/strong&gt;moves small unites of memory (i.e. pages with 4Kbytes). It is more efficient and was added to BSD&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In both cases, least recently used memory is moved to secondary storage and back to main memory only when needed again. In Linux, the term swapping is used to refer to paging. Older Unix-style swapping of entire thread and process is no longer supported.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;CPU Cache&lt;/strong&gt; &amp;#8211; a hardware cache used by CPU to reduce the average time to access data from the main memory. A cache is a smaller, faster memory, located closer to a processor core, which stores copies of the data from frequently used main memory locations. Most CPUs have different independent caches, inclusing insructions and data caches, where the data cache is usually organized as a hierarchy of more cache levels (L1, L2, L3, L4, etc)&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Page Cache (or disk cache)&lt;/strong&gt; &amp;#8211; kept by the OS in computer&amp;#8217;s main memory and controlled by the computer. The OS keeps a page cached in otherwise unused portions of the main memory, resulting in quicker access to the contents of cached pages and overall performance.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Disk Buffer&lt;/strong&gt; &amp;#8211; (or ambiguously called disk cache or cache buffer) the embedded memory in a hard disk drive acting as a buffer between the rest of the computer and the physical hard disk platter that is used for storage. Modern hard disk drives come with 8 to 256 MiB of such memory. Disk buffer is physically distinct from and is used differently from page cache. It is controlled by the microcontroller in the hard disk drive.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;GRUB (GNU GRand Unified Bootloader)&lt;/strong&gt; &amp;#8211; a boot loader package from GNU project. It is predominantly used for Unix-like systems. Current version is GRUB2&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;System call&lt;/strong&gt; &amp;#8211; In computing, a system call is the programmatic way in which a computer program requests a service from the kernel of the operating system it is executed on. This may include hardware-related services (for example, accessing a hard disk drive), creation and execution of new processes, and communication with integral kernel services such as process scheduling. System calls provide an essential interface between a process and the operating system. Below is a list of key system calls:&lt;/p&gt;&#10;&lt;figure class="wp-block-table is-style-stripes"&gt;&lt;table class="has-background" style="background-color:#e9fbe5"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;System Call&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;read()&lt;/td&gt;&lt;td&gt;read bytes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;write()&lt;/td&gt;&lt;td&gt;write bytes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;open()&lt;/td&gt;&lt;td&gt;open a file&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;close()&lt;/td&gt;&lt;td&gt;close a file&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;fork()&lt;/td&gt;&lt;td&gt;create a new process&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;exec()&lt;/td&gt;&lt;td&gt;execute a new program&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;connect()&lt;/td&gt;&lt;td&gt;connect to a network host&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;accept()&lt;/td&gt;&lt;td&gt;accept a network connection&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;stat()&lt;/td&gt;&lt;td&gt;fetch file statistics&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ioctl()&lt;/td&gt;&lt;td&gt;set I/O properties, or other miscellaneous functions&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;mmap()&lt;/td&gt;&lt;td&gt;map a file to the memory address space&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;brk()&lt;/td&gt;&lt;td&gt;extend the heap pointer&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;&lt;a href="http://man7.org/linux/man-pages/man2/syscalls.2.html"&gt;strace &lt;/a&gt;&lt;/strong&gt;is the tool to trace system calls and signals in Linux. &lt;/p&gt;&#10;&lt;h4 class="wp-block-heading"&gt;&lt;strong&gt;sysVinit, runit and systemd&lt;/strong&gt;&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;init &lt;/strong&gt;&amp;#8211; in Unix-based OS, init is the first process started during booting of OS. Init is a daemon process that continues running until the system is shutdown. It is the direct or indirect ancestor of all other processes and automatically adopts all orphaned processes. Init is started by the kernel during the booting process; a kernel panic will occur if the kernel is unable to start it. Init is typically assigned process identifier 1 and its job is to start other programs that are essential to the operation of your system. All other processes are descended from init.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;init systems&lt;/strong&gt;&lt;br&gt; Linux has several options as init systems. For example: sysvinit, runit, systemd and upstart. Here is a comparison of commands involved in managing each. &lt;br&gt; http://unix.cafe/wp/en/2017/07/howto-manage-a-service-in-systemd-sysvinit-upstart-runit-and-openrc/&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;SysV init&lt;/strong&gt; &amp;#8211; System initialization process is handled by the init daemon. One of the original daemon is SysVinit, which is a collection of System V-style init programs. init process starts serially. It is a run-once process during the start of the OS. One task starts only after the last task startup was successful and it was loaded in the memory. This often resulted in delayed and long booting time. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Runit &lt;/strong&gt;&amp;#8211; an init scheme for Unix-like operating systems that initializes, supervises, and ends processes throughout the operating system. It is a replacement of sysvinit and features brevity and simplicity.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Systemd &lt;/strong&gt;&amp;#8211; A init replacement daemon designed to start process in parallel, implemented in a number of standard distribution – Fedora, OpenSuSE, Arch, RHEL, CentOS, etc. Its flexibility comes with more complexity. It is an event driven init system, that not only starts stuff at boot (hence managing dependencies), but also after that. It also keeps track of many things after boot, such as mounts, availability of services, integration with resource management, etc. Because of that, systemd is also good at logging and monitoring. Systemd allows services to start when:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&lt;li&gt;the system boots&lt;/li&gt;&lt;li&gt;a hardware components attaches to the system&lt;/li&gt;&lt;li&gt;other service started&lt;/li&gt;&lt;li&gt;a timer fires&lt;/li&gt;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;To determine which system initialization method your current Linux distribution is using (SysVinit or systemd), simply check process id 1:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt; $ ps -p 1&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading"&gt;&lt;strong&gt;Soft link and hard link&lt;/strong&gt;&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;inode &lt;/strong&gt;&amp;#8211; stores the attributes and disk block locations of a file or directory&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Soft/Symbolic link&lt;/strong&gt; &amp;#8211; essentially a shortcut to another file. The link itself is a separate file, pointing to the destination file or directory. The inode of the file is different from that of the symbolic link. Deleting the destination file will leave the symbolic link file a &amp;#8220;dangling link&amp;#8221;. Symbolic file may also have different permissions from the destination file or directory.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Hard link&lt;/strong&gt; &amp;#8211; essentially an alias of a file. The link itself is not a separate file, and the destination can only be a file (no directory). The inode of the link the the same as the file itself. So there is actually no distinction between destination file and link. Both files are equal. If you delete the file, the link continue to work until the number of hard links to the file becomes zero.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Soft link points to a file by name whereas hard link points by inode number.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://www.digihunch.com/2018/04/centos-remove-swap-safely/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;CentOS – Remove Swap safely&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://www.digihunch.com/2018/05/cron-and-logrotate-in-centos/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;cron and anacron in RedHat Linux (How logrotate works)&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Linux Admin Basics 1 of 3 – Bash</title><link>https://www.digihunch.com/2018/02/linux-tips-and-tricks-in-shell/</link><pubDate>Fri, 02 Feb 2018 21:35:00 -0400</pubDate><guid>https://www.digihunch.com/2018/02/linux-tips-and-tricks-in-shell/</guid><description>&lt;p class="wp-block-paragraph"&gt;This article summarized my time-saving Linux tips, mostly with CentOS environment.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-bash-shortcuts"&gt;Bash Shortcuts&lt;/h3&gt;&#10;&lt;figure class="wp-block-image size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://www.digihunch.com/wp-content/uploads/2020/03/bash.jpg" alt="" class="wp-image-809" width="547" height="215"/&gt;&lt;figcaption class="wp-element-caption"&gt;Bash shortcut illustration&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;These shortcuts save a lot of arrow keystrokes. Some of them may require some tweaking to work on MacOS. &lt;/p&gt;&#10;&lt;figure class="wp-block-table is-style-stripes"&gt;&lt;table class="has-background" style="background-color:#e7f5fe"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;ctrl &amp;#8211; w&lt;/td&gt;&lt;td&gt;delete word&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ctrl &amp;#8211; a&lt;/td&gt;&lt;td&gt;cursor to end of line&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ctrl &amp;#8211; e&lt;/td&gt;&lt;td&gt;cursor to beginning of line&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ctrl &amp;#8211; k&lt;/td&gt;&lt;td&gt;delete to end of line&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ctrl &amp;#8211; u&lt;/td&gt;&lt;td&gt;delete to beginning of line&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ctrl &amp;#8211; l&lt;/td&gt;&lt;td&gt;clear screen&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;cd &amp;#8211; &lt;/td&gt;&lt;td&gt;change to previous directory&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;alt &amp;#8211; b&lt;/td&gt;&lt;td&gt;move cursor back by a word&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;alt &amp;#8211; f&lt;/td&gt;&lt;td&gt;move cursor forward by a word&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;alt &amp;#8211; .&lt;/td&gt;&lt;td&gt;type last parameter of previous command&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;h3 class="wp-block-heading" id="h-job-control"&gt;Job Control&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;We need to first understand the following job states:&lt;/p&gt;&#10;&lt;figure class="wp-block-table is-style-stripes color:black"&gt;&lt;table class="has-background" style="background-color:#e7f5fe"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;Actively running&lt;/td&gt;&lt;td&gt;Displayed in Active Session&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;foreground job&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;suspended job&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;background job&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;These states can be managed by the following shortcut keys:&lt;/p&gt;&#10;&lt;figure class="wp-block-table is-style-stripes"&gt;&lt;table class="has-background" style="background-color:#e7f5fe"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;ctrl &amp;#8211; z&lt;/td&gt;&lt;td&gt;send active job to suspended&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ctrl &amp;#8211; c&lt;/td&gt;&lt;td&gt;send SIGINT to active job to kill it&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;jobs&lt;/td&gt;&lt;td&gt;list jobs with id&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bg&lt;/td&gt;&lt;td&gt;bring a job to background. the current shell still &amp;#8220;owns&amp;#8221; the job&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;fg&lt;/td&gt;&lt;td&gt;bring a job to foreground (by id)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;disown&lt;/td&gt;&lt;td&gt;remove job from current shell&amp;#8217;s job table. the job is still running and can be found by ps command&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;kill&lt;/td&gt;&lt;td&gt;kill a job by id. the job is no longer running and won&amp;#8217;t be found by ps command&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Note 1: running a command &lt;strong&gt;with ampersand(&amp;amp;) at the end starts the process and pushes it to the background&lt;/strong&gt;, so you can continue typing;&lt;/li&gt;&#10;&lt;li&gt;Note 2: an example is to start vim with a file, ctrl-z to push to background, jobs to view, fg + job id to bring it back&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 class="wp-block-heading" id="h-share-screen"&gt;Share Screen&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Different persons may share screen on Linux shell and interact with each other. To do so, everyone need to log on the same server as the same linux user. Then the first person runs:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;screen -S screen_name&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Then the second (and third, etc) person runs:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;screen -x screen_name&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Now everyone can collaborate by seeing what each other is doing and type at the same time. &lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-i-o-redirection"&gt;I/O redirection&lt;/h3&gt;&#10;&lt;figure class="wp-block-table is-style-stripes"&gt;&lt;table class="has-background" style="background-color:#e7f5fe"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;file descriptor&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;input or output expression&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;stdin&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;to read file: 0&amp;lt; or &amp;lt; for short&lt;br&gt;to read a single line: &amp;lt;&amp;lt;&amp;lt;&lt;br&gt;to read multiple lines: &amp;lt;&amp;lt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;stdout&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;to overwrite: 1&amp;gt; or &amp;gt; for short&lt;br&gt;to append: 1&amp;gt;&amp;gt; or &amp;gt;&amp;gt; for short&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;stderr&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;to overwrite: 2&amp;gt;&lt;br&gt;to append: 2&amp;gt;&amp;gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;For example, here is how you display all lines between &amp;#8220;ANYWORD&amp;#8221; (aka &amp;#8220;here document&amp;#8221;):&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;cat &amp;lt;&amp;lt;ANYWORD&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;paragraph&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;after&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;paragraph&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ANDWORD&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;In addition, to redirect between commands, pipe (|) is used. You may also redirect stdout into stderr or the other way round. Below are several examples:&lt;/p&gt;&#10;&lt;figure class="wp-block-table is-style-stripes"&gt;&lt;table class="has-background" style="background-color:#e7f5fe"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;command1 | command2&lt;/td&gt;&lt;td&gt;redirect stdout of command1 to stdin of command2&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;command3 &amp;gt; /dev/null&lt;/td&gt;&lt;td&gt;get rid of stdout from command3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;command4 2&amp;gt; file1&lt;/td&gt;&lt;td&gt;redirect stderr of command4 to file1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;command5 | tee file2&lt;/td&gt;&lt;td&gt;redirect stdout of command5 to stdin for tee command, which display stdout and write to file2 at the same time&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;command6 2&amp;gt;&amp;amp;1&lt;/td&gt;&lt;td&gt;redirect command6&amp;#8217;s stderr into stdout. &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;command7 1&amp;gt;&amp;amp;2&lt;/td&gt;&lt;td&gt;redirect command7&amp;#8217;s stdout into stderr&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Note: in the last two examples, the ampersand just indicates the following number is file descriptor instead of file name. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;For example, in the first command below, stderr is redirected to stdout, and stdout goes to file. The second and third commands are just two forms of shortcut for the first:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;command &amp;gt; file 2&amp;gt;&amp;amp;1&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;command &amp;gt;&amp;amp; file&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;command &amp;amp;&amp;gt; file&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Here is an advanced example to compare two files from two different servers:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;diff &amp;lt;&lt;span style="color:#f92672"&gt;(&lt;/span&gt;ssh user@host1 &lt;span style="color:#e6db74"&gt;&amp;#39;cat /tmp/file1.txt&amp;#39;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt; &amp;lt;&lt;span style="color:#f92672"&gt;(&lt;/span&gt;ssh user@host2 &lt;span style="color:#e6db74"&gt;&amp;#39;cat /tmp/file2.txt&amp;#39;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;With the knowledge of I/O redirection, let&amp;#8217;s compare the efficiency of the following two commands in dealing with a huge file:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;cat huge.file | mycmd&lt;/li&gt;&#10;&lt;li&gt;mycmd &amp;lt; huge.file&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In the first command, cat first causes an I/O read of huge.file, then stdout gets written into pipe buffer. Lastly, the mycmd reads it from its stdin. This is an example of inefficiency. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In the second command, huge.file is provided as stdin to my cmd. Only one read is involved as compared with two read and one write in the previous command. The second command is expected to be three times as fast as the first.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Here is a diagram to illustrate command and I/O redirection:&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="723" height="240" src="https://www.digihunch.com/wp-content/uploads/2020/09/image.png" alt="" class="wp-image-1603"/&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Check out the page for more scenarios. &lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-operators"&gt;Operators&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;First, let&amp;#8217;s introduce some special shell variable and operators:&lt;/p&gt;&#10;&lt;figure class="wp-block-table is-style-stripes"&gt;&lt;table class="has-background" style="background-color:#e7f5fe"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;IFS&lt;/td&gt;&lt;td&gt;A special variable indicating internal field separator&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;;&lt;/td&gt;&lt;td&gt;The ; token just separates commands to run. Use it when you&amp;#8217;d like to combine multiple lines of commands into a single line&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&amp;amp;&amp;amp;&lt;/td&gt;&lt;td&gt;Logical AND operator. When you run command1 &amp;amp;&amp;amp; command2, command2 ONLY runs if command1 returns true (success, or exit status = 0).&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;||&lt;/td&gt;&lt;td&gt;Logical OR operator. When you run command1 &amp;amp;&amp;amp; command2, command2 ONLY runs if command1 does not return false (fail, or exit status != 0)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;{}&lt;/td&gt;&lt;td&gt;command combination operator. e.g. {command1;command2}&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;()&lt;/td&gt;&lt;td&gt;precedence operator&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Note the use of &amp;amp;&amp;amp; and || are fairly common. &amp;amp;&amp;amp; is used when you want to use the first command to provide a good status for the second. || is used when you want to report error about the first command. For example:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;test -d &amp;#34;/tmp/newdir&amp;#34; || mkdir -p &amp;#34;/tmp/newdir&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;test -f &amp;#34;/var/run/app/app.pid&amp;#34; || echo &amp;gt;&amp;amp;2 &amp;#34;ERROR: cannot detect pid&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 class="wp-block-heading"&gt;Attributes&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;I&amp;#8217;ve been using &lt;strong&gt;chown &lt;/strong&gt;and &lt;strong&gt;chmod &lt;/strong&gt;to manipulate owners and file permissions against owners, groups and other users. I recently realized another command &lt;strong&gt;chattr &lt;/strong&gt;(change attribute) which controls file attributes, regardless of users or groups. In other words, if you change the attribute of a file to immutable, then even the owner isn&amp;#8217;t able to change it. Its manual has full list of attributes, but common ones are:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;a -&amp;gt; Append only&lt;/li&gt;&#10;&lt;li&gt;i -&amp;gt; Immutable&lt;/li&gt;&#10;&lt;li&gt;c -&amp;gt; File automatically compressed in kernel.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;For example, the append only attribute is commonly used for log file to prevent any other users from modifying the file. Sometimes we want to keep system files from being changed as well:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;chattr -i /etc/resolv.conf&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo &amp;#34;nameserver 8.8.8.8&amp;#34; &amp;gt; /etc/resolv.conf &#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;chattr +i /etc/resolv.conf&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Whatever attribute that we set with &lt;strong&gt;chattr&lt;/strong&gt;, we can use &lt;strong&gt;lsattr &lt;/strong&gt;to list them. These two commands are in Linux not BSD.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-loop"&gt;Loop&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;If you can tell how many iterations, then use for loop. For example, you want to execute a command for each file in a directory:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; file in /tmp/*.hl7&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;do&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; echo &lt;span style="color:#e6db74"&gt;&amp;#34;Picking File &lt;/span&gt;$file&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; output.txt&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; hl7snd -f &lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;$file&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt; -d destionatiohost:2398 &amp;gt;&amp;gt; output.txt&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; sleep &lt;span style="color:#ae81ff"&gt;2&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;done&lt;/span&gt; &#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;or you may specify range and steps for a for loop: &lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; i in &lt;span style="color:#f92672"&gt;{&lt;/span&gt;1..11..2&lt;span style="color:#f92672"&gt;}&lt;/span&gt; &lt;span style="color:#f92672"&gt;{&lt;/span&gt;13..23..2&lt;span style="color:#f92672"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;do&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; echo &lt;span style="color:#e6db74"&gt;&amp;#34;hostmachine&amp;#34;&lt;/span&gt;$i&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; scp local.file &lt;span style="color:#e6db74"&gt;&amp;#34;hostmachine&amp;#34;&lt;/span&gt;$i:/tmp/&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;done&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Note that the way we use step here is only available on Bash 4.x (check version through variable $BASH_VERSION, reference)&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;If it&amp;#8217;s hard to tell how many iterations, then use while loop. Here are some examples&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Example 1. You want to execute the same command multiple times, each with a line in a file as parameter:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;while&lt;/span&gt; IFS&lt;span style="color:#f92672"&gt;=&lt;/span&gt; read -r var&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;do&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; echo &lt;span style="color:#66d9ef"&gt;$(&lt;/span&gt;date +%Y%m%d:%H%M%S&lt;span style="color:#66d9ef"&gt;)&lt;/span&gt; displaying line &lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;$var&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; resend.log&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; sleep &lt;span style="color:#ae81ff"&gt;2&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;done&lt;/span&gt; &amp;lt; list.txt&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Example 2. One step further, if the input file is a CSV format like this:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;acc1,pid1&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;acc2,pid2&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;acc3,pid3&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;And you want to repeat a command multiple times, each execution with a column 1 as parameter 1, column 2 as parameter 2, etc. Then you can run something like this:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;IFS&lt;span style="color:#f92672"&gt;=&lt;/span&gt;,&lt;span style="color:#66d9ef"&gt;$(&lt;/span&gt;echo -en &lt;span style="color:#e6db74"&gt;&amp;#34;\r\n\b&amp;#34;&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;)&lt;/span&gt;; &lt;span style="color:#66d9ef"&gt;while&lt;/span&gt; read -r f1 f2; &#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;do&lt;/span&gt; &#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo processing $f1, $f2&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;curl -i -X PUT -H &lt;span style="color:#e6db74"&gt;&amp;#34;Content-Type:application/json&amp;#34;&lt;/span&gt; -d &lt;span style="color:#e6db74"&gt;&amp;#39;{&amp;#34;userId&amp;#34;:&amp;#34;dhunch&amp;#34;}&amp;#39;&lt;/span&gt; --url http://localhost:9876/monitoring/document/$f1/$f2/publish;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;done&lt;/span&gt; &amp;lt; input.txt &amp;gt;&amp;gt;out.txt&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;In this example IFS assignment is done before while loop. So it will take effect outside of while loop. This is why \r, \n and \b are specified in addition to comma. If this is not something you like, you may put IFS assignment after while and only specify comma as field separator.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Example 3. If you just want to repeat the same command every 5 seconds, apart from watch command, you can leverage while loop doing something like this:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;while&lt;/span&gt; true; &lt;span style="color:#66d9ef"&gt;do&lt;/span&gt; df -Ph | grep &lt;span style="color:#e6db74"&gt;&amp;#34;sda1&amp;#34;&lt;/span&gt;; sleep 10; &lt;span style="color:#66d9ef"&gt;done&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;In fact in all these examples while loop can be expressed in a single line, with semicolon to indicate where you would have typed enter.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-find-with-xargs-and-exec"&gt;find, with xargs and -exec {}&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The find command offers flexibility searching files with certain conditions.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Example 1. Find files from within last 5 * 24 hours in current directory:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;find -maxdepth &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt; -type f -mtime -5&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Example 2. Find tar files older than 6 * 24 hours:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;find . -type f -name &lt;span style="color:#e6db74"&gt;&amp;#34;*.tar&amp;#34;&lt;/span&gt; -mtime +6&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Notes:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;the switch -iname is similiar to -name but case insensitive&lt;/li&gt;&#10;&lt;li&gt;the switch -mtime goes by modified datetime; -atime goes by access time&lt;/li&gt;&#10;&lt;li&gt;the switch -mmin measures in minutes&lt;/li&gt;&#10;&lt;li&gt;the swtich -daystart makes it measure time from the beginning of current day (instead of 24 hours from current time of current day)&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;a href="https://www.cyberciti.biz/faq/howto-finding-files-by-date/"&gt;Here&lt;/a&gt; are more information about find command, and &lt;a href="https://www.cyberciti.biz/faq/linux-unix-osxfind-files-by-date/"&gt;more examples&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;To execute command per result from find, we have the options of xargs and -exec {}. Both build command based on parameter input, instead of I/O redirection. xargs is considered more efficient and it also works with commands other than find. -exec {} only works with find command. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Here&amp;#8217;s a basic example of -exec {}&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;find . -iname &lt;span style="color:#e6db74"&gt;&amp;#39;*.dcm&amp;#39;&lt;/span&gt; -exec dcm2txt &lt;span style="color:#f92672"&gt;{}&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;\;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;On the other hand, xargs works with any command followed by a pipe. It takes input from previous command, split it by space or carriage return into a list, then build command with each item on the list. To help understand parameter passing with xargs, we examine two examples. The first example is a directory with three files in it: x.a, y.a, z.a&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ ls&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;x.a x.b x.c&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;If we want to prefix each file with pre, we can do the following:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ls | xargs -I aa echo &lt;span style="color:#e6db74"&gt;&amp;#34;mv aa prefix_aa&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;In the second example, suppose find command produces the following result:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;firstdir&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;seconddir&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;Compare the following two commands:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;find . -type d | xargs ls -l&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;find . -type d | xargs -n &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt; ls -l&#9;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;In the first command, xargs invokes &amp;#8220;ls -l firstdir seconddir&amp;#8221; whereas in the second command, xargs invokes &amp;#8220;ls -l firstdir&amp;#8221; and then &amp;#8220;ls -l seconddir&amp;#8221;. The first command requires that the utility takes multiple parameters (in this case, ls does. Other commands such as wc, grep also do). The second command is particular helpful when the &lt;span style="text-decoration: underline;"&gt;utility only takes one parameter&lt;/span&gt;. This is because the switch -n sets the maximum number of arguments taken from standard input for each invocation of utility.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Last but not least, operators are quite useful in Bash scripting. &lt;a href="https://kapeli.com/cheat_sheets/Bash_Test_Operators.docset/Contents/Resources/Documents/index"&gt;Here &lt;/a&gt;is a good reference.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;p&gt;&lt;a rel="next" href="https://www.digihunch.com/2018/02/tcpdump-and-wireshark/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;TCPdump and Wireshark configuration&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;/nav&gt;&#10;</description></item></channel></rss>