<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: BlitzDB and Tokyo Cabinet Concurrency Model</title>
	<atom:link href="http://torum.net/2009/11/blitzdb-and-tc-concurrency-model/feed/" rel="self" type="application/rss+xml" />
	<link>http://torum.net/2009/11/blitzdb-and-tc-concurrency-model/</link>
	<description>Hackaholic and a Web Addict based in Tokyo</description>
	<lastBuildDate>Sun, 06 Mar 2011 10:26:54 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
	<item>
		<title>By: Paul McCullagh</title>
		<link>http://torum.net/2009/11/blitzdb-and-tc-concurrency-model/comment-page-1/#comment-5096</link>
		<dc:creator>Paul McCullagh</dc:creator>
		<pubDate>Mon, 23 Nov 2009 11:49:00 +0000</pubDate>
		<guid isPermaLink="false">http://torum.net/?p=2307#comment-5096</guid>
		<description>Hi Toru,

An interesting problem :)

If I correctly understand what the BlitzLock is doing, then there are two possible problems with the code:

- pthread_cond_broadcast(&amp;condition) should only be called, when scanner_count == 0 in scan_end() (or updater_count == 0).

For example:

  pthread_mutex_lock(&amp;mutex);
  scanner_count--;
  assert(scanner_count &gt;= 0);
  if (scanner_count == 0)
    pthread_cond_broadcast(&amp;condition);
  pthread_mutex_unlock(&amp;mutex);

- The other potential problem is so-called &quot;live lock&quot;:

This would happen, for example, if you had a constant flow of scanners. An updater would never get a chance because scanner_count would never go to zero. Possible solution is to have a limit to the number of scanners or updaters before you switch &quot;modes&quot;.

Best regards,

