<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Alexey&#039;s Random Notes</title>
	<atom:link href="http://timanovsky.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://timanovsky.wordpress.com</link>
	<description>Random technical comments, hacking</description>
	<lastBuildDate>Mon, 28 Jan 2013 19:35:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='timanovsky.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Alexey&#039;s Random Notes</title>
		<link>http://timanovsky.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://timanovsky.wordpress.com/osd.xml" title="Alexey&#039;s Random Notes" />
	<atom:link rel='hub' href='http://timanovsky.wordpress.com/?pushpress=hub'/>
		<item>
		<title>API versioning scheme for cloud REST services</title>
		<link>http://timanovsky.wordpress.com/2013/01/28/api-versioning-scheme-for-cloud-rest-services/</link>
		<comments>http://timanovsky.wordpress.com/2013/01/28/api-versioning-scheme-for-cloud-rest-services/#comments</comments>
		<pubDate>Mon, 28 Jan 2013 19:35:04 +0000</pubDate>
		<dc:creator>Alexey Timanovsky</dc:creator>
				<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Amazon AWS]]></category>
		<category><![CDATA[HTTP API]]></category>
		<category><![CDATA[REST API]]></category>
		<category><![CDATA[versioning]]></category>
		<category><![CDATA[Load balancing]]></category>

		<guid isPermaLink="false">http://timanovsky.wordpress.com/?p=254</guid>
		<description><![CDATA[Traditional approach Traditionally it is considered a good practise to have REST API versioning like &#8220;/api/v1/xxx&#8221; and when you transition to next version of your API you introduce &#8220;/api/v2/xxx&#8221;. It works well for traditional web application deployments where HTTP reverse proxy / load balancer front end exists. In such set up application-level load balancer can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=254&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<h3>Traditional approach</h3>
<p>Traditionally it is considered a good practise to have REST API versioning like &#8220;/api/v1/xxx&#8221; and when you transition to next version of your API you introduce &#8220;/api/v2/xxx&#8221;. It works well for traditional web application deployments where HTTP reverse proxy / load balancer front end exists. In such set up application-level load balancer can also work as an HTTP router, and you can configure where requests go. For example you can define &#8220;v1&#8243; request go to one rack, &#8220;v2&#8243; to other, and static files to third one.</p>
<p>Cloud services tend to simplify things and they often don&#8217;t have path-based HTTP routing capabilities. For example Microsoft Azure does load balancing at TCP level. So any request can hit any VM, so your application needs to be prepared to handle all types of requests at each VM instance. This introduces a lot of issues:</p>
<ul>
<li>No isolation. If you have a bug in v1 code which can be exploited all your instances are vulnerable;</li>
<li>Development limitations. You need to support whole code base making sure &#8216;v1&#8242; and &#8216;v2&#8242; live nicely together. Consider situation when some dependency is used in both &#8216;v1&#8242; and &#8216;v2&#8242; but require specific different versions;</li>
<li>Technology lock in. It either impossible or very hard to have &#8216;v1&#8242; in C# and &#8216;v2&#8242; in Python.</li>
<li>Deployment hurdle. You need to update all VMs in your cluster each time.</li>
<li>Capacity planing and monitoring. It is hard to understand how much resources are consumed by &#8216;v1&#8242; calls vs. &#8216;v2&#8242;</li>
</ul>
<p>Overall it is very risky, and eventually can become absolutely unmanageable.</p>
<h3>Cloud aware approach</h3>
<p>To overcome these and probably other difficulties I suggest to separate APIs at domain name level: e.g. &#8220;v1.api.mysite.com&#8221;, &#8220;v2.api.mysite.com&#8221;. It is then fairy easy to setup DNS mapping of the names to particular cloud clusters handling the requests. This way your clusters for &#8220;v1&#8243; and &#8220;v2&#8243; are completely independent &#8211; deployment, monitoring, they can even run on different platforms &#8211; JS, python, .NET, or even in different clouds &#8211; Amazon and Azure for example. You can scale them independently &#8211; scale v1 cluster down as load reduces, and scale v2 cluster up as its load increases. Then you can deploy &#8220;v2&#8243; into multiple locations and enable geo load balancing still keeping &#8220;v1&#8243; legacy set up compact and cheap. You can have &#8216;v1&#8242; in house, and &#8216;v2&#8242; hoste in cloud. Overall such set up is much more flexible and elastic, more easy to manage and maintain.</p>
<p>Of course this technique applies not only to HTTP REST API services but to others as well &#8211; HTTP, RTMP etc.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timanovsky.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timanovsky.wordpress.com/254/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=254&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timanovsky.wordpress.com/2013/01/28/api-versioning-scheme-for-cloud-rest-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/14d4d2c02acf61f5532588e30de4bf23?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">timanovsky</media:title>
		</media:content>
	</item>
		<item>
		<title>Comparison of cloud storage services</title>
		<link>http://timanovsky.wordpress.com/2012/10/26/comparison-of-cloud-storage-services/</link>
		<comments>http://timanovsky.wordpress.com/2012/10/26/comparison-of-cloud-storage-services/#comments</comments>
		<pubDate>Fri, 26 Oct 2012 20:35:15 +0000</pubDate>
		<dc:creator>Alexey Timanovsky</dc:creator>
				<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Amazon AWS]]></category>
		<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Google Cloud Storage]]></category>
		<category><![CDATA[Microsoft Azure BLOB storage]]></category>
		<category><![CDATA[Rackspace CloudFiles]]></category>

		<guid isPermaLink="false">http://timanovsky.wordpress.com/?p=237</guid>
		<description><![CDATA[In the table below I&#8217;m trying to compare Amazon AWS S3, Microsoft Azure Storage, Google Cloud Storage, Rackspace CloudFiles. Hope this is useful. Amazon AWS S3 MS Azure Google Cloud Storage Rackspace Cloud Files Max account size Unlimited? 200 TB per storage account(by default you have 20 storage accounts per subscription) = 4PB Unlimited? ?? [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=237&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In the table below I&#8217;m trying to compare <a href="http://aws.amazon.com/s3/">Amazon AWS S3</a>, <a href="http://msdn.microsoft.com/en-us/library/windowsazure/gg433040.aspx">Microsoft Azure Storage</a>, <a href="https://cloud.google.com/products/cloud-storage">Google Cloud Storage</a>, <a href="http://www.rackspace.com/cloud/public/files/">Rackspace CloudFiles</a>.</p>
<p>Hope this is useful.</p>
<table style="width:auto;border:1px solid #ddd;">
<tbody>
<tr>
<td></td>
<td style="background-color:#e6e6e6;"><span style="color:#000080;"><strong>Amazon AWS S3</strong></span></td>
<td style="background-color:#e6e6e6;"><span style="color:#000080;"><strong>MS Azure</strong></span></td>
<td style="background-color:#e6e6e6;"><span style="color:#000080;"><strong>Google Cloud Storage</strong></span></td>
<td style="background-color:#e6e6e6;"><span style="color:#000080;"><strong>Rackspace Cloud Files</strong></span></td>
</tr>
<tr>
<td><strong>Max account size</strong></td>
<td>Unlimited?</td>
<td>200 TB per storage account(by default you have 20 storage accounts per subscription) = 4PB</td>
<td>Unlimited?</td>
<td>??</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>Geo redundancy</strong></td>
<td>+extra price</td>
<td>+extra price</td>
<td>?</td>
<td>-</td>
</tr>
<tr>
<td><strong>SLA</strong></td>
<td>Availability SLA: 99.9%Designed to provide 99.999999999% durability and 99.99% availabilityReduced Redundancy:Designed to provide 99.99% durability and 99.99% availability</td>
<td>Availability SLA: 99.9%</td>
<td>Availability SLA: 99.9%</td>
<td>Availability SLA: 99.9%</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>HTTP</strong></td>
<td>+</td>
<td>+</td>
<td>+</td>
<td>-</td>
</tr>
<tr>
<td><strong>HTTPS</strong></td>
<td>+</td>
<td>+</td>
<td>+</td>
<td>+</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>Container namespace</strong></td>
<td>Global LName collision is possible</td>
<td>Storage account</td>
<td>Global L</td>
<td>Account</td>
</tr>
<tr>
<td><strong>Container (bucket) levels</strong></td>
<td>single</td>
<td>single</td>
<td>single</td>
<td>single</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>Root container</strong></td>
<td>-but with HTTP each bucket can have DNS name (not possible with HTTPS)</td>
<td>+</td>
<td>-but each bucket can have DNS name</td>
<td>-</td>
</tr>
<tr>
<td><strong>Cross origin CORS support</strong></td>
<td>+</td>
<td>-</td>
<td>+experimental</td>
<td>+</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>Max number of containers (buckets)</strong></td>
<td>100</td>
<td>unlimited</td>
<td>Unlimited?</td>
<td>500,000</td>
</tr>
<tr>
<td><strong>Container name length</strong></td>
<td>3-63a few limitations, basic form is “my.aws.bucket“in US region:255 bytes[A-Za-z0-9.-_]But DNS-compliant is recommended</td>
<td>3-63 chracters, valid DNS name</td>
<td>3 to 63 charactersvalid DNS nameIf name is dot-separated each component &lt;63 character, and 222 total</td>
<td>256after URL encoding, no ‘/’ character</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>Max files per container</strong></td>
<td>Unlimited, no performance penalty</td>
<td>unlimited</td>
<td>unlimited</td>
<td>Unlimited, but <a href="http://stackoverflow.com/questions/7372868/rackspace-cloud-files-how-to-size-containers-to-optimize-performance">API throttling begins at 50000 files</a>.</td>
</tr>
<tr>
<td><strong>List files, max results</strong></td>
<td>1000</td>
<td>5000</td>
<td>?</td>
<td>10,000</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>List files returns metadata</strong></td>
<td>-</td>
<td>+(configurable)</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td><strong>File (BLOB/object) name</strong></td>
<td>1024</td>
<td>1024</td>
<td>1024</td>
<td>1024 bytes after URL encoding</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>Max file size</strong></td>
<td>5TB</td>
<td>200GB (Block blob)1TB (page BLOB)</td>
<td>5TB</td>
<td>UnlimitedMultiple files in the same container with same name prefix can be joined into single virtual file.</td>
</tr>
<tr>
<td><strong>Max upload size</strong></td>
<td>5 GB</td>
<td>64 MB</td>
<td>5 MB?</td>
<td>5GB</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>HTTP Chunked upload</strong></td>
<td>-</td>
<td>-</td>
<td>+</td>
<td>+</td>
</tr>
<tr>
<td><strong>Parallel upload</strong></td>
<td>+</td>
<td>+</td>
<td>?(Resumable Uploads of Unknown Size)</td>
<td>+</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>Upload Data checksumming</strong></td>
<td>+</td>
<td>+</td>
<td>+</td>
<td></td>
</tr>
<tr>
<td><strong>Server-side copy</strong></td>
<td>+(up to 5 GB?)</td>
<td>+supports external sources</td>
<td>+</td>
<td>+</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>File metadata</strong></td>
<td>2KB, ASCII,no update</td>
<td>8KB</td>
<td>+ (size limit non specified)No update</td>
<td>90 pairs or 4096 bytes total</td>
</tr>
<tr>
<td><strong># data centers</strong></td>
<td>8</td>
<td>8</td>
<td>?</td>
<td>2: ORD, DFW</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>CDN-enabled</strong></td>
<td>+</td>
<td>+</td>
<td>?</td>
<td>+</td>
</tr>
<tr>
<td><strong>Authentication</strong></td>
<td>HMAC-SHA1 signing</td>
<td>HMAC-SHA256signing</td>
<td>OAuth 2.0Google cookie1-hr JWT token</td>
<td>24-hr token obtained from Cloud Authentication Service.</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>Time-limited shared access</strong></td>
<td>+</td>
<td>+</td>
<td>+</td>
<td>+</td>
</tr>
<tr>
<td><strong>File auto expiration</strong></td>
<td>+</td>
<td>-</td>
<td>-</td>
<td>+</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>Server-side encryption</strong></td>
<td>+AES-256</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr style="background-color:#f8f8f8;">
<td style="text-align:center;" colspan="5"><strong>PRICING</strong></td>
</tr>
<tr>
<td><strong>Storage per GB a month</strong></td>
<td>$0.037-$0.093 for reduced redundacny$0.055 &#8211; $0.125 for fully redundant</td>
<td>$0.037 &#8211; $ 0.093 for locally redundant storage$0.055 &#8211; $0.125 for geo redundant</td>
<td>$0.085 &#8211; $0.12</td>
<td>$0.10</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>Outgoing bandwidth per GB</strong></td>
<td>$0.05 &#8211; $0.12 (US)1GB /mo is free</td>
<td>$0.05 &#8211; $0.12 (UE/EU)$0.12-$0.19 (Asia)</td>
<td>$0.08-$0.12 (US)$0.15-$0.21 (Asia-Pacific)</td>
<td>$0.18</td>
</tr>
<tr>
<td><strong>Incoming bandwidth</strong></td>
<td>$0</td>
<td>$0</td>
<td>$0</td>
<td>$0</td>
</tr>
<tr style="background-color:#f8f8f8;">
<td><strong>PUT, POST, LIST</strong></td>
<td>$0.01 per 1000</td>
<td>$0.01 per 100 000 storage transactions</td>
<td>$0.01 per 1000</td>
<td>$0</td>
</tr>
<tr>
<td><strong>HEAD, GET, DELETE </strong></td>
<td>$0.01 per 10 000(no charge for delete)</td>
<td>$0.01 per 100 000 storage transactions</td>
<td>$0.01 per 10 000(no charge for delete)</td>
<td>$0</td>
</tr>
</tbody>
</table>
<p><strong>UPDATE (Nov 5, 2012):</strong> Azure Strorage now has higher limits, way better internal connectivity network, and higher performance targets, see <a title="announcement" href="http://blogs.msdn.com/b/windowsazurestorage/archive/2012/11/04/windows-azure-s-flat-network-storage-and-2012-scalability-targets.aspx">announcement</a>.</p>
<p>2000 IPOS per partition, 20000 IPOS per storage account.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timanovsky.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timanovsky.wordpress.com/237/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=237&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timanovsky.wordpress.com/2012/10/26/comparison-of-cloud-storage-services/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/14d4d2c02acf61f5532588e30de4bf23?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">timanovsky</media:title>
		</media:content>
	</item>
		<item>
		<title>Brief reference on cloud storage</title>
		<link>http://timanovsky.wordpress.com/2012/05/05/brief-reference-on-cloud-storage/</link>
		<comments>http://timanovsky.wordpress.com/2012/05/05/brief-reference-on-cloud-storage/#comments</comments>
		<pubDate>Sat, 05 May 2012 07:09:56 +0000</pubDate>
		<dc:creator>Alexey Timanovsky</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Storage]]></category>

		<guid isPermaLink="false">http://timanovsky.wordpress.com/?p=224</guid>
		<description><![CDATA[This is very brief and shallow comparison of data model and partitioning principles in Amazon S3 and Azure Storage. Please also see my feature comparison post of various storage platforms: http://timanovsky.wordpress.com/2012/10/26/comparison-of-cloud-storage-services/ Amazon S3 Getting most out of Amazon S3: http://aws.typepad.com/aws/2012/03/amazon-s3-performance-tips-tricks-seattle-hiring-event.html Their storage directory is lexigraphically-sorted, and leftmost characters used as partition key. It is not said, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=224&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This is very brief and shallow comparison of data model and partitioning principles in Amazon S3 and Azure Storage. Please also see my feature comparison post of various storage platforms: <a href="http://timanovsky.wordpress.com/2012/10/26/comparison-of-cloud-storage-services/">http://timanovsky.wordpress.com/2012/10/26/comparison-of-cloud-storage-services/</a><br />
<strong>Amazon S3</strong><br />
Getting most out of Amazon S3: <a href="http://aws.typepad.com/aws/2012/03/amazon-s3-performance-tips-tricks-seattle-hiring-event.html">http://aws.typepad.com/aws/2012/03/amazon-s3-performance-tips-tricks-seattle-hiring-event.html</a><br />
Their storage directory is lexigraphically-sorted, and leftmost characters used as partition key. It is not said, but looks like you need to have your prefix tree balanced in order for partition balancing to work optimally. I.e. if you prefix with 0-9A-F as suggested in the article, amount of requests going to all 16 prefixes must be roughly the same. This underneath might mean that key space is always partitioned evenly &#8211; split into fixed amount of equal key ranges. That is totally my speculation, but otherwise I can not explain why such prefixes would matter.</p>
<p><strong>Microsoft Azure Storage</strong><br />
<a href="http://blogs.msdn.com/b/windowsazurestorage/archive/2010/05/10/windows-azure-storage-abstractions-and-their-scalability-targets.aspx">http://blogs.msdn.com/b/windowsazurestorage/archive/2010/05/10/windows-azure-storage-abstractions-and-their-scalability-targets.aspx</a><br />
<a href="http://blogs.msdn.com/b/windowsazurestorage/archive/2010/12/30/windows-azure-storage-architecture-overview.aspx">http://blogs.msdn.com/b/windowsazurestorage/archive/2010/12/30/windows-azure-storage-architecture-overview.aspx</a><br />
<a href="http://blogs.msdn.com/b/windowsazurestorage/archive/2011/11/20/windows-azure-storage-a-highly-available-cloud-storage-service-with-strong-consistency.aspx">http://blogs.msdn.com/b/windowsazurestorage/archive/2011/11/20/windows-azure-storage-a-highly-available-cloud-storage-service-with-strong-consistency.aspx</a><br />
Having glanced over MS docs I&#8217;m under impression that Azure storage can split key ranges independently based on the load and size.<br />
<strong>Update:</strong> The following quote shows that Azure is similar to S3, and I was wrong:</p>
<blockquote><p>A downside of range partitioning is scaling out access to<br />
sequential access patterns. For example, if a customer is writing<br />
all of their data to the very end of a table’s key range (e.g., insert<br />
key 2011-06-30:12:00:00, then key 2011-06-30:12:00:02, then<br />
key 2011-06:30-12:00:10), all of the writes go to the very last<br />
RangePartition in the customer’s table. This pattern does not take<br />
advantage of the partitioning and load balancing our system<br />
provides. In contrast, if the customer distributes their writes<br />
across a large number of PartitionNames, the system can quickly<br />
split the table into multiple RangePartitions and spread them<br />
across different servers to allow performance to scale linearly<br />
with load (as shown in Figure 6). To address this sequential<br />
access pattern for RangePartitions, a customer can always use<br />
hashing or bucketing for the PartitionName, which avoids the<br />
above sequential access pattern issue.</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timanovsky.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timanovsky.wordpress.com/224/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=224&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timanovsky.wordpress.com/2012/05/05/brief-reference-on-cloud-storage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/14d4d2c02acf61f5532588e30de4bf23?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">timanovsky</media:title>
		</media:content>
	</item>
		<item>
		<title>Enabling ARCHIVE storage engine in IUS MySQL 5.1</title>
		<link>http://timanovsky.wordpress.com/2010/10/09/enabling-archive-storage-engine-in-ius-mysql-5-1/</link>
		<comments>http://timanovsky.wordpress.com/2010/10/09/enabling-archive-storage-engine-in-ius-mysql-5-1/#comments</comments>
		<pubDate>Sat, 09 Oct 2010 08:17:50 +0000</pubDate>
		<dc:creator>Alexey Timanovsky</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[BI]]></category>
		<category><![CDATA[IUS repo]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://timanovsky.wordpress.com/?p=215</guid>
		<description><![CDATA[IUS is great repo which allows seamless integration of MySQL 5.1 and Python 2.6 into CentOS systems (which have 5.0 and 2.4 versions). The only issue is that if you run &#8216;SHOW ENGINES&#8217; it will only show you MRG_MYISAM, CSV, FEDERATED, InnoDB, MEMORY, MyISAM engines. I wanted to experiment with ARCHIVE storage engine for storing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=215&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://iuscommunity.org/">IUS</a> is great repo which allows seamless integration of MySQL 5.1 and Python 2.6 into CentOS systems (which have 5.0 and 2.4 versions). The only issue is that if you run &#8216;SHOW ENGINES&#8217; it will only show you MRG_MYISAM, CSV, FEDERATED, InnoDB, MEMORY, MyISAM engines. I wanted to experiment with ARCHIVE storage engine for storing raw input BI events, which is basically JSON. ARCHIVE engine seems to be a good hit for this &#8211; it supports compression (of our highly redundant data) and auto increment, which is necessary to implement queue-like processing, how it goes should be a topic for the separate post. So I was puzzled when I didn&#8217;t see archive storage engine in MySQL by IUS. Initial googling only suggested that ARCHIVE storage engine is enabled at compile time, which was pretty sad and I couldn&#8217;t understand why on the Earth had they omitted it. Later I found<a href="http://www.willis-owen.co.uk/wp/2010/01/ius-mysql-how-to-enable-the-archive-storage-engine/"> this post</a> suggesting that ARCHIVE storage engine can be installed as plugin, and I need to install separate YUM packages. Finding for those packages in the current repo gave no results. So I finally found <a href="https://answers.launchpad.net/ius/+question/127045">this bugreport</a> revealing taht a few plugins are actually installed as a part of mysql51-server package and you only need to enable it! So I went a head and<br />
<code><br />
mysql&gt; INSTALL PLUGIN archive SONAME 'ha_archive.so';<br />
Query OK, 0 rows affected (0.02 sec)<br />
</code><br />
And then<br />
<code><br />
mysql&gt; show engines \G</code></p>
<p><code> </code></p>
<p><code>*************************** 7. row ***************************<br />
Engine: ARCHIVE<br />
Support: YES<br />
Comment: Archive storage engine<br />
Transactions: NO<br />
XA: NO<br />
Savepoints: NO<br />
7 rows in set (0.00 sec)<br />
</code></p>
<p>Voila!</p>
<p>The following plugins are installed into the OS but not into MySQL:</p>
<p><code><br />
ha_archive.so - ARCHIVE<br />
ha_blackhole.so - BLACKHOLE<br />
ha_example.so - EXAMPLE<br />
ha_innodb_plugin.so - InnoDB Plugin<br />
</code></p>
<p>Enjoy!</p>
<p><strong>Update</strong>: Experiment on 24M rows shows 11X compression ratio! From 437 bytes/row in InnoDB (no indexes) down to 38 bytes per row.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timanovsky.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timanovsky.wordpress.com/215/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=215&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timanovsky.wordpress.com/2010/10/09/enabling-archive-storage-engine-in-ius-mysql-5-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/14d4d2c02acf61f5532588e30de4bf23?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">timanovsky</media:title>
		</media:content>
	</item>
		<item>
		<title>SSH: Convert OpenSSH to SSH2 and vise versa (via //burnz.blog)</title>
		<link>http://timanovsky.wordpress.com/2010/08/18/ssh-convert-openssh-to-ssh2-and-vise-versa-via-burnz-blog/</link>
		<comments>http://timanovsky.wordpress.com/2010/08/18/ssh-convert-openssh-to-ssh2-and-vise-versa-via-burnz-blog/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 13:47:02 +0000</pubDate>
		<dc:creator>Alexey Timanovsky</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[openssh]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://timanovsky.wordpress.com/2010/08/18/ssh-convert-openssh-to-ssh2-and-vise-versa-via-burnz-blog/</guid>
		<description><![CDATA[SSH2 format is used by windows PuTTY. If you need to migrate your SSH keys from windows to linux/ mac os, then this article is useful. Connecting two server running different type of SSH can be nightmare if you does not know how to convert the key. In this tutorial, I will try to explain [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=209&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>SSH2 format is used by windows PuTTY. If you need to migrate your SSH keys from windows to linux/ mac os, then this article is useful.</p>
<blockquote cite='http://burnz.wordpress.com/2007/12/14/ssh-convert-openssh-to-ssh2-and-vise-versa/' style='overflow:hidden;'><p><a href='http://burnz.wordpress.com/2007/12/14/ssh-convert-openssh-to-ssh2-and-vise-versa/' title='//burnz.blog'></a> Connecting two server running different type of SSH can be nightmare if you does not know how to convert the key. In this tutorial, I will try to explain on how to convert the public key from OpenSSH to SSH2 and SSH2 to OpenSSH. To convert the key, it must be done in OpenSSH server. Convert OpenSSH key to SSH2 key Run the OpenSSH version of ssh-keygen on your OpenSSH public key to convert it into the format needed by SSH2 on the remote machine. T &#8230; <a href='http://burnz.wordpress.com/2007/12/14/ssh-convert-openssh-to-ssh2-and-vise-versa/' title='//burnz.blog'>Read More</a></p>
</blockquote>
<p>via <a href='http://burnz.wordpress.com/2007/12/14/ssh-convert-openssh-to-ssh2-and-vise-versa/' title='//burnz.blog'>//burnz.blog</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timanovsky.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timanovsky.wordpress.com/209/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=209&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timanovsky.wordpress.com/2010/08/18/ssh-convert-openssh-to-ssh2-and-vise-versa-via-burnz-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/14d4d2c02acf61f5532588e30de4bf23?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">timanovsky</media:title>
		</media:content>
	</item>
		<item>
		<title>Some myths about H.264 vs Theora and their use in HTML5 video tag.</title>
		<link>http://timanovsky.wordpress.com/2010/05/02/some-myths-about-h-264-vs-theora/</link>
		<comments>http://timanovsky.wordpress.com/2010/05/02/some-myths-about-h-264-vs-theora/#comments</comments>
		<pubDate>Sun, 02 May 2010 19:26:29 +0000</pubDate>
		<dc:creator>Alexey Timanovsky</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[h.264]]></category>
		<category><![CDATA[h264]]></category>
		<category><![CDATA[mpeg]]></category>
		<category><![CDATA[mpeg-la]]></category>
		<category><![CDATA[theora]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://timanovsky.wordpress.com/?p=191</guid>
		<description><![CDATA[I was planning to write this post some time ago, now I&#8217;ve got the last piece of puzzle [7]. Myth: H.264 &#8211; is proprietary codec, Theora &#8211; is open. Facts: H.264 &#8211; is open international standard ISO/IEC 14496-10 [8], there exist open/free reference code and several open source implementations. Theora &#8211; is nonstandard codec with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=191&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I was planning to write this post some time ago, now I&#8217;ve got the last piece of puzzle [7]. </p>
<p><strong>Myth:</strong> H.264 &#8211; is proprietary codec, Theora &#8211; is open.<br />
<strong>Facts:</strong>  H.264 &#8211;  is open international standard ISO/IEC 14496-10 [8], there exist open/free reference code and several open source implementations. Theora &#8211; is nonstandard codec with unpredictable roadmap, distributed as open source [5].</p>
<p><strong>Myth:</strong> One have to pay royalties to use H.264 on web site<br />
<strong>Facts:</strong> No if your video content is free (i.e. you are not selling videos on title-by-title or subscription basis), at least till the end of 2015 [10]. This date has been moved several times, chances are it will be moved yet again. After that date one will have to pay $2500/year if service has less than half a million users; $5K &#8211;  if less than 1M users; $10K &#8211; over 1M users. The bill very reasonable even for startup. Additional protection is that license terms are fixed for five years, and royalties can not be increased by more than 10% at renewal. [4]</p>
<p><strong>Myth</strong>: One have to pay for H.264 encoding and decoding applications.One have to pay if using browser with H.264.<br />
<strong>Facts:</strong> Yes, each developer of H.264 encoding/decoding application or library has to pay  $0.20 for each copy sold. If you are an end user there is no grounds to worry, it is application developer/distributor responsibility to pay the royalties. Paid application have royalties already included. Free applications like IE, Safari, iTunes, Flash will obviously remain free, as corporations will wave those royalties for users. Moreover some of the SW companies are among H.264 licensors, so they probably have special conditions agreements and pay much less if anything. It is not clear, but companies like Mozilla, Firefox maker, may be among losers, as they don&#8217;t have a way to pay royalties if they are found to have to. [4]</p>
<p><strong>Myth</strong>: Theora &#8211; open source codec, therefore it could be no problems with patent infringement.<br />
<strong>Facts</strong>:  Video codecs (and audio too) is a knowledge area with extremely high patent density. Everything one can imagine has already been patented, that&#8217;s what millions bucks research budgets are spent for. So probability of Theora being patent-clear is zero. </p>
<p><strong>Myth:</strong>  On2 donated original (VP3) code which Theora is based on, and warranted no legal actions against anybody using it or its modifications. So no patent worries.<br />
<strong>Facts:</strong> A) There is only protection from On2 legal actions [6] B) Development of Theora went quite a bit from original VP3 code, so it now may infringe some patents unintentionally. C) There is no warranties that original VP3 technology does not violate third party patents including ones in H.264 patent pool.  D) Another fact to keep in mind, even obtaining MPEG-LA license does not warrant one is all covered, there could be other panets out of MPEG-LA pool [3]. E) We&#8217;ve got first confirmation that legal actions against Theora are possible &#8211; by Steve Jobs [7].</p>
<p><strong>Myth</strong>: With broad support for <code>Video</code> tag in browsers Flash Video will die.<br />
<strong>Facts:</strong> Not that soon.  <code>Video</code> tag provides way fewer controls to developer &#8211; e.g. no caching and buffer size control. Live streaming is not supported yet, and is not in roadmaps.</p>
<p><strong>Who is in which camp among SW giants?</strong><br />
<strong>Fact:</strong> Apple, Microsoft are among H.264 licensors pool; Adobe, Google are not. [2] Google seems to be trying to build its own video patent portfolio by acquiring On2 company [9].</p>
<p><strong>Why industry seems to like H.264 codec more than free open source solutions</strong>?<br />
This codec is now supported by Adobe Flash, MS Silverlight, Apple iTunes/QuickTime, it is supported by a lot of mobile phones, camcoders, digital television etc. And its support will become only wider. For all industry players it is very beneficial to have single universal standard codec, it allows for great technology reuse, simplifies and makes development cheaper, it benefits technology convergence. And after all it is just a very good codec delivering very good quality in wide bitrate ranges.</p>
<p><strong>Conclusion:</strong><br />
We will see major perturbations if Theora success starts threaten business of big guys.</p>
<p><strong>Update</strong><br />
1. Changed spelling to Firefox, as was required <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
2. Actually, H.264 use for free internet broadcast will remain royalty-free till the end of 2015 [10], as pointed out in<br />
3. One more good article: <a href="http://www.engadget.com/2010/05/04/know-your-rights-h-264-patent-licensing-and-you/">http://www.engadget.com/2010/05/04/know-your-rights-h-264-patent-licensing-and-you/</a></p>
<p><strong>Update 2</strong><br />
Another very good article on On2-Google VP8 now: <a href="http://x264dev.multimedia.cx/?p=377">http://x264dev.multimedia.cx/?p=377</a> It nicely describes overall quality of VP8 code, and patent issues with VP8 and MS&#8217;s VC-1. The later was also thought patent-free initially. </p>
<p><strong>References</strong><br />
1. H.264 page at MPEG LA site: <a href="http://www.mpegla.com/main/programs/AVC/Pages/Intro.aspx">http://www.mpegla.com/main/programs/AVC/Pages/Intro.aspx</a><br />
2. List of H.264 patent pool licensors &#8211; <a href="http://www.mpegla.com/main/programs/AVC/Pages/Licensors.aspx">http://www.mpegla.com/main/programs/AVC/Pages/Licensors.aspx</a><br />
3. MPEG LA FAQ  <a href="http://www.mpegla.com/main/programs/AVC/Pages/FAQ.aspx">http://www.mpegla.com/main/programs/AVC/Pages/FAQ.aspx</a><br />
4. Summary of H.264 license terms by MPEG LA &#8211; <a href="http://www.mpegla.com/main/programs/AVC/Documents/AVC_TermsSummary.pdf">http://www.mpegla.com/main/programs/AVC/Documents/AVC_TermsSummary.pdf</a><br />
5. Theora codec page: <a href="http://www.theora.org">http://www.theora.org</a><br />
6. On2 statement about VP3 license: <a href="http://svn.xiph.org/trunk/theora/LICENSE">http://svn.xiph.org/trunk/theora/LICENSE</a><br />
7. Apple prepares to go after open source codecs: <a href="http://blogs.fsfe.org/hugo/2010/04/open-letter-to-steve-jobs/">http://blogs.fsfe.org/hugo/2010/04/open-letter-to-steve-jobs/</a><br />
8. Official H.264 standard <a href="http://www.iso.org/iso/catalogue_detail.htm?csnumber=52974">http://www.iso.org/iso/catalogue_detail.htm?csnumber=52974</a><br />
9. Google acquires On2 Technologies &#8211; <a href="http://www.google.com/intl/en/press/pressrel/ir_20090805.html">http://www.google.com/intl/en/press/pressrel/ir_20090805.html</a><br />
10. H.264 will remain free for internet broadcast till end of 2015 <a href="http://www.mpegla.com/Lists/MPEG%20LA%20News%20List/Attachments/226/n-10-02-02.pdf">http://www.mpegla.com/Lists/MPEG%20LA%20News%20List/Attachments/226/n-10-02-02.pdf</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timanovsky.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timanovsky.wordpress.com/191/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=191&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timanovsky.wordpress.com/2010/05/02/some-myths-about-h-264-vs-theora/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/14d4d2c02acf61f5532588e30de4bf23?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">timanovsky</media:title>
		</media:content>
	</item>
		<item>
		<title>Fast IP-&gt;location resolution in SQL</title>
		<link>http://timanovsky.wordpress.com/2009/12/25/fast-ip-location-resolution-in-sql/</link>
		<comments>http://timanovsky.wordpress.com/2009/12/25/fast-ip-location-resolution-in-sql/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 11:59:35 +0000</pubDate>
		<dc:creator>Alexey Timanovsky</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://timanovsky.wordpress.com/?p=187</guid>
		<description><![CDATA[Abstract Many web services nowadays rely on users&#8217; geo location information. It can be required purely for statistics purposes, or to add value to provided service itself. In most cases the only possible way to detect user location is to use IP address of originating request. IP addresses are not hierarchical in a geographical sense, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=187&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><strong>Abstract</strong><br />
Many web services nowadays rely on users&#8217; geo location information. It can be required purely for statistics purposes, or to add value to provided service itself. In most cases the only possible way to detect user location is to use IP address of originating request. IP addresses are not hierarchical in a geographical sense, large block of IP addresses is reserved to an ISP, and then broken down for smaller companies or individuals. There is no much order in the system. So a quick database is required in order to be able to make millions of lookups.</p>
<p><strong>Geo location data</strong><br />
Surely enough companies exist which provide such IP-based geo location data. <a href="http://www.maxmind.com/app/ip-location">Maxmind</a> is one of them. Fortunately they provide<a href="http://www.maxmind.com/app/geolitecountry"> free version</a> of their database under some legal constraints. There are other providers too, I&#8217;ve recently came across <a href="http://ipinfodb.com/ip_database.php">IpInfoDB</a>. So far so good, now we need a system to make use of the data.</p>
<p><strong>Physical database design</strong><br />
Data consists of (startIp, endIp, country) tuples. If IP address is in the range, it is originated from that country. There blind unassigned ranges, there are private ranges, and as said above multiple (very many) ranges map to a Country. In my table there is &gt; 100K distinct IP ranges.</p>
<p>Physical design in MySQL:<br />
<code>CREATE TABLE LookupIpToCountry (<br />
  startIp int(10) unsigned NOT NULL,<br />
  endIp int(10) unsigned NOT NULL,<br />
  countryId tinyint(3) unsigned NOT NULL,<br />
  PRIMARY KEY  (startIp),<br />
  KEY fk_countryId (countryId),<br />
  CONSTRAINT LookupIpToCountry_ibfk_1 FOREIGN KEY (countryId) REFERENCES Countries (id)<br />
) ENGINE=InnoDB;</code></p>
<p>Other database or engine can be used, provided that <code>startIp</code> is clustering index, i.e. data in the table is physically sorted according to startIp in ascending order.</p>
<p><strong>Fast lookup query</strong><br />
<code>mysql&gt; select * from LookupIpToCountry where startIp&lt;=INET_ATON('74.125.19.99') and endIp&gt;=INET_ATON('74.125.19.99')  order by startIp desc limit 1;<br />
+------------+------------+-----------+<br />
| startIp    | endIp      | countryId |<br />
+------------+------------+-----------+<br />
| 1249693272 | 1249773023 |       230 |<br />
+------------+------------+-----------+<br />
1 row in set (0.00 sec)</code></p>
<p>The idea here is to find the first region into which IP of interest falls. <code>SELECT ... WHERE startIp&lt;= X ... order by startIp desc</code> will navigate through B-tree index  to the last row satisfying <code>startIp</code> criterion and setup scan iterator in descending order. (Because it can only validate second condition  <code>endIp&gt;= X </code>by scanning). But the iteration ends immediately because of <code>LIMIT 1</code> if second condition is satisfied. So effectively whole query is reduced to B-tree lookup of one value. Of course, in case of the miss (IP address does not fall to any of known ranges), there is a performance hit:</p>
<p><code>mysql&gt; select * from LookupIpToCountry where startIp&lt;=INET_ATON('255.255.255.255') and endIp&gt;=INET_ATON('255.255.255.255')  order by startIp desc limit 1;<br />
Empty set (<strong>0.39 sec</strong>)</code></p>
<p>In order to fix it you can simplify the query to <code>select * from LookupIpToCountry where startIp&lt;=INET_ATON('255.255.255.255') order by startIp desc limit 1;</code> and check second condition <code>endIp&gt;=INET_ATON('255.255.255.255')</code> at application level, if you think it is worth.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timanovsky.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timanovsky.wordpress.com/187/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=187&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timanovsky.wordpress.com/2009/12/25/fast-ip-location-resolution-in-sql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/14d4d2c02acf61f5532588e30de4bf23?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">timanovsky</media:title>
		</media:content>
	</item>
		<item>
		<title>Solving performance problems in pub-sub erlang server</title>
		<link>http://timanovsky.wordpress.com/2009/08/20/solving-performance-problems-in-pub-sub-erlang-server/</link>
		<comments>http://timanovsky.wordpress.com/2009/08/20/solving-performance-problems-in-pub-sub-erlang-server/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 20:15:22 +0000</pubDate>
		<dc:creator>Alexey Timanovsky</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Erlang]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[long polling]]></category>
		<category><![CDATA[mochiweb]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[pub-sub]]></category>
		<category><![CDATA[TCP]]></category>

		<guid isPermaLink="false">http://timanovsky.wordpress.com/?p=133</guid>
		<description><![CDATA[Intro So I wrote (see some prehistory here) a kind of notification server where clients can subscribe to events and be notified when event of interest happens. Clients use HTTP long poll method to get notifications delivered, and one of the application of the server is chat room. Symptoms In my case there were two [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=133&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><strong>Intro</strong><br />
So I wrote (see some prehistory <a href="http://timanovsky.wordpress.com/2009/01/09/toward-a-million-user-long-poll-http-application-nginx-erlang-mochiweb/">here</a>) a kind of notification server where clients can subscribe to events and be notified when event of interest happens.  Clients use HTTP long poll method to get notifications delivered, and one of the application of the server is chat room.</p>
<p><strong>Symptoms</strong><br />
In my case there were two problems:</p>
<ol>
<li>general lack of performance (I started optimizing somewhere from 200-300 messages per second)</li>
<li>under high load server would lock up, sometimes for extended period of time &#8211; it does not deliver any messages</li>
<li>even under moderate load performance is not stable and would drop eventually for some period of time (sometimes to complete lock up, sometimes not, sometimes for a couple of seconds, sometimes for longer time).</li>
<li>In-depth investigation with tcpdump has shown that server can not even accept connections.</li>
</ol>
<p><strong>Side note on server not accepting tcp connections</strong><br />
That is interesting how it happens though. I don&#8217;t know if it is specific Linux 2.6 behavior of it is a norm, but the sequence is:</p>
<ol>
<li>client sends SYN</li>
<li>server responds with ACK, but acknowledgment number set to some arbitrary big number</li>
<li>client drops connection by sending RST</li>
</ol>
<p>So should you see similar behavior note that this is just a symptom, not disease. The problem is somewhere dipper. In my case increasing TCP listen backlog from mochiweb&#8217;s default 30 helped a bit, fewer timeouts were observed, but still performance sucked.</p>
<p><strong>Fixing Root Cause</strong><br />
So how pub-sub servers in Erlang are generally built? You get a message being processed in some process, it might have been received from somewhere else or originates from this process . And then you have bunch of waiting processes representing connected subscribed clients waiting for a message be delivered. Each of these processes normally represents TCP connection or in my case HTTP long polling connection. And delivering message to this process releases it from wait state and allows message to be delivered to end user. There is of course some router module or process which determines a subset of processes (PIDs) to which the message should be delivered. How to do efficiently is very interesting topic but not for this post. Then you do something like<br />
<strong><code>lists:foreach(fun(Pid) -&gt; send_message(Pid, Message) end, PidList)</code></strong></p>
<p>The result of this is that each of processes from the target group (selected by router) becomes immediately available for execution. And if the group size is big, chances are that current process broadcasting this notifications will be preempted. And the thing is that this actually causes context switching storm. I&#8217;m not 100% sure how Erlang runtime is implemented, but it seems that if process receives a message it gets some kind of priority and is scheduled for execution, like it happens in some OSes. So the message sending loop may take quite awhile.</p>
<p>Now, if the message broadcast loop is more complex, say it consists of two nested loops, and inside it you do some non trivial operations followed by sending the message for one particular PID, then the things become very bad. Context switching overhead no matter how light it is in Erlang kills your performance.</p>
<p><strong>Recipe</strong></p>
<ol>
<li>If you have complex loops to calculate to which PID send the message, and you do message sending inside that loop &#8211; rewrite the code. First prepare list of PIDs using whatever complex procedures you have, then send messages to those PIDs in one shot.</li>
<li>Then sending messages to bunch of PIDs do temporarily boost performance of your thread so it won&#8217;t be preempted.</li>
</ol>
<p>Example:<br />
<strong><code><br />
PidList = generate_pid_list(WhatEver),<br />
OldPri = process_flag(priority, high),  % Raise priority, save old one<br />
lists:foreach(fun({Pid, Msg}) -&gt; send_message(Pid, Msg) end, PidList),<br />
process_flag(priority, OldPri)<br />
</code><br />
</strong><br />
That&#8217;s basically it. The result is that now I&#8217;m reliably achieving about 1.5k messages/sec with all stuff like HTTP/JSON parsing, ETS operations, logging, etc. I would like to pump this number few times higher, but at the moment that&#8217;s what I can get. I will come back when learn something new <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>PS. You may also find this discussion followed $1000 code challenge useful:<br />
<a href="http://groups.google.com/group/erlang-programming/browse_thread/thread/1931368998000836/b325e869a3eea26a">http://groups.google.com/group/erlang-programming/browse_thread/thread/1931368998000836/b325e869a3eea26a</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timanovsky.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timanovsky.wordpress.com/133/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=133&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timanovsky.wordpress.com/2009/08/20/solving-performance-problems-in-pub-sub-erlang-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/14d4d2c02acf61f5532588e30de4bf23?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">timanovsky</media:title>
		</media:content>
	</item>
		<item>
		<title>Fix Eclipse Config to Start with Broken Perspective</title>
		<link>http://timanovsky.wordpress.com/2009/08/13/fix-eclipse-config-to-start-with-broken-perspective/</link>
		<comments>http://timanovsky.wordpress.com/2009/08/13/fix-eclipse-config-to-start-with-broken-perspective/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 10:10:16 +0000</pubDate>
		<dc:creator>Alexey Timanovsky</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Eclipse]]></category>

		<guid isPermaLink="false">http://timanovsky.wordpress.com/?p=129</guid>
		<description><![CDATA[I happened to switch to Ruby Browsing Perspective in Eclipse eventually, for whatever reason it crashed Eclipse with Out of Memory exception. When I try to restart it won&#8217;t, because it tries to load all the same Perspective. The solution is to edit one of Eclipse config files. The file of interest is "workspace/.metadata/.plugins/org.eclipse.ui.workbench/workbench.xml" (in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=129&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I happened to switch to Ruby Browsing Perspective in Eclipse eventually, for whatever reason it crashed Eclipse with Out of Memory exception. When I try to restart it won&#8217;t, because it tries to load all the same Perspective. The solution is to edit one of Eclipse config files. The file of interest is <code>"workspace/.metadata/.plugins/org.eclipse.ui.workbench/workbench.xml"</code> (in my case on Mac it is ~Documents/workspace/.metadata/.plugins/org.eclipse.ui.workbench/workbench.xml)</p>
<p>The default perspective is configured by the following directive:<br />
<code>&lt;perspectives activePart="org.rubypeople.rdt.ui.EditorRubyFile"<strong> activePerspective="org.rubypeople.rdt.ui.RubyBrowsingPerspective"</strong>&gt;</code></p>
<p>So what I had to do is replace <code>org.rubypeople.rdt.ui.RubyBrowsingPerspective</code> with <code>org.eclipse.jdt.ui.JavaPerspective</code></p>
<p>You can find for exact class names of available perspectives in the same file. Perspective declaration looks like:<br />
<code><br />
&lt;perspective editorAreaTrimState="2" editorAreaVisible="1" fixed="0" version="0.016"&gt;<br />
&lt;descriptor class="org.eclipse.jdt.internal.ui.JavaPerspectiveFactory" <strong>id="org.eclipse.jdt.ui.JavaPerspective" </strong>label="Java"/&gt;<br />
...<br />
</code><br />
First line is opening of perspective declaration, and &lt;descriptor&gt; tag contains id attribute which is what you want. If you search trough <code>workbench.xml</code> you will find all available perspective names.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timanovsky.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timanovsky.wordpress.com/129/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=129&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timanovsky.wordpress.com/2009/08/13/fix-eclipse-config-to-start-with-broken-perspective/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/14d4d2c02acf61f5532588e30de4bf23?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">timanovsky</media:title>
		</media:content>
	</item>
		<item>
		<title>Tuning Linux firewall connection tracker ip_conntrack</title>
		<link>http://timanovsky.wordpress.com/2009/04/10/tuning-linux-firewall-connection-tracker-ip_conntrack/</link>
		<comments>http://timanovsky.wordpress.com/2009/04/10/tuning-linux-firewall-connection-tracker-ip_conntrack/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 15:16:14 +0000</pubDate>
		<dc:creator>Alexey Timanovsky</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[conntrack]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://timanovsky.wordpress.com/?p=117</guid>
		<description><![CDATA[Overview If your Linux server should handle lots of connections, you can get into the problem with ip_conntrack iptables module. It limits number of simultaneous connections your system can have. Default value (in CentOS and most other distros) is 65536. To check how many entries in the conntrack table are occupied at the moment: cat [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=117&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><strong>Overview</strong><br />
If your Linux server should handle lots of connections, you can get into the problem with ip_conntrack iptables module. It limits number of simultaneous connections your system can have. Default value (in CentOS and most other distros) is 65536.</p>
<p>To check how many entries in the conntrack table are occupied at the moment:<br />
<code><br />
cat /proc/sys/net/ipv4/netfilter/ip_conntrack_count<br />
</code><br />
Or you can dump whole table :<br />
<code><br />
cat /proc/net/ip_conntrack<br />
</code></p>
<p>Conntrack table is hash table (hash map) of fixed size (8192 entries by default), which is used for primary lookup. When the slot in the table is found it points to list of conntrack structures, so secondary lookup is done using list traversal. 65536/8192 gives 8 &#8211; the average list length.  You may want to experiment with this value on heavily loaded systems.</p>
<p><strong>Modifying conntrack capacity</strong><br />
To see the current conntrack capacity:<br />
<code><br />
cat /proc/sys/net/ipv4/netfilter/ip_conntrack_max<br />
</code><br />
You can modify it by echoing new value there:<br />
<code><br />
# echo 131072 &gt; /proc/sys/net/ipv4/netfilter/ip_conntrack_max<br />
# cat /proc/sys/net/ipv4/netfilter/ip_conntrack_max<br />
131072<br />
</code><br />
Changes are immediate, but temporary &#8211; will not survive reboot.</p>
<p><strong>Modifying number of buckets in the hash table</strong><br />
As mentioned above just changing this parameter will give you some relief, if your server was at the cap, but it is not ideal setup. For 1M connections average list becomes 1048576 / 8192 = 128, which is a bit too much.</p>
<p>To see current size of hash table:<br />
<code><br />
cat /proc/sys/net/ipv4/netfilter/ip_conntrack_buckets<br />
</code><br />
which is read-only aliase for module parameter:<br />
<code><br />
cat /sys/module/ip_conntrack/parameters/hashsize<br />
</code><br />
You can change it on the fly as well:<br />
<code><br />
#echo 32768 &gt; /sys/module/ip_conntrack/parameters/hashsize<br />
# cat /sys/module/ip_conntrack/parameters/hashsize<br />
32768<br />
</code></p>
<p><strong>Persisting the changes</strong><br />
Making these changes persistent is a bit tricky.<br />
For total number of connection just edit <code>/etc/sysctl.conf</code> (CentOs, Redhat etc) and you are done:<br />
<code><br />
# conntrack limits<br />
net.ipv4.netfilter.ip_conntrack_max = 131072<br />
</code></p>
<p>Not so easy with hashtable size. You need to pass parameters to kerenl module at boot time. Edit add to <code>/etc/modprobe.conf</code>:<br />
<code><br />
options ip_conntrack hashsize=32768<br />
</code> </p>
<p><strong>Memory usage</strong><br />
You can find how much kernel memory each conntrack entry occupies by grepping /var/log/messages :<br />
<code><br />
ip_conntrack version 2.4 (8192 buckets, 65536 max) - 304 bytes per conntrack<br />
</code><br />
1M connections would require 304MB of kernel memory.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timanovsky.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timanovsky.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timanovsky.wordpress.com&#038;blog=5831516&#038;post=117&#038;subd=timanovsky&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timanovsky.wordpress.com/2009/04/10/tuning-linux-firewall-connection-tracker-ip_conntrack/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/14d4d2c02acf61f5532588e30de4bf23?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">timanovsky</media:title>
		</media:content>
	</item>
	</channel>
</rss>
