<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dan Weinreb's blog &#187; Concurrency</title>
	<atom:link href="http://danweinreb.org/blog/category/concurrency/feed" rel="self" type="application/rss+xml" />
	<link>http://danweinreb.org/blog</link>
	<description>Software and Innovation</description>
	<lastBuildDate>Fri, 10 Sep 2010 17:44:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>NoSQL Storage Systems Never Violate ACID.  Never?  Well, Hardly Ever!</title>
		<link>http://danweinreb.org/blog/nosql-storage-systems-never-violate-acid-never-well-hardly-ever</link>
		<comments>http://danweinreb.org/blog/nosql-storage-systems-never-violate-acid-never-well-hardly-ever#comments</comments>
		<pubDate>Tue, 07 Sep 2010 11:31:55 +0000</pubDate>
		<dc:creator>Dan Weinreb</dc:creator>
				<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[High Availabilty]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Storage]]></category>

		<guid isPermaLink="false">http://danweinreb.org/blog/?p=507</guid>
		<description><![CDATA[Everybody agrees that the new &#8220;NoSQL&#8221; storage systems &#8220;aren&#8217;t ACID&#8221;, or &#8220;don&#8217;t have transactions&#8221;.  This is true &#60;i&#62;in a sense&#60;/i&#62;, but without knowing the sense, it doesn&#8217;t tell you much. In one sense, they &#60;i&#62;do&#60;/i&#62; have transactions that are limited to having one operation per transaction.  One operation could mean reading, writing, incrementing, or doubling [...]]]></description>
			<content:encoded><![CDATA[<p>Everybody agrees that the new &#8220;NoSQL&#8221; storage systems &#8220;aren&#8217;t ACID&#8221;, or &#8220;don&#8217;t have transactions&#8221;.  This is true &lt;i&gt;in a sense&lt;/i&gt;, but without knowing the sense, it doesn&#8217;t tell you much.</p>
<p>In one sense, they &lt;i&gt;do&lt;/i&gt; have transactions that are limited to having one operation per transaction.  One operation could mean reading, writing, incrementing, or doubling the value associated with a particular key.  For example, look at an &#8220;insert&#8221; operation in a key/value store.  An operations acts on only one data object.  Are these single-operation transactions ACID?  Let&#8217;s check each criterion:</p>
<p>A means &#8220;atomic&#8221;: either all the operations happen, or none of them happens.  Well, there&#8217;s only one operation.  The key-value store &lt;i&gt;does&lt;/i&gt; guarantee that either the insert happens, or it doesn&#8217;t.  So the transaction atomic.</p>
<p>C means &#8220;consistent&#8221;.  In relational database systems, people use this to mean that various interesting consistency guarantees are maintained.  But here, we don&#8217;t have to worry about such things as referential integrity, since there are no references to have integrity; that is, there are no foreign keys.  So it&#8217;s consistent.</p>
<p>I means &#8220;isolated&#8221;: concurrency is never seen by the application.  The system behaves as if each operation happened at a particular, distinct moment in time.  The key-value stores all make this guarantee.</p>
<p>D means &#8220;durable&#8221;: before the application is told that the transaction has been completed successfully (i.e. committed), any side-effects it does are in stable storage so that if a node stops (such as a crash of a process or a whole node) won&#8217;t lose the results of the side-effects.  Here, a transaction is only one operation, but that doesn&#8217;t change anything: the system does provide &#8220;durability&#8221;.  (Some systems might cheat by not actually forcing data to stable storage, but we&#8217;re not talking about those.)</p>
<p>So it appears to be ACID!  OK, something has &lt;i&gt;got&lt;/i&gt; to be wrong here, right?</p>
<p>Right.  Where I tried to pull the wool over your eyes is the definition of &#8220;C&#8221;.  &#8220;C&#8221; doesn&#8217;t just mean conforming to the databases integrity constraints.  It means that the system returns the correct answer! That is, response to any operation is consistent with some state that the database could be in.  There&#8217;s more than one such state when there are concurrent operations going on, which might be ordered in more than one way, depending on how the concurrency system works.  So it&#8217;s clearer to think of &#8220;C&#8221; as meaning &#8220;correct&#8221;.  (In the <a href="http://danweinreb.org/blog/what-does-the-proof-of-the-cap-theorem-mean">famous Gilbert and Lynch paper that &#8220;proves the CAP theorem&#8221;</a>, that&#8217;s what they mean by &#8220;C&#8221;.)</p>
<p>The &#8220;NoSQL&#8221; storage systems are guaranteed return the correct answer &lt;i&gt;only&lt;/i&gt;if there are no partitions in the network.  But if there are (or were, e.g. at write time) partitions, they can return things like &#8220;two replicas say the value is X, but another replica says that the answer is Y&#8221;, and the application has to try to make sense of and cope with that.  That is &lt;i&gt;not&lt;/i&gt; &#8220;C&#8221;.  This is usually called &#8220;eventually consistency&#8221;: if the partitions were to eventually heal and the system deferred accepting new operations until all the in-progress operations finished, and something went over the whole database to fix up any inconsistencies that happened during writes, then the system would become fully consistent, and would be behave correctly until the next partition.</p>
<p>that there are at least two nodes that cannot send messages between each other.  It&#8217;s important to know that if a node in your your system is down, that&#8217;s considered a partition: it&#8217;s as if this node were disconnected from the network.</p>
<p>The &#8220;NoSQL&#8221; systems are ACID, as long as you accept that a transaction can only perform one operation, in the sense that the only thing that gets in the way of being ACID is when there are network partitions and the system is called upon to perform operations while the partition is still there.</p>
<p>&#8220;Partition&#8221; is a somewhat slippery concept that I will examine in an upcoming separate essay.  But the basic ides is that a it means that there are at least two nodes that cannot send messages between them.  It&#8217;s important to know that if a node in your your system is down, that&#8217;s considered a partition: it&#8217;s as if this node were disconnected from the network.</p>
<p>This also shows that the name &#8220;NoSQL&#8221; doesn&#8217;t explain everything that&#8217;s important about these systems.  But you can&#8217;t pack a whole lot into a short, punchy name, so I&#8217;m not really complaining.  ( do the same thing with the names of my blog essays; &lt;i&gt;mea culpa&lt;i&gt;.  You just have to keep in mind that the lack of SQL is not the only important thing.</p>
]]></content:encoded>
			<wfw:commentRss>http://danweinreb.org/blog/nosql-storage-systems-never-violate-acid-never-well-hardly-ever/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>What Does the Proof of the &#8220;CAP theorem&#8221; Mean?</title>
		<link>http://danweinreb.org/blog/what-does-the-proof-of-the-cap-theorem-mean</link>
		<comments>http://danweinreb.org/blog/what-does-the-proof-of-the-cap-theorem-mean#comments</comments>
		<pubDate>Mon, 12 Jul 2010 13:23:15 +0000</pubDate>
		<dc:creator>Dan Weinreb</dc:creator>
				<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://danweinreb.org/blog/?p=357</guid>
		<description><![CDATA[Several years back, Eric Brewer of U.C. Berkeley presented the &#8220;CAP conjecture&#8221;, which he explained in these slides from his keynote speech at the PODC conference in 2004. The conjecture says that a system cannot be consistent, available, and partition-tolerant; that is, it can have two of these properties, but not all three. This idea [...]]]></description>
			<content:encoded><![CDATA[<p>Several years back, Eric Brewer of U.C. Berkeley presented the &#8220;CAP conjecture&#8221;, which he explained in <a href="http://www.cs.berkeley.edu/~brewer/cs262b-2004/PODC-keynote.pdf"> these slides from his keynote speech at the PODC conference in 2004</a>.  The conjecture says that a system cannot be consistent, available, and partition-tolerant; that is, it can have two of these properties, but not all three.  This idea has been very influential.
<p>Seth Gilbert and Nancy Lynch, of MIT, in 2002, wrote a now-famous<a href="http://people.csail.mit.edu/sethg/pubs/BrewersConjecture-SigAct.pdf"> paper called &#8220;Brewer&#8217;s Conjecture and the Feasibility of Consistent Available Partition-Tolerant Web Services&#8221;</a>.  It is widely said that this paper <i>proves</i> the conjecture</a>, which is now considered a theorem.  Gilbert and Lynch, clearly proved <i>something</i>, but what does the proof mean by &#8220;consistency&#8221;, &#8220;availability&#8221;, and &#8220;partition-tolerance&#8221;?
<p>Many people refer to the proof, but not all of them have actually read the paper, thinking that it&#8217;s all obvious.  I wasn&#8217;t so sure, and wanted to get to the bottom of it.  There&#8217;s something about my personality that drives me to look at things all the way down to the details before I feel I understand. (This is not always a good thing: I sometimes lose track of what I originally intended to do, as I &#8220;dive down a rat-hole&#8221;, wasting time.)  For at least a year, I have wanted to really figure this out.
<p>A week ago, I came across <a href="http://pl.atyp.us/wordpress/?p=2521/"> a blog entry called &#8220;Availability and Partition Tolerance&#8221;</a> by <a href="http://pl.atyp.us/wordpress/?page_id=1278">Jeff Darcy</a>. You can&#8217;t imagine how happy I was to find someone who agrees that there is confusion about the terms, and that they need to be clarified. Reading Jeff&#8217;s post inspired me to finally read Gilbert and Lynch&#8217;s paper carefully and write these comments.</p>
<p>I had an extensive email conversation with Jeff, without whose help I could not have written this.  I am very grateful for his generous assistance.  I also thank Seth Gilbert for helping to clarify his paper for me.  I am solely responsible for all mistakes.
<p>I will now <a href="http://en.wikipedia.org/wiki/Sister_Mary_Ignatius_Explains_It_All_For_You"> explain it all for you</a>.  First I&#8217;ll lay out the basic concepts and terminology.  Then I&#8217;ll discuss what &#8220;C&#8221;, &#8220;A&#8221;, and &#8220;P&#8221; mean, and the &#8220;CAP theorem&#8221;.  Next I&#8217;ll discuss &#8220;weak consistency&#8221;, and summarize the meaning of the proof for practical purposes.</p>
<h4>Basic Concepts</h4>
<p>A distributed system is built of &#8220;nodes&#8221; (computers), which can (attempt to) send messages to each other over a network.  But the network is not entirely reliable.  There is no bound on how long a message might take to arrive.  This implies that it might &#8220;get lost&#8221;, which is effectively the same as taking an extremely long time to arrive.  If a node sends a message (and does not see an acknowledgment), it has no way to know whether the message was received and processed or not (because either the request or the response might have been lost).</p>
<p>There are &#8220;objects&#8221;, which are abstract resources that reside on nodes.  Objects can perform &#8220;operations&#8221; on those objects.  Operations are synchronous: some thread issues a request and expects a response.  Operations do not request other operations, so they do not do any messaging themselves.</p>
<p>(There can be replicas of an object on more than one node, but for the most part that doesn&#8217;t affect the following discussion.  An operation could be &#8220;read X and return the value&#8221;, &#8220;write X&#8221;, &#8220;add X to the beginning of a queue&#8221;, etc.  I&#8217;ll just say &#8220;read&#8221; for an operation that has no side-effects and returns some part of the state of the object, and &#8220;write&#8221; to mean an operation that performs side-effects.)
<p>A &#8220;client&#8221; is a thread running on some node, which can &#8220;request&#8221; an object (on any node) to perform an operation. The request is sent in a message, and the sender expects a response message, which might returns a value, and which confirms that the operation was performed.  In general, more than one thread could be performing operations on one object.  That is, there can be <i>concurrent</i> requests.
<p>The paper says: &#8220;In this note we will not consider stopping failures, though in some cases a stopping failure can be modeled as a node existing in its own unique component of a partition.&#8221;  Of course in any real distributed system, nodes can crash.  But for purposes of this paper, a crash is considered to be a network failure, because from the point of view of another node, there&#8217;s no way to distinguish between the two.  A crashed node behaves exactly like a node that&#8217;s off the network.</p>
<h4>Consistent</h4>
<p>The paper says that consistency &#8220;is equivalent to requiring requests of the distributed shared memory to act as if they were executing on a single node, responding to operations one at a time.&#8221;
<p>Paraphrased, this means consistency is equivalent to requiring all operations (in the whole distributed system) to be linearizable.</p>
<p>&#8220;Linearizability&#8221; is a formal criterion presented in the paper &#8220;Linearizability: A Correctness Condition for Concurrent Objects&#8221;, by Maurice Herlihy and Jeannette Wing.  It means (basically) that operations behave <i>as if</i> there were no concurrency.</p>
<p>That is, although there is a set of threads, each of which can send an operation to an object, and later receive a response.  Despite the fact that the operations from the different threads can overlap in time in various ways, the responses are <i>as if</i> each operation took place instantaneously, in some order.  The order must be consistent with each thread&#8217;s own order, so that a read operation in a thread always sees the results of that thread&#8217;s writes.
<p>Linearizability <i>per se</i> does not include failure atomicity, which is the &#8220;A&#8221; (&#8220;atomic&#8221;) in &#8220;ACID&#8221;.  But Gilbert and Lynch assume no node failures. So operations always run to completion, and so they are &#8220;atomic&#8221; as well.  (But their response messages can get lost.)
<p>So by &#8220;consistent&#8221; (&#8220;C&#8221;), the paper means that every object is linearizable.  (That&#8217;s not what the &#8220;C&#8221; in &#8220;ACID&#8221; means, by the way, but that&#8217;s not important.)  Very loosely, &#8220;consistent&#8221; means that if you get a response, it has the right answer.
<p>This is <i>not</i> what the &#8220;C&#8221; in &#8220;ACID transaction&#8221; means.  It&#8217;s what the &#8220;I&#8221; means, namely &#8220;isolation&#8221; from concurrent operations.  This is probably a source of confusion sometimes.</p>
<p>Furthermore, the paper says nothing about transactions, which have would have a beginning, a <i>sequence</i> of operations, and an end, which may commit or abort.  &#8220;ACID&#8221; is talking about the entire transaction.  The &#8220;linearizability&#8221; criterion only talks about individual operations on objects.  (So the whole &#8220;ACID versus BASE&#8221; business, while cute, can be misleading.)</p>
<h4>Available</h4>
<p>&#8220;Available&#8221; is defined as &#8220;every request received by a non-failing node in the system must result in a response.&#8221;  The phrase &#8220;non-failing node&#8221; seemed to imply that some nodes might be failing and others not.  But since the paper postulates that nodes never fail, I believe the phrase is redundant, and can be ignored.</p>
<p>After the definition, the paper says &#8220;That is, any algorithm used by the service must eventually terminate.&#8221;  Does that mean the response might not arrive for a trillion years?  That&#8217;s the same as never terminating, from a practical point of view!
<p>This definition of &#8220;available&#8221; is only useful if it includes some kind of real-time limit: the response must arrive within a period of time, which I&#8217;ll call the maximum latency.
<p>Next, it&#8217;s very important to notice that &#8220;A&#8221; says nothing about the content of the response.  It could be anything, as far as &#8220;A&#8221; is concerned; it need not be &#8220;successful&#8221; or &#8220;correct&#8221;.  (If think otherwise, see section 3.2.3.)</p>
<p>So &#8220;available&#8221; (&#8220;A&#8221;) means: If a client sends a request to a node, it always gets back some response within L time, but there is no guarantee about contents of the response.<br />
<h4>Partition Tolerant</h4>
<p>There is no definition, <i>per se</i>, of the term &#8220;partition-tolerant&#8221;, not even in section 2.3, &#8220;Partition Tolerance&#8221;.
<p>First, what is a &#8220;partition&#8221;? They first define it to mean that there is a way to assort all the nodes into separate sets, which they call &#8220;components&#8221;, and all messages sent from a node in one component to another nodes in a separate component are lost. But then they go on to say &#8220;And any pattern of message loss can be modeled as a temporary partition separating the communicating nodes at the exact instance the message is lost.&#8221;  That&#8217;s probably <i>not</i> what you had in mind!
<p>In real life, some messages are lost and some aren&#8217;t, and it&#8217;s not exactly clear when a &#8220;partition&#8221; situation starts, is happening, or ends.  I realize that for practical purposes, we usually know what a partition means, but if we&#8217;re going to do formal proofs and understand what was proved, one must be completely clear about these terms.</p>
<p>Even in a local-area network, packets can be dropped.  Protocols like TCP re-transmit packets until the destination acknowledges that they have arrived.  If that happens, it&#8217;s clearly not a network failure from the point of view of the application.  &#8220;Losing messages&#8221; clearly has something to do with nodes entirely unable to communicate for a &#8220;long&#8221; time compared to the latency requirements of the system.
<p>Taking that into account: for their formal purposes, &#8220;partition&#8221; simply means that a message can be lost. (The whole &#8220;component&#8221; business can be disregarded.)
<p>Furthermore, remember that node failure is treated as a network failure.</p>
<p>So &#8220;partition-tolerant&#8221; (&#8220;P&#8221;) means that any guarantee of atomicity or availability is still guaranteed even if there is a partition.  In other words, if a system is <i>not</i> partition-tolerant, that means that if the network can lose messages or any nodes can fail, then any guarantee of atomicity or consistency is voided.<br />
<h4>CAP</h4>
<p>The CAP theorem says that a distributed system as described above cannot have properties C, A, and P all at the same time.  You can only have two of them.  There are three cases:
<p>AP: You are guaranteed get back responses promptly, but you aren&#8217;t guaranteed anything about the value/contents of the response.  (See section 3.2.3.)  This guarantee is completely useless.
<p>CP: You are guaranteed that any response you get has a consistent (linearizable) result.  But you might not get any responses whatsoever.  (See section 3.2.1.)  This guarantee is also completely useless, since the entire system might behave as if it were totally down.
<p>CA: If the network never fails (and nodes never crash, as they postulated earlier), then, unsurprisingly, life is good.  But if any messages are dropped, <i>all</i> guarantees are off.  So a CA guarantee is also completely useless. (Note that even if only one node is unreachable, you still can&#8217;t guarantee CA, since any request might need a resource on that one node.)
<p>At first, this seems to mean that practical, large distributed systems can&#8217;t make <i>any</i> useful guarantees!  What&#8217;s going on here?<br />
<h4>Weak Consistency</h4>
<p>Large-scale distributed systems that must be highly available can provide some kind of &#8220;weaker&#8221; consistency guarantee than linearizability.  Most such systems provide what they call &#8220;eventual consistency&#8221; and may return &#8220;stale data&#8221;.</p>
<p>For some applications, that&#8217;s OK.  Google search is an obvious case: the search is already specified/known to be using &#8220;stale&#8221; data (data since the last time Google looked at the web page), so as long as partitions are fixed quickly relative to the speed of Google&#8217;s updating everything, (and even if sometimes not, for that matter), nobody is going to complain.
<p>Just saying that results &#8220;might be stale&#8221; and will be &#8220;eventually consistent&#8221; is unfortunately vague.  How stale can it be, and how long is &#8220;eventually&#8221;? If there&#8217;s no limit, then there&#8217;s no useful guarantee.</p>
<p>For a staleness-type weak consistency guarantee, you&#8217;d like to be able to say something like: &#8220;operations (that read) will always return a result that was consistent with all the other operations (that write) no longer ago than time X&#8221;.  And this implies that &#8220;write&#8221; operations are never lost, i.e. always happen within a fixed time bound.
<p>Gilbert and Lynch discuss &#8220;weakened consistency&#8221; in section 4. It&#8217;s also about stale data, but with &#8220;formal requirements on the quality of stale data returned&#8221;.  They call it &#8220;t-Connected Consistency&#8221;.
<p>It makes two assumptions.  (a) Every node has a clock that can be used to do timeouts. The clocks don&#8217;t have to be synchronous with each other.  (b) There&#8217;s some time period after which you can assume that an unanswered message must be lost. (c) Every node processes a received message within a given, known time.
<p>The real definition of &#8220;t-Connected Consistency&#8221; is too formal for me to explain here (see section 4.4).  It (basically) guarantees (1) when there is no partition, the system is fully consistent; (2) if a partition happens, requests can see stale data; and (3) and after the partition is fixed, there&#8217;s a time limit on how long it takes for consistency to return.
<p>Are the assumptions OK in practice?  Every real computer can do timeouts, so (a) is no problem.  You can always ignore any responses to messages after the time period, so (b) is OK.  It&#8217;s not obvious that every system will obey (c), but some will.
<p>I have two reservations.  First, if the network is so big that it&#8217;s never entirely working at any one time, what would guarantee (3) mean?  Second, in the algorithm in section 4.4, in the second step (&#8220;<i>write</i> at node A&#8221;), it retries as long as necessary to get a response.  But that could exceed L, violating the availability guarantee.
<p>So it&#8217;s not clear how attractive t-Connected Consistency really is.  It can be hard it is to come up with formal proofs of more complicated, weakened consistency guarantees.  Most working software engineers don&#8217;t think much about formal proofs, but don&#8217;t underrate them.  Sometimes they can help you identifying bugs that would otherwise be hard to track down, before they happen.</p>
<p>Jeff Darcy wrote <a href="http://pl.atyp.us/wordpress/?p=2532">a blog posting about &#8220;eventual consistency&#8221;</a> about a half year ago, which I recommend.  And there are other kinds of weak consistency guarantees, such as the one provided by <a href="http://s3.amazonaws.com/AllThingsDistributed/sosp/amazon-dynamo-sosp2007.pdf"> Amazon&#8217;s Dynamo key-store</a>, which worth examining.<br />
<h4>Reliable Networks</h4>
<p>Can&#8217;t you just make the network reliable, so that messages are never lost?  (&#8220;Never&#8221; meaning that the probability of losing a message is as low as other failure mode that you&#8217;re not protecting against.)</p>
<p>Lots and lots of experience has shown that in a network with lots of routers and such, no matter how much redundancy you add, you <i>will</i> experience lost messages, and you <i>will</i> see partitions that last for a significant amount of time.  I don&#8217;t have a citation to prove this, but, ask around and that&#8217;s what experienced operators of distributed systems will always tell you.</p>
<p>How many routers is &#8220;lots&#8221;?  How reliable is it if you have no routers (layer 3 switches), only hubs (layer 2 switches)?  What if you don&#8217;t even have hubs?  I don&#8217;t have answers to all this.  But if you&#8217;re going to build a distributed system that depends on a reliable network, you had better ask experienced people about these questions.  If it involves thousands of nodes and/or is geographically distributed, you can be sure that the network will have failures.</p>
<p>And again, as far as the proof of the CAP theorem is concerned, node failure is treated as a network failure.  Having a perfect network does you no good if machines can crash, so you&#8217;d also need each node to be highly-available in and of itself.  That would cost a lot more than using &#8220;commercial off-the-shelf&#8221; computers.</p>
<h4>The Bottom Line</h4>
<p>My conclusion is that the proof of the CAP theorem means, in practice: if you want to build a distributed system that is (1) large enough that nodes can fail and the network can&#8217;t be guaranteed to never lose messages, <i>and</i> (2) you want to get a useful response to every request within a specified maximum latency, <i>then</i> the best you can guarantee about the meaning of the response is that it is guaranteed to have some kind of &#8220;weak consistency&#8221;, which you had better carefully <i>define</i> in such a way that it&#8217;s useful.<br />
<h4>P.S.</h4>
<p>After writing this but just before posting it, Alex Feinberg added a comment to my previous blog post with a link to <a href="http://www.cloudera.com/blog/2010/04/cap-confusion-problems-with-partition-tolerance/">this excellent post by Henry Robinson</a>, which discusses many of the same issues and links to even more posts.  If you want to read more about all this, take a look.</p>
]]></content:encoded>
			<wfw:commentRss>http://danweinreb.org/blog/what-does-the-proof-of-the-cap-theorem-mean/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>VoltDB versus NoSQL</title>
		<link>http://danweinreb.org/blog/voltdb-versus-nosql</link>
		<comments>http://danweinreb.org/blog/voltdb-versus-nosql#comments</comments>
		<pubDate>Sun, 11 Jul 2010 21:51:57 +0000</pubDate>
		<dc:creator>Dan Weinreb</dc:creator>
				<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Storage]]></category>

		<guid isPermaLink="false">http://danweinreb.org/blog/?p=345</guid>
		<description><![CDATA[Mike Stonebraker is the co-founder and CTO of VoltDB, which makes a novel on-line transaction processing (OLTP) relational database management system (RDBMS). He recently gave a talk entitled &#8220;VoltDB Decapitates Six SQL Urban Myths&#8221;. You can read the slides here. Much of the talk is a reply to the claims of the community building data [...]]]></description>
			<content:encoded><![CDATA[<p>Mike Stonebraker is the co-founder and CTO of <a href="http://voltdb.com">VoltDB</a>, which makes a novel on-line transaction processing (OLTP) relational database management system (RDBMS). He recently gave a talk entitled <a href="http://voltdb.com/voltdb-webinar-sql-urban-myths">&#8220;VoltDB Decapitates Six SQL Urban Myths&#8221;</a>. You can read the slides <a href="http://voltdb.com/_pdf/VoltDB-MikeStonebraker-SQLMythsWebinar-060310.pdf"> here.</a> Much of the talk is a reply to the claims of the community building data stores often referred to as <a href="http://en.wikipedia.org/wiki/NoSQL">NoSQL data stores</a>.</p>
<p>Todd Hoff of <a href="http://highscalability.com">HighScalability</a> has written <a href="http://highscalability.com/blog/2010/6/28/voltdb-decapitates-six-sql-urban-myths-and-delivers-internet.html">an excellent commentary on the talk.</a> If you want to understand what&#8217;s going on with VoltDB, you can&#8217;t do better than to read this (including the commentary, with some replies from VoltDB).  I have a bit to add.</p>
<h4>Benchmarking</h4>
<p>Dr. Stonebraker&#8217;s talk includes benchmark results, which VoltDB ran much faster than MySQL and <a href="http://en.wikipedia.org/wiki/Apache_Cassandra"></a>, a well-known NoSQL data store.</p>
<p>Over many years, I have found that what nearly everybody wants is a predictive &#8220;single number&#8221; that says how much faster one DBMS is than another.  But applications differ <em>hugely</em> in their workloads, and measured speed depends <em>tremendously</em> on using the DBMS in the best way, including layout, clustering, indexing, partitioning, and all kinds of options, such as whether transactions are immediately made durable or not.  Saying that one DBMS is &#8220;N times faster&#8221; than another DBMS is very misleading.  But everyone wants the magic number, and are too quick to assume that the result of one benchmark predicts speed in all situations.</p>
<p>One must take into account that the VoltDB engineers wrote these micro-benchmarks, and ran them on a very specific workload, knowing what they were trying to prove.  I do appreciate that they made a good-faith attempt to be fair, based on John Hugg&#8217;s comments above.  And I can vouch that John is a very smart guy, and I believe all that he says in his comments above.  Nevertheless, they did not bring in experts in the other systems who would could tune them optimally.  Different benchmarks might be less flattering.</p>
<p>The old argument about assembly language versus high-level languages would be analogous if RDBMS optimizers worked as well as C/Java/etc compilers.  SQL is supposed to be declarative: you just ask for what you want, and the RDBMS figures out the best way to get it.  But my experience, and what my friends tell me, is that the optimizers in some popular RDBMS&#8217;s (especially Oracle) frequently make bad choices, and picking the wrong query strategy can slow things down by huge factors.  So the developers are forced to override the optimizer with &#8220;hints&#8221;.  It&#8217;s been over 30 years, and still the optimizers fail.  Maybe it&#8217;s time to declare the experiment a failure.  (This may not be an issue for VoltDB, as the SQL might be always be very simple or something.)</p>
<h4>Stored Procedures</h4>
<p>He&#8217;s right that performance can be hurt by too many round trips to the DBMS.  But Oracle users have know for a long time that you have to use stored procedures to get high performance; this is nothing new.  When you do this with Oracle, you end up with lots of PL/SQL code.  Most of your developers can&#8217;t understand it, and it&#8217;s a proprietary language so you&#8217;re &#8220;locked in&#8221; to Oracle (it&#8217;s very hard to switch to a different DBMS).</p>
<p>It&#8217;s one thing to provide stored procedures as a way to improve performance.  But VoltDB requires you to use stored procedures, and each interaction with VoltDB is a transaction. Any application that mixes database access with other operations that must be done on the client side cannot use VoltDB.  The application has to be written in the VoltDB manner, from the beginning.  This is like &#8220;lock-in&#8221; in some ways.</p>
<h4>More about the VoltDB presentation</h4>
<p>Todd says: &#8220;In contrast, the VoltDB model seems from a different age: a small number of highly tended nodes in a centralized location.&#8221;  I don&#8217;t think this is right.  For disaster recovery (e.g. blackouts), you need a replica far away; this has always been an integral part of VoltDB&#8217;s justification for not logging to disk.  And then you have to worry about network partitions over a WAN.  WAN&#8217;s are not yet supported in VoltDB.</p>
<p>I find Todd&#8217;s point about Amazon&#8217;s Dynamo very compelling: why would Amazon do so much work if partitions are so rare?  At Amazon scale, partitions must be frequent enough to justify all this work.  Not all VoltDB customers will be operating at that scale, but John Hugg has said that it&#8217;s designed for &#8220;Internet scale&#8221;.  Dr. Stonebraker is right that there&#8217;s no substitute for actual measurement of how likely partition is.</p>
<h4>Putting the burden on application programmers</h4>
<p>Serious production databases are usually manged by database experts/administrators, who decide where to replicate what, whether and how to partition tables (across nodes), and so on.</p>
<p>But with VoltDB, the <i>application developers</i> have to understand a lot about this.  For example, they need to know whether a procedure is single-partitioned, so they can assert that in the code.  So they have to know about sharding, where replicas are, and so on.  It makes the application brittle insofar as changes by the database administrators could break those assertions.</p>
<p>For example, a VoltDB engineer explained to a customer: &#8220;The goal of VoltDB is to optimize single-partition transactions and part of the responsibility for that falls on the application developer. You must write the queries to operate properly within a single partition and then declare the procedure to be single-partitioned. [...] Today, VoltDB does not verify that the SQL queries within a single-partitioned procedure are actually single-partitioned.&#8221;  Another VoltDB engineer said: &#8220;The vast majority (almost 100%) of your stored procedure invocations must be single-partition for VoltDB to be useful to you.&#8221;</p>
<p>Different &#8220;NoSQL&#8221; systems also put such burdens on application programmers to greater or lesser degrees, as well.  RDBMS&#8217;s have traditionally boasted that they hide these issues from application programmers.  VoltDB uses SQL, but what it provides is very different from the original concept of the relational model.</p>
<h4>What is a &#8220;SQL&#8221; database system?</h4>
<p>You can see more of this in their <a href="http://community.voltdb.com/sites/default/files/voltdb%20dos%20and%20donts.pdf"> &#8220;VoltDB do&#8217;s and don&#8217;ts list&#8221;</a> Perhaps the most important point is the first &#8220;Don&#8217;t&#8221;: &#8220;Don&#8217;t use ad hoc SQL queries as part of a production application.&#8221;  Dr. Stonebraker&#8217;s talk is very much a defense of using SQL for OLTP, rather than the &#8220;NoSQL&#8221; models such as key-value stores.  But what does the restriction against &#8220;ad hoc&#8221; queries mean?</p>
<p>The original fundamental claim of relational DBMS&#8217;s (as opposed to the previous generation, the CODASYL-type DBMS&#8217;s) is that you don&#8217;t have know the access pattern; you just say what you want in SQL, and the DBMS figures out how to do it.  Applications keep working even if there are changes in the storage layout, indexing, and whatever else the DBMS uses.  But, as a VoltDB engineer said, &#8220;Part of VoltDB&#8217;s underlying premise is that workloads are known in advance.&#8221;</p>
<p>Even though VoltDB uses SQL, maybe it isn&#8217;t as far from the &#8220;NoSQL&#8221; storage engines as one might think!</p>
]]></content:encoded>
			<wfw:commentRss>http://danweinreb.org/blog/voltdb-versus-nosql/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Programming with Concurrency</title>
		<link>http://danweinreb.org/blog/programming-with-concurrency</link>
		<comments>http://danweinreb.org/blog/programming-with-concurrency#comments</comments>
		<pubDate>Mon, 27 Jul 2009 13:26:30 +0000</pubDate>
		<dc:creator>Dan Weinreb</dc:creator>
				<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Europe]]></category>
		<category><![CDATA[Guy L. Steele Jr.]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://danweinreb.org/blog/?p=184</guid>
		<description><![CDATA[New high-speed computers will have more and more cores as the years go by, and the ramp-up has started and is going very quickly.  To take advantage of those processors, some programs will need to use interesting (complicated and novel) concurrency. But the history of concurrent software is littered with approaches that just turned out [...]]]></description>
			<content:encoded><![CDATA[<p>New high-speed computers will have more and more cores as the years go by, and the ramp-up has started and is going very quickly.  To take advantage of those processors, some programs will need to use interesting (complicated and novel) concurrency.</p>
<p>But the history of concurrent software is littered with approaches that just turned out to be too hard to use, and the software was slow to develop and very hard to debug.  Now that we&#8217;re all in the same boat, how do we solve the software problem?</p>
<p>Many language designers think that the answer lies in pure (side-effect free) programming.  The best known, and quite practical, languages that are pure are Haskell and Erlang.</p>
<p>But many new languages are arriving based on the idea that you should use mostly side-effect-free code, and then when side-effects are needed, use transactions.  This is at least a trend if not a movement or revolution.</p>
<p>When Guy Steele came back from the <a href="http://jaoo.dk/aarhus-2008/conference/" target="_blank">JAOO Conference</a>, I asked him for a quick report, and he sent me this (very slightly copy edited, used with Guy&#8217;s permission):</p>
<blockquote><p>I was stunned by the end of the first day of JAOO 2008 when I realized that Anders Hejlsberg had given a plenary talk on C#, I had given a talk on Fortress, Bill Venners had given a talk on Scala, and Erik Meijer had given a talk on functional programming, and we had all delivered approximately the same message to this object-oriented crowd: the multicores are coming—no, they&#8217;re <em>here</em>—and the only plausible way to deal with them in the long run is to rein in the side effects inherent to the OO point of view and move as much as possible to a functional programming style with mostly-immutable data structures and implicit parallelism.</p></blockquote>
<p>I am very excited by the new Clojure language, which is a dialect of Lisp based on exactly these same principles.  Rich Hickey apparently wasn&#8217;t at JAOO, but would have found friends there!</p>
<p>Normally I don&#8217;t try to learn a language unless I&#8217;m about to actually program in it.  But it&#8217;s worth learning a language when you pick up fundamental new ideas that might be helpful (or just interesting).  Haskell is like that (thanks, Alan Bawden, for letting me know).</p>
<p>If you might have to write highly-concurrent programs in the future, I recommend that you keep your eyes on all this.</p>
]]></content:encoded>
			<wfw:commentRss>http://danweinreb.org/blog/programming-with-concurrency/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>