Paul</description>
		<content:encoded><![CDATA[<p>Hi Toru,</p>
<p>An interesting problem :)</p>
<p>If I correctly understand what the BlitzLock is doing, then there are two possible problems with the code:</p>
<p>- pthread_cond_broadcast(&amp;condition) should only be called, when scanner_count == 0 in scan_end() (or updater_count == 0).</p>
<p>For example:</p>
<p>  pthread_mutex_lock(&amp;mutex);<br />
  scanner_count&#8211;;<br />
  assert(scanner_count &gt;= 0);<br />
  if (scanner_count == 0)<br />
    pthread_cond_broadcast(&amp;condition);<br />
  pthread_mutex_unlock(&amp;mutex);</p>
<p>- The other potential problem is so-called &#8220;live lock&#8221;:</p>
<p>This would happen, for example, if you had a constant flow of scanners. An updater would never get a chance because scanner_count would never go to zero. Possible solution is to have a limit to the number of scanners or updaters before you switch &#8220;modes&#8221;.</p>
<p>Best regards,</p>
<p>Paul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Toru Maesaka</title>
		<link>http://torum.net/2009/11/blitzdb-and-tc-concurrency-model/comment-page-1/#comment-4985</link>
		<dc:creator>Toru Maesaka</dc:creator>
		<pubDate>Thu, 19 Nov 2009 16:52:01 +0000</pubDate>
		<guid isPermaLink="false">http://torum.net/?p=2307#comment-4985</guid>
		<description>Heya Jay,

Graphs are always good. Writing that standalone is as far as I&#039;ve gotten so it&#039;s not integrated into the engine yet. When I get all the pieces together, I&#039;ll definitely compare it against the native library and publish the results.

Thanks very much for the C++ tip!

I&#039;m definitely not a C++ ninja but I thought adding code into a constructor/deconstructor wasn&#039;t good practice since failure inside a constructor can be pretty yucky to take care of... Please correct me if I&#039;m wrong but my understanding was that the constructor should only be used for allocation and basic initialization only, and bring out anything that involves assignments and further allocation into a different function like init().

This is something I&#039;d love to know more about :)</description>
		<content:encoded><![CDATA[<p>Heya Jay,</p>
<p>Graphs are always good. Writing that standalone is as far as I&#8217;ve gotten so it&#8217;s not integrated into the engine yet. When I get all the pieces together, I&#8217;ll definitely compare it against the native library and publish the results.</p>
<p>Thanks very much for the C++ tip!</p>
<p>I&#8217;m definitely not a C++ ninja but I thought adding code into a constructor/deconstructor wasn&#8217;t good practice since failure inside a constructor can be pretty yucky to take care of&#8230; Please correct me if I&#8217;m wrong but my understanding was that the constructor should only be used for allocation and basic initialization only, and bring out anything that involves assignments and further allocation into a different function like init().</p>
<p>This is something I&#8217;d love to know more about :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jay Pipes</title>
		<link>http://torum.net/2009/11/blitzdb-and-tc-concurrency-model/comment-page-1/#comment-4982</link>
		<dc:creator>Jay Pipes</dc:creator>
		<pubDate>Thu, 19 Nov 2009 16:23:39 +0000</pubDate>
		<guid isPermaLink="false">http://torum.net/?p=2307#comment-4982</guid>
		<description>Hi Toru!

Nice stuff.  Would be nice to see if your homegrown implementation is more scalable than a standard rwlock.  Can you post graphs of your findings in this regard?

Also, one little suggestion:

Change the BlitzLocK::init() into a constructor and BlitzLock::destroy() into the destructor.  Since you are already paying the price of the constructor and destructor, you might as well move the init/destroy code into the constructor/destructor.  This allows RAII principles to dominate as well, which means user of the BlitzLock class can&#039;t make the mistake of forgetting to call init or destroy.

Cheers!

Jay</description>
		<content:encoded><![CDATA[<p>Hi Toru!</p>
<p>Nice stuff.  Would be nice to see if your homegrown implementation is more scalable than a standard rwlock.  Can you post graphs of your findings in this regard?</p>
<p>Also, one little suggestion:</p>
<p>Change the BlitzLocK::init() into a constructor and BlitzLock::destroy() into the destructor.  Since you are already paying the price of the constructor and destructor, you might as well move the init/destroy code into the constructor/destructor.  This allows RAII principles to dominate as well, which means user of the BlitzLock class can&#8217;t make the mistake of forgetting to call init or destroy.</p>
<p>Cheers!</p>
<p>Jay</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Toru Maesaka</title>
		<link>http://torum.net/2009/11/blitzdb-and-tc-concurrency-model/comment-page-1/#comment-4981</link>
		<dc:creator>Toru Maesaka</dc:creator>
		<pubDate>Thu, 19 Nov 2009 16:20:34 +0000</pubDate>
		<guid isPermaLink="false">http://torum.net/?p=2307#comment-4981</guid>
		<description>Hi Baron!

So tchdbput() is the interface that the application calls and the first argument of the function is the TCHDB object that contains the state information of the database file. If a different thread is doing something critical that needs total atomicity, it would have obtained a writer&#039;s lock which would make a call to tchdbput() block until the writer&#039;s lock is released.

I&#039;m not sure if this is the answer you expected but TC has a rwlock called mmtx (no idea what it stands for) which protects the entry of TC&#039;s API functions. I think peeking at tchdb.h (first struct in tchdb.h) would give you a good picture of what kind of mutexes are involved in TC&#039;s hash database (it&#039;s well commented).

&gt;&gt; MySQL has had a lot of trouble from taking locks before it needs to :(

Wish I knew more about it... too much things to study and too little time :)</description>
		<content:encoded><![CDATA[<p>Hi Baron!</p>
<p>So tchdbput() is the interface that the application calls and the first argument of the function is the TCHDB object that contains the state information of the database file. If a different thread is doing something critical that needs total atomicity, it would have obtained a writer&#8217;s lock which would make a call to tchdbput() block until the writer&#8217;s lock is released.</p>
<p>I&#8217;m not sure if this is the answer you expected but TC has a rwlock called mmtx (no idea what it stands for) which protects the entry of TC&#8217;s API functions. I think peeking at tchdb.h (first struct in tchdb.h) would give you a good picture of what kind of mutexes are involved in TC&#8217;s hash database (it&#8217;s well commented).</p>
<p>>> MySQL has had a lot of trouble from taking locks before it needs to :(</p>
<p>Wish I knew more about it&#8230; too much things to study and too little time :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Baron Schwartz</title>
		<link>http://torum.net/2009/11/blitzdb-and-tc-concurrency-model/comment-page-1/#comment-4979</link>
		<dc:creator>Baron Schwartz</dc:creator>
		<pubDate>Thu, 19 Nov 2009 14:36:15 +0000</pubDate>
		<guid isPermaLink="false">http://torum.net/?p=2307#comment-4979</guid>
		<description>I haven&#039;t looked at the code you mentioned, but you said: &quot;If you look at the entry point of tchdbput(), you will notice that it is actually obtaining a reader’s lock (in terms of rwlock). TCHDB then hashes the provided key...&quot;

Why is it taking *any* lock before doing this and the other work you mentioned?  Again I don&#039;t know the code, but in general locks should be taken as late as possible.  MySQL has had a lot of trouble from taking locks before it needs to :-(</description>
		<content:encoded><![CDATA[<p>I haven&#8217;t looked at the code you mentioned, but you said: &#8220;If you look at the entry point of tchdbput(), you will notice that it is actually obtaining a reader’s lock (in terms of rwlock). TCHDB then hashes the provided key&#8230;&#8221;</p>
<p>Why is it taking *any* lock before doing this and the other work you mentioned?  Again I don&#8217;t know the code, but in general locks should be taken as late as possible.  MySQL has had a lot of trouble from taking locks before it needs to :-(</p>
]]></content:encoded>
	</item>
</channel>
</rss>

