<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sivakumar Kalyanaraman on Medium]]></title>
        <description><![CDATA[Stories by Sivakumar Kalyanaraman on Medium]]></description>
        <link>https://medium.com/@kshivaa?source=rss-53b310cdc957------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*8QPbLRpbqnE5jWvN</url>
            <title>Stories by Sivakumar Kalyanaraman on Medium</title>
            <link>https://medium.com/@kshivaa?source=rss-53b310cdc957------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 08:38:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kshivaa/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Some examples of mechanical sympathy]]></title>
            <link>https://kshivaa.medium.com/some-examples-of-mechanical-sympathy-7ebfe0242c28?source=rss-53b310cdc957------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ebfe0242c28</guid>
            <category><![CDATA[mechanical-sympathy]]></category>
            <category><![CDATA[cas-locks]]></category>
            <category><![CDATA[shared-memory]]></category>
            <dc:creator><![CDATA[Sivakumar Kalyanaraman]]></dc:creator>
            <pubDate>Wed, 23 Dec 2020 09:45:47 GMT</pubDate>
            <atom:updated>2020-12-23T09:45:47.360Z</atom:updated>
            <content:encoded><![CDATA[<p>Examples of mechanical sympathy, encountered in my journey as a performance engineer</p><p><em>The term Mechanical Sympathy was coined by racing driver Jackie Stewart and applied to software by Martin Thompson. Jackie Stewart said, “You don’t have to be an engineer to be be a racing driver, but you do have to have Mechanical Sympathy.” He meant that understanding how a car works makes you a better driver. This is just as true for writing code. You don’t need to be a hardware engineer, but you do need to understand how the hardware works and take that into consideration when you design software.</em></p><p><em>[2020–06–09 </em><a href="https://dzone.com/articles/mechanical-sympathy"><em>https://dzone.com/articles/mechanical-sympathy</em></a><em> ]</em></p><p>This simply means understand the underlying hardware, memory and I/O subsystems and program accordingly so that the code runs optimally and in alignment with the hardware systems designs. Let us study some sample usages of this concept in Low-Latency computing.</p><ol><li>Processor affinity: We are aware of the ‘context switching’ where processes are swapped in and out of a CPU. Given the amount of local cache associated with modern day CPU’s, swapping a process out and in from the same CPU is less costly compared to swapping out from one CPU and swapping in into another CPU. So, it is better to ensure that a process is swapped in/out on the same CPU. At latency requirements in millisecond / microsecond ranges, this has more than 10–15% improvement on the latency. This can be done by setting the affinity for the processor threads (or processes) to ensure that they are bound a CPU.</li><li>Cost of synchronization and use of CAS locks: This is one of the often-talked concepts when it comes to mechanical sympathy. Using system calls for synchronization can cause significant overheads when compared against using CAS locks — simple CPU instructions that allow one to increment / decrement / swap the value at a memory location. This can be used to implement a mutex lock and also solve the multiple readers problems without resorting to synchronization system calls. Synchronization system calls are costly as they involve doing operations in kernel space and process context switching. In systems where the probability of having work after doing the locking is high, this will cause a significant overhead. (example: worker threads trying to get data from a work dispatcher, in a high-volume stock exchange application. Since the worked will find a work item 90% of the time, synchronization will be an overhead). This is illustrated in below diagram.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*_WDPtKjSwsROsrqIie-5xg.png" /><figcaption>How CAS locks can help reduce # system calls</figcaption></figure><p>3. Using shared memory for inter-process communications: The typical mechanism used to send data across processes is to use system calls or files. Both these are inefficient from the latency perspective. They need copying of data from user-space to kernel space (message queue system calls), or into file system buffers for reading by different processes (file based). A more efficient mechanism is to use shared memory for the data sharing. This requires neither copying into kernel space nor copying into file-system buffers from the user space data. Since the memory pages are directly mapped.</p><p>4. Another example in Java: how the data structure definition can make use of caching characteristics of modern CPU’s: <a href="https://entzik.medium.com/a-case-for-in-memory-columnar-data-structures-44ddb20c2c69">https://entzik.medium.com/a-case-for-in-memory-columnar-data-structures-44ddb20c2c69</a></p><p>While these are some examples of mechanical sympathy, will add more in the next set.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ebfe0242c28" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>