<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Making PStore reaaaally fast (and stable)</title>
	<link>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/</link>
	<description>Ecchi nanowa ikenai to omoimasu</description>
	<pubDate>Sat, 05 Jul 2008 18:37:27 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: Hongli</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-8019</link>
		<dc:creator>Hongli</dc:creator>
		<pubDate>Fri, 28 Mar 2008 18:14:28 +0000</pubDate>
		<guid>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-8019</guid>
		<description>No, the file I/O is probably safe. But bad things may happen if two threads enter the same transaction. For example, suppose thread 1 enters a read-only transaction, and it just passed this line:

@rdonly = read_only

Then a context switch occurs. Thread 2 enters a read-write transaction and passes the same line as well, setting @rdonly to false. Thread 2 exits transaction. Context switch occurs. Thread 1, which was supposed to be executing a read-only transaction, now thinks that the transaction is read-write and writes stuff to disk. Boom.</description>
		<content:encoded><![CDATA[<p>No, the file I/O is probably safe. But bad things may happen if two threads enter the same transaction. For example, suppose thread 1 enters a read-only transaction, and it just passed this line:</p>
<p>@rdonly = read_only</p>
<p>Then a context switch occurs. Thread 2 enters a read-write transaction and passes the same line as well, setting @rdonly to false. Thread 2 exits transaction. Context switch occurs. Thread 1, which was supposed to be executing a read-only transaction, now thinks that the transaction is read-write and writes stuff to disk. Boom.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mla</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-8018</link>
		<dc:creator>mla</dc:creator>
		<pubDate>Fri, 28 Mar 2008 18:07:17 +0000</pubDate>
		<guid>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-8018</guid>
		<description>Just for my understanding, what made the original version
not thread-safe? I see your synchronize call, I'm just not
clear on exactly what it's serializing access to. Is the
file I/O not thread safe even when flock'd?</description>
		<content:encoded><![CDATA[<p>Just for my understanding, what made the original version<br />
not thread-safe? I see your synchronize call, I&#8217;m just not<br />
clear on exactly what it&#8217;s serializing access to. Is the<br />
file I/O not thread safe even when flock&#8217;d?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mla</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-8012</link>
		<dc:creator>mla</dc:creator>
		<pubDate>Fri, 28 Mar 2008 06:44:47 +0000</pubDate>
		<guid>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-8012</guid>
		<description>The patch to marshal seems to work perfectly :)

For pstore physical writes your version is 2x faster for me:

      user     system      total        real
std 20.240000  36.490000  56.730000 ( 58.234056)
new_canonical_marshal 13.090000  12.830000  25.920000 ( 26.656768)

That's using the fast store strategy and read/writing the same file 50k times.

For logical writes where the data hasn't changed, the new version is
roughly 15-20% slower:

      user     system      total        real
std  6.500000   3.160000   9.660000 (  9.841138)
new_canonical_marshal  8.640000   3.300000  11.940000 ( 12.119400)

I did some quick profiling and I don't see anything obvious. I think it's the
overhead of the added method calls. I inlined most of them and got pretty
close to the standard version.

new_mla  6.810000   3.110000   9.920000 ( 10.008198)

OTOH, even with the slight slow-down we're still talking 4k+ ops/sec
which is unlikely to be a bottleneck.</description>
		<content:encoded><![CDATA[<p>The patch to marshal seems to work perfectly <img src='http://izumi.plan99.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>For pstore physical writes your version is 2x faster for me:</p>
<p>      user     system      total        real<br />
std 20.240000  36.490000  56.730000 ( 58.234056)<br />
new_canonical_marshal 13.090000  12.830000  25.920000 ( 26.656768)</p>
<p>That&#8217;s using the fast store strategy and read/writing the same file 50k times.</p>
<p>For logical writes where the data hasn&#8217;t changed, the new version is<br />
roughly 15-20% slower:</p>
<p>      user     system      total        real<br />
std  6.500000   3.160000   9.660000 (  9.841138)<br />
new_canonical_marshal  8.640000   3.300000  11.940000 ( 12.119400)</p>
<p>I did some quick profiling and I don&#8217;t see anything obvious. I think it&#8217;s the<br />
overhead of the added method calls. I inlined most of them and got pretty<br />
close to the standard version.</p>
<p>new_mla  6.810000   3.110000   9.920000 ( 10.008198)</p>
<p>OTOH, even with the slight slow-down we&#8217;re still talking 4k+ ops/sec<br />
which is unlikely to be a bottleneck.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hongli</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-8001</link>
		<dc:creator>Hongli</dc:creator>
		<pubDate>Thu, 27 Mar 2008 21:01:31 +0000</pubDate>
		<guid>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-8001</guid>
		<description>Yeah, weird. I sent the email hours ago but I still don't see it.

http://pastebin.com/m12689e12
Patch is against 1.8.6.</description>
		<content:encoded><![CDATA[<p>Yeah, weird. I sent the email hours ago but I still don&#8217;t see it.</p>
<p><a href="http://pastebin.com/m12689e12" rel="nofollow">http://pastebin.com/m12689e12</a><br />
Patch is against 1.8.6.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mla</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-8000</link>
		<dc:creator>mla</dc:creator>
		<pubDate>Thu, 27 Mar 2008 20:54:55 +0000</pubDate>
		<guid>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-8000</guid>
		<description>Fantastic. I don't see the marshal patch in the archives yet. Would you post it to pastebin too?</description>
		<content:encoded><![CDATA[<p>Fantastic. I don&#8217;t see the marshal patch in the archives yet. Would you post it to pastebin too?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hongli</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-7995</link>
		<dc:creator>Hongli</dc:creator>
		<pubDate>Thu, 27 Mar 2008 18:40:49 +0000</pubDate>
		<guid>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-7995</guid>
		<description>I've modified Marshal.dump and added a 'canonical' option. :) A patch has been sent to ruby-core. I've also restored the MD5 checking code. It makes use of the 'canonical' option whenever possible. Code is here: http://pastebin.com/mb293607
Could you benchmark it?

(If you don't want to apply the patch, then you can simulate the 'canonical' behavior by calling rehash() on all your Hash elements, including the @table instance variable in PStore.)</description>
		<content:encoded><![CDATA[<p>I&#8217;ve modified Marshal.dump and added a &#8216;canonical&#8217; option. <img src='http://izumi.plan99.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> A patch has been sent to ruby-core. I&#8217;ve also restored the MD5 checking code. It makes use of the &#8216;canonical&#8217; option whenever possible. Code is here: <a href="http://pastebin.com/mb293607" rel="nofollow">http://pastebin.com/mb293607</a><br />
Could you benchmark it?</p>
<p>(If you don&#8217;t want to apply the patch, then you can simulate the &#8216;canonical&#8217; behavior by calling rehash() on all your Hash elements, including the @table instance variable in PStore.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mla</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-7984</link>
		<dc:creator>mla</dc:creator>
		<pubDate>Thu, 27 Mar 2008 01:33:15 +0000</pubDate>
		<guid>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-7984</guid>
		<description>&lt;blockquote&gt;By the way, what benchmark script did you use to generate the results seen in your pstore.png graph?&lt;/blockquote&gt;

Here is the patch to add partitioning:
http://mla.homeunix.com/tmp/pstore_hashed_directories.patch.txt

I think this is the script I used to test it. See the database_manager param which
I toggled for successive runs:

http://mla.homeunix.com/tmp/pstore-bench.rb

That was one of my first forays into Ruby so be gentle ;/

I think you should take another look at the md5 logic. Under Rails, the session is always being opened for R/W, correct?
Which means the session will always be written even if it hasn't changed.  But in most environments, the read/write ratio is often 10:1 or more.

In a quick benchmark of your new version, it appears to be 2x as slow when the session has not changed, suggesting that the write is still substantially more expensive than the md5 check.</description>
		<content:encoded><![CDATA[<blockquote><p>By the way, what benchmark script did you use to generate the results seen in your pstore.png graph?</p></blockquote>
<p>Here is the patch to add partitioning:<br />
<a href="http://mla.homeunix.com/tmp/pstore_hashed_directories.patch.txt" rel="nofollow">http://mla.homeunix.com/tmp/pstore_hashed_directories.patch.txt</a></p>
<p>I think this is the script I used to test it. See the database_manager param which<br />
I toggled for successive runs:</p>
<p><a href="http://mla.homeunix.com/tmp/pstore-bench.rb" rel="nofollow">http://mla.homeunix.com/tmp/pstore-bench.rb</a></p>
<p>That was one of my first forays into Ruby so be gentle ;/</p>
<p>I think you should take another look at the md5 logic. Under Rails, the session is always being opened for R/W, correct?<br />
Which means the session will always be written even if it hasn&#8217;t changed.  But in most environments, the read/write ratio is often 10:1 or more.</p>
<p>In a quick benchmark of your new version, it appears to be 2x as slow when the session has not changed, suggesting that the write is still substantially more expensive than the md5 check.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hongli</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-7983</link>
		<dc:creator>Hongli</dc:creator>
		<pubDate>Thu, 27 Mar 2008 00:39:26 +0000</pubDate>
		<guid>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-7983</guid>
		<description>By the way, what benchmark script did you use to generate the results seen in your pstore.png graph?</description>
		<content:encoded><![CDATA[<p>By the way, what benchmark script did you use to generate the results seen in your pstore.png graph?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hongli</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-7982</link>
		<dc:creator>Hongli</dc:creator>
		<pubDate>Wed, 26 Mar 2008 23:10:14 +0000</pubDate>
		<guid>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-7982</guid>
		<description>Hm, interesting. :) I'll look into this, thanks.

As for Marshal: it's implemented in C. Changing it would require a bit of work as well as patching the interpreter.</description>
		<content:encoded><![CDATA[<p>Hm, interesting. <img src='http://izumi.plan99.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> I&#8217;ll look into this, thanks.</p>
<p>As for Marshal: it&#8217;s implemented in C. Changing it would require a bit of work as well as patching the interpreter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mla</title>
		<link>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-7981</link>
		<dc:creator>mla</dc:creator>
		<pubDate>Wed, 26 Mar 2008 21:58:28 +0000</pubDate>
		<guid>http://izumi.plan99.net/blog/index.php/2008/03/26/making-pstore-reaaaally-fast/#comment-7981</guid>
		<description>&lt;blockquote&gt;This is true for listing all files in a directory, but are you sure it’s also true for reading the contents of a single of which the filename is already known?&lt;/blockquote&gt;

I believe so. Take a look at this graph that shows the performance gain by partitioning the sessions
into directories (this is on ext3 filesystem):

  http://mla.homeunix.com/tmp/pstore.png

I'll look at the marshal stuff later, but here's a example of how it can appear that the contents has changed when it hasn't:

  http://mla.homeunix.com/tmp/marshal-test.rb
  http://mla.homeunix.com/tmp/marshal-test.txt

I'm very much interested in gettting an improved version of the file session store into rails.  Esp. when using a load balancer that has session affinity, this is a very scalable solution if you can't or don't want to use the cookie store approach.</description>
		<content:encoded><![CDATA[<blockquote><p>This is true for listing all files in a directory, but are you sure it’s also true for reading the contents of a single of which the filename is already known?</p></blockquote>
<p>I believe so. Take a look at this graph that shows the performance gain by partitioning the sessions<br />
into directories (this is on ext3 filesystem):</p>
<p>  <a href="http://mla.homeunix.com/tmp/pstore.png" rel="nofollow">http://mla.homeunix.com/tmp/pstore.png</a></p>
<p>I&#8217;ll look at the marshal stuff later, but here&#8217;s a example of how it can appear that the contents has changed when it hasn&#8217;t:</p>
<p>  <a href="http://mla.homeunix.com/tmp/marshal-test.rb" rel="nofollow">http://mla.homeunix.com/tmp/marshal-test.rb</a><br />
  <a href="http://mla.homeunix.com/tmp/marshal-test.txt" rel="nofollow">http://mla.homeunix.com/tmp/marshal-test.txt</a></p>
<p>I&#8217;m very much interested in gettting an improved version of the file session store into rails.  Esp. when using a load balancer that has session affinity, this is a very scalable solution if you can&#8217;t or don&#8217;t want to use the cookie store approach.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
