<?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 Ivan Kelly on Medium]]></title>
        <description><![CDATA[Stories by Ivan Kelly on Medium]]></description>
        <link>https://medium.com/@ivankelly?source=rss-c6a780cad6e3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*hjpqw_HKAaMjfPO2.jpeg</url>
            <title>Stories by Ivan Kelly on Medium</title>
            <link>https://medium.com/@ivankelly?source=rss-c6a780cad6e3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 00:59:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ivankelly/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[WTF is tenuring?]]></title>
            <link>https://medium.com/@ivankelly/what-in-tarnation-is-tenuring-833e6e845551?source=rss-c6a780cad6e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/833e6e845551</guid>
            <category><![CDATA[garbage-collection]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Ivan Kelly]]></dc:creator>
            <pubDate>Fri, 16 Jun 2017 13:59:12 GMT</pubDate>
            <atom:updated>2018-08-09T07:20:56.007Z</atom:updated>
            <content:encoded><![CDATA[<p>JVM Garbage collection is a generational collector. This means it splits the heap into multiple generations, which it calls Eden, Survivor and Old.</p><p>By broad strokes, it works like this: New allocations are made in Eden. When eden fills up, a young GC cycle kicks in and copies any still living objects to the survivor space. Live objects that have been in survivor space for a long enough are copied to old generation. A full GC is needed to clean objects out of the old generation. Young GC is stop-the-world, so your application will see pauses when it occurs. If the GC logs show a long time spent copying, then tenuring is the cause.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83cf19b2be02dbc1da8ab04ebf6a37ab/href">https://medium.com/media/83cf19b2be02dbc1da8ab04ebf6a37ab/href</a></iframe><p>The JVM offers no way to tell which objects are surviving and being copied between generations. Profilers like YourKit and Mission Control don’t show it. The information doesn’t seem to exist in hprof files. Really, you’re only option is to eyeball your code and hope something jumps out at you. Good luck if this is a large system, with many subsystems and years of development work!</p><p>Alternatively you can eyeball multiple object histograms from multiple hprof dumps taken over an extended period and hope something reveals itself. However, there’s no accurate and reliable way of finding out what is being copied between regions.</p><p>When all else fails, you can hack up the JDK…</p><p>Compiling your own JDK isn’t as bad as it sounds, though they do try to discourage it by burning your retinas with <a href="http://openjdk.java.net/projects/build-infra/guide.html">instructions on a cyan background</a>.</p><p>Hacking it up, to show the info you want, is a bit more involved, but not rocket science. I modified the JDK to record every object it copies between generations in a map, and then output the list when outputting per thread statistics. It’s a hack. But it doesn’t need to go into production. It doesn’t need to be pretty. It doesn’t need to follow the JDK style. It doesn’t need to be good C++. It just needs to work. You can find my patch <a href="https://gist.github.com/ivankelly/17e4f89a7e1947814f0ae9d554291ed9">here</a>.</p><p>First get the JDK sources and the dependencies needed to build.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1037ca4c60ddd8b1c96fdd6ae4625c04/href">https://medium.com/media/1037ca4c60ddd8b1c96fdd6ae4625c04/href</a></iframe><p>Apply the patch and build.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbdda6f095d69c3cebff0c16cefea2be/href">https://medium.com/media/fbdda6f095d69c3cebff0c16cefea2be/href</a></iframe><p>This should leave you with a JVM image in <em>~/jdk8u-wtftenure/build/linux-x86_64-normal-server-release/images/j2sdk-image/.</em></p><p>To use it, set JAVA_HOME to this path, and add $JAVA_HOME/bin to your PATH.</p><p>To record the list of objects being tenured you need to set “<em>-XX:+ParallelGCVerbose</em>” and “<em>-XX:+UseG1GC</em>”. This only works with the G1GC collector.</p><p>The output will look something like</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e7471bda47c55afc506e3e69fae334b/href">https://medium.com/media/8e7471bda47c55afc506e3e69fae334b/href</a></iframe><p>This isn’t very useful in itself. You need to massage the data a bit to get something useful.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ef83274f92b4ebb28d62a0192bd44e7/href">https://medium.com/media/3ef83274f92b4ebb28d62a0192bd44e7/href</a></iframe><p>So once you have this data, what do you do? It really depends on your application.</p><p>In our case, it highlighted a number of places where we were keeping data for a relatively long time (1 minute). We already knew this was bad, but we had implemented object pooling and we thought this was taking care of it. The data said otherwise.</p><p>Our solution was to take these data structures and reimplement in C++, and call out to them via JNI. This won’t be the solution to all problems like this, but in our case it brought time spent in GC under heavy load from multiple second per minute, to roughly 150ms per minute!</p><p>All examples in this post use Ubuntu 14.04. The JDK source code was taken pulled on June 2nd, 2017, so if the patch doesn’t apply revert to that date. This only works with G1GC collector.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=833e6e845551" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reliable Table Writer Locks for HBASE]]></title>
            <link>https://medium.com/@ivankelly/reliable-table-writer-locks-for-hbase-731024295215?source=rss-c6a780cad6e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/731024295215</guid>
            <category><![CDATA[hbase]]></category>
            <category><![CDATA[zookeeper]]></category>
            <dc:creator><![CDATA[Ivan Kelly]]></dc:creator>
            <pubDate>Tue, 07 Jul 2015 13:17:56 GMT</pubDate>
            <atom:updated>2015-07-07T13:17:56.922Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<p>In distributed systems, it’s pretty common to have a centralized control node to coordinate interactions in the system or to handle a resource which would be very complex to handle in a completely distributed fashion. Examples of this are the Hadoop HDFS namenode which handles the metadata of the Hadoop filesystem, the HBase Master node which controls where regions of tables live and Storm’s Nimbus which orchestrates which workers do which work in the cluster.</p><p>However, a centralized control node is a single point of failure. To be fault tolerant, the state of the control node must be replicated to multiple nodes. This can be done in a number of ways. The system could implement a paxos like protocol for replicating changes as the HDFS namenode does. Changes could be written to a distributed write ahead log, such as BookKeeper or Kafka(in certain configurations). Alternatively, you could store state directly in another system that already provides replication, such as ZooKeeper or HBase.</p><p>I ran into this problem a couple of months ago. We had built a system where a single node coordinated client access to hundreds of other Hadoop and HBase nodes. The coordinator node state was large and updated very regularly (10k+ updates per second), so storing it in zookeeper was out of the question. Our goto solution for this was to put its write ahead log in BookKeeper, and snapshot every so often. However, the ops folks wouldn’t buy this. They were already managing hundreds of Hadoop and HBase nodes. They didn’t want to have another piece of infrastructure to learn and maintain.</p><p>One option we had was to store the coordinator state in HBase. On the surface this looks simple. You run multiple coordinator nodes, and use ZooKeeper to elect the leader. The leader writes all its state to a HBase table. When that leader crashes, ZooKeeper will elect a new leader who can then recover the state from HBase and start serving requests.</p><h4>ZooKeeper locks aren’t safe on their own</h4><p>However, this isn’t safe. ZooKeeper leader election, and distributed locks in general are purely advisory. What this means is that, when ZooKeeper tells you that you are leader, there’s no guarantee that there isn’t another node that “thinks” its the leader. This is due to the fact that, in a distributed system, it is impossible to distinguish between a node failure and a node just going slow, so when ZooKeeper detects that a node has crashed and assigns leadership to another node, the first node may still think it has leadership.</p><p>For example, imagine node A is granted leadership by ZooKeeper and starts serving client requests and writing updates to the system state in HBase. Node A then becomes partitioned from ZooKeeper. This partition could come in the form of a network partition, or simply a stop-the-world java garbage collection cycle, but in any case, during a period of time no messages are communicated between node A and ZooKeeper. ZooKeeper decides, after a timeout, that node A has crashed, so it elects node B as leader. Node B reads the system state from HBase, and starts serving client requests and updating the system state in HBase.</p><p>The problem occurs when the partition goes away and node A can communicate with the network and ZooKeeper again. There is a period of time before ZooKeeper can inform node A that it is no longer leader. During this time node A thinks it is leader, so it will write to the system state with abandon. If node A writes to the system state while node B is leader (after B has read the system state), then the system state will end up inconsistent (neither A nor B will have a correct view of the system state).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WcpBc1Rp1ylPJLvNMypY5Q.png" /></figure><h4>Leader exclusion with sequence numbers</h4><p>To avoid situations where two “leaders” can write to the system state at the same time, the storage system on which system state is stored needs to enforce leadership. When a new leader starts writing, the storage system should prevent all previous leaders from writing to the state.</p><p>A common way to do this is with sequence numbers. Each time a new leader is elected, the leader generates a sequence number higher than any sequence number that has been used before. Something like <a href="http://curator.apache.org/">Curator</a>’s <a href="https://curator.apache.org/apidocs/org/apache/curator/framework/recipes/atomic/DistributedAtomicLong.html">DistributedAtomicLong</a> can be used for this. Once the sequence number has been generated, the leader must ensure that enough storage nodes have seen it for it to be impossible for a write to complete without one of those nodes being involved. In our HBase example, this means making sure each regionserver serving part of the table has seen the new sequence number.</p><p>When a storage node has seen the sequence number for the new leader, it should reject any writes with a lower sequence number. Having received acknowledgments from enough storage nodes, a leader can be sure that the previous leader cannot modify the system state, so it can start making its own modifications to the state.</p><h4>Adding writer sequence numbers to HBase</h4><p>For HBase, this can be implemented using coprocessors and an extra column family. There are two parts to the implementation, table acquisition and checking the sequence number of each write. The full prototype implementation can be found at <a href="http://github.com/ivankelly/hbase-exclusive-writer">http://github.com/ivankelly/hbase-exclusive-writer</a>.</p><p>For table acquisition, the writer stores its writer sequence number in a sequence number row of the table, in the exclusiveWriter column family. Then the writer sends a message to every region in the table, telling it to update its writer sequence number. On receipt of this message, each region first reads the sequence number from the sequence number row, and then tries to write an entry in the region. The write is necessary to ensure that the regionserver handling the message still has ownership of the region in question. If the write succeeds, the region sends the sequence number back to the writer. When the writer has received a response from all regions it checks the sequence number they have sent back against its sequence number. If they all match, and the regions haven’t changed since the acquisition requests were sent, then the writer can commence writing. Otherwise it throws an exception. The sending of the sequence number update request and response are implemented with a coprocessor service.</p><p>In order to check the sequence number a region observer coprocessor is used. The writer attaches the sequence number to all mutations. On receipt of the mutation, the region checks the sequence number against its current sequence number. If the sequence number is different, an exception is thrown.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bcaf2a185abeed482e030d724010192f/href">https://medium.com/media/bcaf2a185abeed482e030d724010192f/href</a></iframe><p>And that’s it. As is often the case, the problem is more interesting, and takes longer to describe, than the solution. With these small modifications, HBase can now be used as a store for system state, and no amount of bad timing and network partitions will corrupt your data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=731024295215" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mining Zookeeper’s transaction log to track down bugs]]></title>
            <link>https://medium.com/@ivankelly/mining-zookeeper-s-transaction-log-to-track-down-bugs-63b4c653bb6?source=rss-c6a780cad6e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/63b4c653bb6</guid>
            <category><![CDATA[zookeeper]]></category>
            <category><![CDATA[debug]]></category>
            <category><![CDATA[midonet]]></category>
            <dc:creator><![CDATA[Ivan Kelly]]></dc:creator>
            <pubDate>Mon, 11 May 2015 10:23:55 GMT</pubDate>
            <atom:updated>2015-05-11T10:23:55.497Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<p>At <a href="http://www.midokura.com/">Midokura</a>, we use Z<a href="http://zookeeper.apache.org/">ookeeper</a> to store the virtual network topology and device tables for our <a href="http://www.github.com/midonet/midonet">SDN product</a>. A couple of weeks ago we started to see an issue on one of our QA environments where our agents, which run on each hypervisor providing the network overlay, would start receiving errors when accessing zookeeper.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a260f01d44d48c9910ef066e928b9a25/href">https://medium.com/media/a260f01d44d48c9910ef066e928b9a25/href</a></iframe><p>This is a relatively well known error. It occurs when a client tries to read a znode or the children of a znode, and the size of the response is greater than jute.maxbuffer (which defaults to 1MB). The agents were trying to read something that had grown very large, but we didn&#39;t know what. We connected to zookeeper, but there were no nodes that were particularly big, either in terms of data size or number of children. This stumped us for a while. Obviously there had been something very large at that point in time, that was large enough to fill 1MB, but it didn&#39;t seem to exist anymore. We needed a way to see exactly what the zookeeper state looked like at that point of time.</p><p>Fortunately this is possible with Zookeeper. Zookeeper is a <a href="http://en.wikipedia.org/wiki/State_machine_replication">replicated state machine</a>. Writes are replicated to each node in the ensemble using a protocol called ZAB before being applied to the zookeeper state. ZAB stores these updates in a transaction log on a disk on the zookeeper server. By starting with a clean zookeeper state and applying the entries in the log in order, you can rebuild the zookeeper state at any point in time. Of course, in a cluster that has been running for years you may not have the whole log reaching back until the beginning of time. Zookeeper periodically takes a snapshot of its state and stores this on disk. In this case, you just need to find the last snapshot taken before the point in time you are interested in, and play forward the transaction log from that point onward.</p><p>This is exactly what we did. And we wrote a tool to do it easily. To run the tool, you just need to point it at your snapshot and transaction log directories and specify the time at which you would like to see what the zookeeper state was. The tool will then rebuild the state and dump it to the console.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a70b0e9ce39b842eea815dfeb9188d93/href">https://medium.com/media/a70b0e9ce39b842eea815dfeb9188d93/href</a></iframe><p>Running the tool against the zookeeper data from our QA environment showed that one of our agents was creating a whole load of ephemeral nodes under a znode. When the other agents tried to get the children of this znode (they were watching for changes to the children), they would get “Packet len is out of range” exception. But then, when the agents restarted after not being able to access zookeeper for a period, these ephemeral nodes would be cleaned up. This is why we couldn&#39;t find the large nodes after the fact.</p><p>Not only were we able to see what nodes were being created, but we could see what was in them. This gave us more clues to which code path was at fault. We eventually narrowed it down to one rarely exercised code path, which we have since removed.</p><p>Some days later we were having another “problem” with zookeeper. Something was creating a lot of shortlived connections. This left us suspicious. We had been having zookeeper problems around that time. Maybe these connections were a contributing cause?</p><p>Our agent creates a zookeeper session which it maintains for the lifetime of the agent, which should be in the order of weeks to months. These connections were only living for 10 seconds or so. One way to figure out what was creating the connection would be to see what each of these zookeeper sessions were doing.</p><p>Having previously had success in digging into zookeeper’s history, we figured we could pull this info out of the transaction log quite easily. We wrote a tool, GrepOps which allows you to grep the log by the znode path, the session id or both, and shows you all operations which match your criteria.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/209ba379a17beb8404a68e84f1971f0f/href">https://medium.com/media/209ba379a17beb8404a68e84f1971f0f/href</a></iframe><p>In this particular case, we found that the sessions were either creating port bindings or deleting port bindings. By knowing the exact sequence of operations we could narrow down the possible code paths which could be causing these connections, eventually discovering that it must be the mm-ctl tool, which is used for integration with <a href="https://wiki.openstack.org/wiki/Neutron">OpenStack neutron</a>. It turns out this had nothing to do with the zookeeper problems we had been seeing, but at least, with this tool, we could rule out the possibility.</p><p>Both the TimeMachine and GrepOps tool are available on github: <a href="http://github.com/midonet/zktimemachine">http://github.com/midonet/zktimemachine</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63b4c653bb6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>