<?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>Pushing the Web</title>
	<atom:link href="http://pushingtheweb.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://pushingtheweb.com</link>
	<description>With innovation and real-time technology</description>
	<lastBuildDate>Thu, 09 Feb 2012 09:16:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Three projects to boost your Python performance</title>
		<link>http://pushingtheweb.com/2012/02/three-projects-to-boost-your-python-performance/</link>
		<comments>http://pushingtheweb.com/2012/02/three-projects-to-boost-your-python-performance/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 13:02:00 +0000</pubDate>
		<dc:creator>Jonas Tärnström</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://pushingtheweb.com/?p=247</guid>
		<description><![CDATA[As mentioned before we at ESN use Python for most things we do as well as the backbone language for our real-time web development framework Planet. Let&#8217;s face it, performance matters. If you can do more with less hardware your web site will cost less to operate. This translates into decreased operating costs and if [...]]]></description>
			<content:encoded><![CDATA[<p>As mentioned before we at <a href="http://www.esn.me">ESN </a>use Python for most things we do as well as the backbone language for our real-time web development framework <a href="http://www.esn.me/product/planet/">Planet</a>.</p>
<p>Let&#8217;s face it, performance matters. If you can do more with less hardware your web site will cost less to operate. This translates into decreased operating costs and if it&#8217;s in your interest also increased profits.</p>
<p>Our hunt for increased performance sent us down the path of developing a couple of Python extensions which we&#8217;ve made available on github, licensed under the permissive BSD license. We suffix the project names with &#8220;ultra&#8221; to denote their family heritage as being closely bound to performance or ultimate if you so will.</p>
<p>Though compatible with any CPython flavour we especially prefer enjoying the increased performance using the well engineered <a href="http://www.gevent.org">gevent project</a> and socket monkey patching.</p>
<p>So what have we done?</p>
<h4>UltraJSON:</h4>
<p>Fully JSON standard complaint encoder and decoder with <a href="https://github.com/esnme/ultrajson/blob/master/README">unsurpassed performance</a> written entirely in C. Visit <a href="http://github.com/esnme/ultrajson">github </a>or <a href="http://pypi.python.org/pypi/ujson">pypi</a>.</p>
<h4>UltraMySQL:</h4>
<p>MySQL client written entirley in C/C++. Visit <a href="http://github.com/esnme/ultramysql">github </a>or <a href="http://pypi.python.org/pypi/umysql">pypi</a>.</p>
<h4>UltraMemcache:</h4>
<p>Memcache Client written entirley in C/C++. Visit <a href="http://github.com/esnme/ultramemcache">github </a>or <a href="http://pypi.python.org/pypi/umemcache">pypi</a>.</p>
<h4>What kind of performance boost can I expect?</h4>
<p>Short answer, it depends. We experienced a 15-35% increase in web requests per second when phasing out <a href="https://github.com/simplejson/simplejson">simplejson</a>, <a href="https://github.com/mthurlin/gevent-MySQL">gevent-mysql</a> and <a href="https://github.com/hjlarsson/gevent-memcache">gevent-memcache</a>. Worth mentioning is that all of the modules we phased out have bits and pieces of native compiled code. You may get more, you may get less but considering that compiled native code usually is 2-5 times faster than Python code you will always decrease your effective CPU usage.</p>
]]></content:encoded>
			<wfw:commentRss>http://pushingtheweb.com/2012/02/three-projects-to-boost-your-python-performance/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A faster MySQL driver for Python and gevent</title>
		<link>http://pushingtheweb.com/2011/05/a-faster-mysql-driver-for-python-and-gevent/</link>
		<comments>http://pushingtheweb.com/2011/05/a-faster-mysql-driver-for-python-and-gevent/#comments</comments>
		<pubDate>Tue, 31 May 2011 08:59:14 +0000</pubDate>
		<dc:creator>Jonas Tärnström</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://pushingtheweb.com/?p=222</guid>
		<description><![CDATA[During the later development and optimization phases of our real-time web framework PLANET we at ESN began looking more at the possibility of doing spot on C/C++ optimizations of our Python code. Not being the typical Python hacker of ESN I was asked to put together a proof of concept MySQL driver for Python written [...]]]></description>
			<content:encoded><![CDATA[<p>During the later development and optimization phases of our real-time web framework <a href="http://www.esn.me/product/planet/" target="_blank">PLANET</a> we at ESN began looking more at the possibility of doing spot on C/C++ optimizations of our Python code. Not being the typical Python hacker of <a href="http://www.esn.me" target="_blank">ESN</a> I was asked to put together a proof of concept MySQL driver for Python written in pure C/C++.</p>
<p>Lucky for me I didn&#8217;t have to start from scratch, the <a href="https://github.com/mthurlin/gevent-MySQL" target="_blank">gevent port</a> of the Concurrence project already had done most of the research of the protocol and their source code acted as the perfect blue print. My work would become more of porting Python and Pyrex to C/C++ while adding my own touch for low level optimizations.</p>
<h2>Integration code and the base driver</h2>
<p>The base driver and the language specific integration code exchange a set of function pointers which allows the base driver to call into the integration code. The integration code is responsible for creating sockets, handling blocking I/O, result sets, character set conversions and type conversions. The base drivers deals with the MySQL protocol and may I say in a very performant matter <img src='http://pushingtheweb.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Not only for gevent and Python!</h2>
<p>While the emphasis has been on creating a Python driver for gevent I&#8217;m also shipping integration code for &#8220;normal&#8221; blocking Python called simply CPython. Beyond that there&#8217;s nothing that will stop anyone from developing bindings to other languages like Ruby for instance. I&#8217;m looking very much forward to seeing that happening!</p>
<h2>Fibers, threads or greenlets</h2>
<p>Depending on which approach the I/O specific integration code takes it&#8217;s possible to adapt the base driver to any type offiber, thread or greenlet enviorment provided that they either switch back to the operating system upon blocking for I/O or yield to another user space thread (like fibers and greenlets) and while doing so preserves the stack.</p>
<h2>Performance benchmarks</h2>
<p>I&#8217;ll publish more detailed statistics later on but my initial benchmarks showed a <em><strong>3-8 times performance gain</strong></em> over using the gevent-mysql driver. Until I find the time for putting up better benchmarks you&#8217;re just gonna have to take my word for it or feel free to <a href="https://github.com/esnme/ultramysql">contribute</a> your own results!<br />
<span style="font-size: 13px; font-weight: normal;">Check out the project on <a href="https://github.com/esnme/ultramysql">github here</a>!</span></p>
]]></content:encoded>
			<wfw:commentRss>http://pushingtheweb.com/2011/05/a-faster-mysql-driver-for-python-and-gevent/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ultra fast JSON encoder and decoder for Python</title>
		<link>http://pushingtheweb.com/2011/03/ultra-fast-json-encoding-decoding-python/</link>
		<comments>http://pushingtheweb.com/2011/03/ultra-fast-json-encoding-decoding-python/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 19:40:23 +0000</pubDate>
		<dc:creator>Jonas Tärnström</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://pushingtheweb.com/?p=187</guid>
		<description><![CDATA[We do a lot of JSON encoding and decoding here at ESN. Python 2.6 ships with an accurate but rather slow implementation which we&#8217;ve switched for simplejson. There&#8217;s a lot of stuff going on with JavaScript and JSON today and I thought maybe this was a place where my good old C optimization skills could [...]]]></description>
			<content:encoded><![CDATA[<p>We do a lot of JSON encoding and decoding here at ESN. Python 2.6 ships with an accurate but rather slow implementation which we&#8217;ve switched for simplejson. There&#8217;s a lot of stuff going on with JavaScript and JSON today and I thought maybe this was a place where my good old C optimization skills could be of good use. To be honest I also wanted to prove that I still had the skills</p>
<h2>UltraJSON</h2>
<p>Not being able to stay out of this mess I spent a weekend researching the quickest and (perhaps) also the dirtiest way of  encoding and decoding JSON. I call the result UltraJSON and it&#8217;s by my preliminary and perhaps somewhat limited benchmarks the fastest JSON encoder and decoder I&#8217;ve found so far (and if it&#8217;s not I&#8217;m gonna make it faster!).</p>
<h2>Python bindings</h2>
<h2><span style="font-size: 13px; font-weight: normal;">Neither the decoder nor the encoder part of UltraJSON is specific to any language. It can be integrated with most anything and since I wanted my colleges to use it I implemented Python bindings for it as the module &#8216;ujson&#8217;. </span></h2>
<p><span style="font-size: 13px; font-weight: normal;"><strong>UPDATE:</strong> UltraJSON is now available on <a href="http://pypi.python.org/pypi/ujson/">PyPI</a> package <em>ujson</em>. Installation should be simple through easy_install or pip! </span></p>
<h2>Current benchmarks:</h2>
<pre>
<pre>64-bit benchmarks Linux
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)
OS Version: Ubuntu 10.10
System Type: x64-based PC
Processor: Intel(R) Core(TM) i5-2300 CPU @ 2.80GHz
Total Physical Memory: 4096 MB

Array with 256 utf-8 strings:
ujson encode      : 2874.54652 calls/sec
simplejson encode : 1539.47999 calls/sec
cjson encode      : 132.33571 calls/sec

ujson decode      : 2072.09417 calls/sec
cjson decode      : 991.20903 calls/sec
simplejson decode : 310.75309 calls/sec

Medium complex object:
ujson encode      : 19001.01929 calls/sec
simplejson encode : 3512.29205 calls/sec
cjson encode      : 3063.69959 calls/sec

ujson decode      : 12791.80993 calls/sec
cjson decode      : 8288.32916 calls/sec
simplejson decode : 6640.22169 calls/sec

Array with 256 strings:
ujson encode      : 40161.78453 calls/sec
simplejson encode : 19301.40779 calls/sec
cjson encode      : 12337.13166 calls/sec

ujson decode      : 36944.81317 calls/sec
cjson decode      : 30187.40167 calls/sec
simplejson decode : 25105.56562 calls/sec

Array with 256 doubles:
ujson encode      : 6054.71950 calls/sec
simplejson encode : 2912.44353 calls/sec
cjson encode      : 3539.51228 calls/sec

ujson decode      : 27794.29735 calls/sec
cjson decode      : 14892.38775 calls/sec
simplejson decode : 14879.00070 calls/sec

Array with 256 True values:
ujson encode      : 168086.95325 calls/sec
simplejson encode : 49348.93309 calls/sec
cjson encode      : 67392.90623 calls/sec

ujson decode      : 139359.25968 calls/sec
cjson decode      : 82552.26652 calls/sec
simplejson decode : 114998.51396 calls/sec

Array with 256 dict{string, int} pairs:
ujson encode      : 24125.68837 calls/sec
simplejson encode : 5751.74871 calls/sec
cjson encode      : 4735.65147 calls/sec

ujson decode      : 17176.70493 calls/sec
cjson decode      : 13420.93963 calls/sec
simplejson decode : 9854.27352 calls/sec

Dict with 256 arrays with 256 dict{string, int} pairs:
ujson encode      : 86.52449 calls/sec
simplejson encode : 17.46117 calls/sec
cjson encode      : 18.31323 calls/sec

ujson decode      : 49.54660 calls/sec
cjson decode      : 38.34094 calls/sec
simplejson decode : 28.18035 calls/sec</pre>
</pre>
<h2>More on GitHub!</h2>
<p>I&#8217;d love to see more people using and contributing to this project, so please check out my <a title="GitHub repository" href="https://github.com/esnme/ultrajson">GitHub repository</a>!</p>
<p>Bindings to more languages would be awesome!</p>
]]></content:encoded>
			<wfw:commentRss>http://pushingtheweb.com/2011/03/ultra-fast-json-encoding-decoding-python/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Reaching out of the browser sandbox using jQuery Title Alert</title>
		<link>http://pushingtheweb.com/2010/10/reaching-out-of-the-browser-sandbox-using-jquery-title-alert/</link>
		<comments>http://pushingtheweb.com/2010/10/reaching-out-of-the-browser-sandbox-using-jquery-title-alert/#comments</comments>
		<pubDate>Fri, 15 Oct 2010 13:02:14 +0000</pubDate>
		<dc:creator>Jonatan Heyman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://pushingtheweb.com/?p=121</guid>
		<description><![CDATA[Most websites that we develop at ESN are social websites with real-time features. Features that are in real-time on these websites might be contact lists with chat features, counter-strike game lobbies, social activity feeds, and so on. Having these features in real-time really enhances the over all functionality of the websites, especially together with some [...]]]></description>
			<content:encoded><![CDATA[<p>Most websites that we develop at <a href="http://esn.me">ESN</a> are social websites with real-time features. Features that are in real-time on these websites might be contact lists with chat features, counter-strike game lobbies, social activity feeds, and so on. Having these features in real-time really enhances the over all functionality of the websites, especially together with some ways of making users aware of the updates, like animations and toasters. </p>
<p>These websites &#8211; as well as many others on the net like Facebook, Twitter, Gmail, Last.fm (the list goes on forever) &#8211; are more and more taking the role that was previously hold by normal applications like Thunderbird, Emacs, Skype, etc. When using such web application, it&#8217;s normal user behavior to multitask between different web pages and programs, just like one would do using a normal application, like Skype. However, OS level programs have ways to alert the user when certain events occur (i.e. someone sends you a message), that web application is some what lacking, because they live in the browser sandbox. This is a problem, because the usefulness of having a user-to-user chat in real-time, decreases a great deal, if one has to manually go and check for new messages while having another website, or another program, focused. One solution to this is to show notification messages in the browser&#8217;s title bar. </p>
<p>That&#8217;s why I wrote <a href="http://heyman.info/2010/sep/30/jquery-title-alert/">jQuery Title Alert</a> about a year ago. It&#8217;s a small <a href="http://jquery.org">jQuery</a> plugin for displaying a flashing notification message in the browser&#8217;s title bar. It supports setting different intervals and timings, that defines the appearance of the notification, as well as options for stopping the title notification when the browser get focus. </p>
<p>Hopefully someone will find the plugin very useful as a complement to a website that uses a <a href="http://beaconpush.com/">real-time service</a> like <a href="http://beaconpush.com/">BeaconPush</a>.</p>
<h2>Try it!</h2>
<p>Here is an example on how to use it:<br />
(See the <a href="http://heyman.info/2010/sep/30/jquery-title-alert/#documentation">documentation</a> for all available options)</p>
<pre style="background:#f3faff; border:1px solid #aaccef; padding:5px; font-family:courier new">
$.titleAlert("New chat message!", {
    stopOnFocus:true,
    duration:60000,
    interval:500
});
</pre>
<p><script type="text/javascript" src="http://github.com/heyman/jquery-titlealert/raw/master/jquery.titlealert.js"></script></p>
<input type="button" value="Run it!" onclick="jQuery.titleAlert('New chat message!', {stopOnFocus:true, duration:60000, interval:500});" />
<h2 style="margin-top:20px;">Get it!</h2>
<p>Go ahead and grab it in my <a href="http://heyman.info/2010/sep/30/jquery-title-alert/">original blog post</a>, or at the <a href="http://github.com/heyman/jquery-titlealert">project GitHub page</a>. And feel free to fork it as much as you want!</p>
]]></content:encoded>
			<wfw:commentRss>http://pushingtheweb.com/2010/10/reaching-out-of-the-browser-sandbox-using-jquery-title-alert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Endless scroller jQuery plugin</title>
		<link>http://pushingtheweb.com/2010/09/endless-scroller-jquery-plugin/</link>
		<comments>http://pushingtheweb.com/2010/09/endless-scroller-jquery-plugin/#comments</comments>
		<pubDate>Wed, 15 Sep 2010 14:13:57 +0000</pubDate>
		<dc:creator>Micael Sjölund</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://pushingtheweb.com/?p=109</guid>
		<description><![CDATA[In a recent web project, I needed to build an automatic pagination for end-users, which automatically fetches more content when the user scrolls the page. Examples of this are the Facebook log and the shoe browsing on http://www.mirapodo.de/herrenschuhe/ (not affiliated with us). When the user gets to the end of the page, it fetches more content. [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent web project, I needed to build an automatic pagination for end-users, which automatically fetches more content when the user scrolls the page. Examples of this are the Facebook log and the shoe browsing on <a title="http://www.mirapodo.de/herrenschuhe/" href="http://www.mirapodo.de/herrenschuhe/">http://www.mirapodo.de/herrenschuhe/</a> (not affiliated with us). When the user gets to the end of the page, it fetches more content. This way, you don&#8217;t have to load more than neccesary on the first page load, and the user benefits, since she doesn&#8217;t have to click numbers in a pagination widget. The result is the jquery.esn.autobrowse.js jQuery plugin which does that for any page.</p>
<p>It loads JSON data from the server, and renders it client-side. One of the problems with a typical auto-pagination is that when the user clicks on a link in the content, and then clicks &#8220;back&#8221; in the browser, he or she ends up at the top of the page and have to scroll all the way down again (even Facebook suffers from this problem at the time of writing this 2010). In this plugin, you can choose to use the browser local storage to cache the content fetched, and it keeps track on how far you have scrolled on the page. This means that if the user clicks a link and then goes back, she will see what she left.</p>
<p>The browser cache is accomplished using the <a href="http://www.jstorage.info/">jStorage</a> plugin (slightly modified for this autobrowse plugin). It presents a cross-browser interface for saving arbitrary data in the browser storage. The storage methods are different in different browsers however, so for instance IE doesn&#8217;t have as much storage space as Chrome or Firefox. The cache does fallback on an ajax request if the storage failed. The modified version of jStorage notifies the autobrowse plugin when the storage failed (i.e. when the data didn&#8217;t fit into the space available).</p>
<div id="_mcePaste">Try the <a href="http://msjolund.github.com/autobrowse/">demo</a> and <a href="http://github.com/msjolund/jquery-esn-autobrowse">download</a>. Report bugs or feature requests to <a href="http://github.com/msjolund">me on GitHub</a> or simply fork it!</div>
]]></content:encoded>
			<wfw:commentRss>http://pushingtheweb.com/2010/09/endless-scroller-jquery-plugin/feed/</wfw:commentRss>
		<slash:comments>48</slash:comments>
		</item>
		<item>
		<title>Python memory management and TCMalloc</title>
		<link>http://pushingtheweb.com/2010/06/python-and-tcmalloc/</link>
		<comments>http://pushingtheweb.com/2010/06/python-and-tcmalloc/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 11:37:00 +0000</pubDate>
		<dc:creator>Marcus Nilsson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://pushingtheweb.com/?p=70</guid>
		<description><![CDATA[At ESN, we have recently experienced problems with Python not giving back memory to the OS in Linux. It reuses allocated memory internally, but never releases free memory back to the OS. This causes problems with monitoring, as it becomes difficult to see trends or temporary memory usage spikes. At first we thought we had [...]]]></description>
			<content:encoded><![CDATA[<p>At <a href="http://www.esn.me">ESN</a>, we have recently experienced problems with Python not giving back memory to the OS in Linux. It reuses allocated memory internally, but never releases free memory back to the OS. This causes problems with monitoring, as it becomes difficult to see trends or temporary memory usage spikes. At first we thought we had a Python memory leak on our hands. Others seem to have similar problems, for example there is a <a href="http://stackoverflow.com/questions/1194416/python-memory-footprint-vs-heap-size">Stack Overflow</a> entry about it. We investigated this problem and solved it using TCMalloc, a malloc replacement part of <a href="http://goog-perftools.sourceforge.net/">Google Performance Tools</a>, and some appropriate tuning. This post details the results of our investigation and our solution.</p>
<p>Pythons default memory management is based on two basic techniques:</p>
<ul>
<li>Using malloc, on Linux-systems usually the GLIBC version, to allocate memory from the OS.</li>
<li>A custom memory allocator for small objects, to reduce the number of malloc calls.</li>
</ul>
<p>To understand why Python does not give back memory to the OS, we have to dig into how GLIBC&#8217;s malloc works and in particular how Linux memory management works.</p>
<p>In Linux, there are two ways to allocate memory:</p>
<ul>
<li>Through the <strong>brk()/sbrk()</strong><strong> </strong>syscalls. These are used to increase or decrease a continuous amount of memory allocated to the process. It is always provided as a continuous chunk, so you can only free memory at the end of the allocated memory, you cannot have &#8220;holes&#8221;.</li>
<li>Through the <strong>mmap()</strong> syscall. With mmap, you can allocate an arbitrary size of memory and map it wherever you like in the virtual address space of the process. You can also release memory allocated by mmap using <strong>munmap()</strong>, meaning you can have &#8220;holes&#8221; in your allocated memory. In many respects, allocating memory through mmap() is similar and as flexible as using malloc. There is, however, a performance penalty for using mmap. The reason is that the OS, to be POSIX compliant, has to zero the memory before giving it to the process. Because of this, mmap is traditionally only used for larger allocations that are not so frequent.</li>
</ul>
<p style="text-align: left;">The picture below shows the virtual address space of a process. The first segment, marked as <strong>brk</strong>, is the memory allocated using brk()/sbrk() calls. The end of the brk segment is called the <strong>breakpoint</strong> of the process (which is the reason for the syscall names). Using sbrk()/brk(), it is possible to move this breakpoint. With mmap() you can place arbitrary chunks of memory into the address space.</p>
<p style="text-align: left;"><a href="http://pushingtheweb.com/wp-content/uploads/2010/06/unixmem5.png"><img class="aligncenter size-full wp-image-92" title="Unix memory model" src="http://pushingtheweb.com/wp-content/uploads/2010/06/unixmem5.png" alt="Describes how Unix uses brk() and mmap" width="480" height="148" /></a></p>
<p>GLIBC&#8217;s malloc uses both brk and mmap. It uses brk for small  allocations (on 64-bit the default is lower than 64MB, but this  threshold is dynamically adjusted and can be tuned, explained in a <a href="http://sourceware.org/ml/libc-alpha/2006-03/msg00033.html">message  from libc mailing list</a>) and mmap for larger allocations.  Allocations inside the memory allocated by brk is managed by malloc  internally, potentially leading to fragmentation.</p>
<p>The problem arises when many allocations occur followed by almost all memory being freed. If the memory that is still allocated is high up in the brk segment, malloc will not be able to release the memory to the OS. Typical scenarios is when you have a long memory-consuming computation, and store the result. The result is then likely to be in the upper part of the brk segment.</p>
<p>While malloc can be tuned to use mmap at lower thresholds, it does not have the ability to manage smaller allocations inside a block allocated using mmap. Python&#8217;s own allocator for small objects can help, but it does not use it for all objects.</p>
<p>Our solution was to use TCMalloc, a malloc replacement part of  <a href="http://goog-perftools.sourceforge.net/">Google Performance  Tools</a>. TCMalloc can be tuned to only use mmap, and uses a delay before releasing memory to the OS, reducing the number of OS calls for applications using malloc frequently.</p>
<p>We compiled a version of Python with TCMalloc that only uses mmap. When testing the new Python in one of our largest projects, we found that not only did Python give back memory to the OS correctly, it also had a reduced memory usage and no apparent CPU penalty for using mmap instead of brk.</p>
<p><a href="http://www.esn.me">Planet</a>, our development platform for the social real-time web,  now ships with Python using TCMalloc as standard.</p>
]]></content:encoded>
			<wfw:commentRss>http://pushingtheweb.com/2010/06/python-and-tcmalloc/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Debugging NPAPI plugins in Visual Studio</title>
		<link>http://pushingtheweb.com/2010/06/debugging-npapi-plugins-in-visual-studio/</link>
		<comments>http://pushingtheweb.com/2010/06/debugging-npapi-plugins-in-visual-studio/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 15:39:11 +0000</pubDate>
		<dc:creator>Jonas Tärnström</dc:creator>
				<category><![CDATA[Open-source]]></category>

		<guid isPermaLink="false">http://pushingtheweb.com/?p=61</guid>
		<description><![CDATA[A follow up to my last post about a sample boilerplate plugin for NPAPI I&#8217;d like to give some advice on how to debug NPAPI plugins in Mozilla Firefox in Visual Studio 2008 (or similar). Disable Mozilla Crash reporting In order to debug your plugin you must first make sure that Mozilla Firefox doesn&#8217;t try to [...]]]></description>
			<content:encoded><![CDATA[<p>A follow up to my last post about a sample boilerplate plugin for NPAPI I&#8217;d like to give some advice on how to debug NPAPI plugins in Mozilla Firefox in Visual Studio 2008 (or similar).</p>
<h3>Disable Mozilla Crash reporting</h3>
<p>In order to debug your plugin you must first make sure that Mozilla Firefox doesn&#8217;t try to handle crashes and exceptions on it&#8217;s own. The easiest way of doing this is to set a System environment variable (<em>Control panel-&gt;System-&gt;Advanced-&gt;Environment Variables</em>). Name the variable <em>MOZ_CRASHREPORTER_DISABLE </em>and set it&#8217;s value to &#8220;1&#8243; (without the quotes of course).  Restart most things after this, or at least Visual Studio and any running Firefox instances.</p>
<h3>Making sure Mozilla loads the right plugin</h3>
<ol>
<li>Start Visual Studio and open your project. Make note of the full path to the plugin DLL your project builds.</li>
<li>Start regedit and change the &#8220;path&#8221; value for your plugin&#8217;s registry entry to the full path of your plugin DLL. Take a look at the <a href="http://github.com/jskorpan/BoilerplateNp/blob/master/win32/plugininstall.reg">registry patch</a> found in the <a href="http://github.com/jskorpan/BoilerplateNp">boilerplate projec</a>t for further reference.</li>
<li>Create a HTML test file which instances your plugin using the &lt;embed&gt; or &lt;object&gt; tag. You can use <a href="http://github.com/jskorpan/BoilerplateNp/blob/master/test/test.html">mine</a> as a reference.</li>
<li>Open <em>Project properties</em> (ALT+F7) for your plugin project.</li>
<li>Go to the <em>Debugging.</em></li>
<li>As<em> Command</em>, browse to the location of firefox.exe</li>
<li>As <em>Command Arguments</em>, enter the URL to your test file written as an URL (like <em>file:///c:/mydir/myfile.html</em>)</li>
<li>Save/Apply the changes.</li>
<li>Set a breakpoint early in the program, preferably in some of the boilerplate like the NP_Initialize function. This is just to make sure everything works out.</li>
<li>Start debugging (press F5). If the breakpoint we set out trips it means everything works out.</li>
</ol>
<h3>Troubleshooting the debugging</h3>
<p>The most common problem is that Firefox for some reason loads another plugin DLL or not the one matching your PDB files. Make sure everything in step 2 checks out.</p>
<p>Happy debugging!</p>
]]></content:encoded>
			<wfw:commentRss>http://pushingtheweb.com/2010/06/debugging-npapi-plugins-in-visual-studio/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Think twice before &#8220;helping&#8221; your visitors</title>
		<link>http://pushingtheweb.com/2010/06/think-twice-before-helping-your-visitors/</link>
		<comments>http://pushingtheweb.com/2010/06/think-twice-before-helping-your-visitors/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 14:38:34 +0000</pubDate>
		<dc:creator>Markus Thurlin</dc:creator>
				<category><![CDATA[User Experience]]></category>

		<guid isPermaLink="false">http://pushingtheweb.com/?p=52</guid>
		<description><![CDATA[The website of SEB, a major bank in Sweden, has a lot of annoying design choices. Nevermind the frames, as I&#8217;m sure they have lots of enterprisy technical reasons to use them in the year 2010.  Nevermind selectboxes with &#8220;go&#8221;-buttons, instead of plain links. The top most annoying thing is that when logging in, they [...]]]></description>
			<content:encoded><![CDATA[<p>The website of <a href="http://www.seb.se" target="_blank">SEB</a>, a major bank in Sweden, has a lot of annoying design choices.</p>
<p>Nevermind the frames, as I&#8217;m sure they have lots of enterprisy technical reasons to use them in the year 2010.  Nevermind selectboxes with &#8220;go&#8221;-buttons, instead of plain links.</p>
<p>The top most annoying thing is that when logging in, they have decided to &#8220;help&#8221; you press TAB.</p>
<div class="mceTemp">
<dl id="attachment_53" class="wp-caption alignnone" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://pushingtheweb.com/wp-content/uploads/2010/06/seb.png"><img class="size-medium wp-image-53" title="SEB" src="http://pushingtheweb.com/wp-content/uploads/2010/06/seb-300x79.png" alt="Login screen of SEB" width="300" height="79" /></a></dt>
</dl>
</div>
<p>After typing in my 10 digit ID-number, SEB has decided to help me set the focus to the next inputbox.</p>
<p>So, every single time I try to login, I forget that they are &#8220;helping&#8221; me and I press TAB after completing the first inputbox.</p>
<p>This is the way all other sites and desktop apps work. But, at SEB, this of course makes the login button get focus instead (since focus has shifted to the second input by the time I press TAB).</p>
<p>The intent is good, but the result is horrible. Instead of trying to come up with clever ideas like this, make sure your website follows current UI standards. That&#8217;s the best help your visitors can get.</p>
]]></content:encoded>
			<wfw:commentRss>http://pushingtheweb.com/2010/06/think-twice-before-helping-your-visitors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Useful tools for JBoss Netty</title>
		<link>http://pushingtheweb.com/2010/06/useful-tools-for-jboss-netty/</link>
		<comments>http://pushingtheweb.com/2010/06/useful-tools-for-jboss-netty/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 07:44:44 +0000</pubDate>
		<dc:creator>Carl Byström</dc:creator>
				<category><![CDATA[Open-source]]></category>

		<guid isPermaLink="false">http://pushingtheweb.com/?p=30</guid>
		<description><![CDATA[At ESN, we&#8217;re avid users of the Java networking library, JBoss Netty. It sports a really well-designed API for working with non-blocking I/O and great performance! Written by Trustin Lee of the Apache MINA fame. Our real-time push server, Orbit, is written in Java and based on aforementioned library. Orbit is used both in our real-time Planet [...]]]></description>
			<content:encoded><![CDATA[<p>At <a href="http://www.esn.me">ESN</a>, we&#8217;re avid users of the Java networking library, <a href="http://www.jboss.org/netty">JBoss Netty</a>. It sports a really well-designed API for working with non-blocking I/O and great performance! Written by <a href="http://twitter.com/trustin">Trustin Lee</a> of the <a href="http://mina.apache.org/">Apache MINA</a> fame.</p>
<p>Our real-time push server, Orbit, is written in Java and based on aforementioned library. Orbit is used both in our real-time <a href="http://www.esn.me/product/">Planet framework</a> and in <a href="http://beaconpush.com">Beacon</a>, our cloud hosted push service. For supporting the latest in HTML 5 development it naturally supports both <a href="http://en.wikipedia.org/wiki/Comet_(programming)">Comet</a> and <a href="http://en.wikipedia.org/wiki/Web_Sockets">Web Sockets</a> as transport alternatives.</p>
<p>During the months of developing Orbit, a couple well-known standards and protocols was implemented. HTTP, <a href="http://en.wikipedia.org/wiki/Web_Sockets">Web Sockets</a> and <a href="http://en.wikipedia.org/wiki/Thrift_(protocol)">Thrift</a> being the most used. However, after finishing and stabilizing these it felt a bit immoral to keep this closed source. Especially since we use a lot of open-source software ourselves.</p>
<h2>Giving back</h2>
<p>Most of what could be re-used was extracted out of our real-time push server and <a href="http://github.com/cgbystrom/netty-tools">put up on GitHub</a>. Licensed under the liberal <a href="http://en.wikipedia.org/wiki/MIT_License">MIT license</a> and will hopefully come to good use.</p>
<p>Right now it features:</p>
<ul>
<li><strong>HTTP File Server</strong></li>
<li><strong></strong><strong>HTTP Cache</strong></li>
<li><strong>HTTP Router</strong></li>
<li><strong></strong><strong>Bandwidth meter</strong></li>
<li><strong>Asynchronous Web Socket client</strong></li>
<li><strong>Thrift processor</strong></li>
</ul>
<p>More details can be found in the <a href="http://github.com/cgbystrom/netty-tools">netty-tools repository</a> on <a href="http://github.com/">GitHub</a>.</p>
<p>Despite us trying to minimize the use of Java, we still use it for certain projects. The performance and tools available make it very hard to resist sometimes. However, we try limit the use of it to infrastructural projects with well defined responsibilities, such as back-end servers or IDE development.</p>
<p>Our goal of sharing and open-sourcing as much <a href="http://www.esn.me">ESN</a> technology as possible has started. Keep your eyes open for more!</p>
]]></content:encoded>
			<wfw:commentRss>http://pushingtheweb.com/2010/06/useful-tools-for-jboss-netty/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Boilerplate for a NPAPI plugin</title>
		<link>http://pushingtheweb.com/2010/06/boilerplate-for-a-npapi-plugin/</link>
		<comments>http://pushingtheweb.com/2010/06/boilerplate-for-a-npapi-plugin/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 10:56:53 +0000</pubDate>
		<dc:creator>Jonas Tärnström</dc:creator>
				<category><![CDATA[Open-source]]></category>

		<guid isPermaLink="false">http://pushingtheweb.com/?p=3</guid>
		<description><![CDATA[The world of NPAPI is strange and odd world kind of like a puzzle with the right answers spread all over the Internet. Getting started with a portable project can be quiet cumbersome and the browsers do very little and sometimes nothing to aid you with debugging and deployment. Therefore I&#8217;ve put together a sample [...]]]></description>
			<content:encoded><![CDATA[<p>The world of <a href="http://en.wikipedia.org/wiki/NPAPI">NPAPI</a> is strange and odd world kind of like a puzzle with the right answers spread all over the Internet. Getting started with a portable project can be quiet cumbersome and the browsers do very little and sometimes nothing to aid you with debugging and deployment.</p>
<p>Therefore I&#8217;ve put together a sample plugin with the boilerplate and everything necessary to build an (almost) empty  <a href="http://en.wikipedia.org/wiki/NPAPI">NPAPI</a> plugin for Windows and OS X. My hope is that this can get you going faster with less problems and frustrations. The plugin has been tested and should work with most browsers compatible with <a href="http://en.wikipedia.org/wiki/NPAPI">NPAPI</a>. These include Google Chrome, Firefox, Opera and Safari. I&#8217;ve created ready to use project files for <a href="http://en.wikipedia.org/wiki/Xcode">Xcode</a> (3.2) and <a href="http://en.wikipedia.org/wiki/Microsoft_Visual_Studio">Visual Studio</a> (2008). It&#8217;s probably possible (with little or no modification) to build this plugin on various Unix flavors such as Linux but I simply haven&#8217;t tried it. I&#8217;m not claiming that I know everything on this subject but I do know that this boilerplate is in it&#8217;s essence the same code as we have shipped to several satisfied customers of <a href="http://www.esn.me">ESN</a>.</p>
<p>Feel free to <a href="http://github.com/jskorpan/BoilerplateNp">fork the project on GitHub</a><a href="http://wiki.github.com/jskorpan/BoilerplateNp/">!</a></p>
<p><span id="more-3"></span></p>
<h2>What do I need to build?</h2>
<div id="_mcePaste">To build you need Xcode 3.2 if you want to target OS X and Visual Studio 2008 for targeting Windows. You also need a version of the <a href="https://developer.mozilla.org/en/Gecko_SDK">Gecko SDK</a> available from <a href="https://developer.mozilla.org/en/Gecko_SDK">Mozilla Developer Center (MDC)</a>. In order to be compatible with as many browsers as possible I choose the oldest Gecko SDK available which is version 1.8 (NPAPI major 0, minor 19). You can probably go ahead and try newer ones but beware that this is not tested with the included project files. Just download and extract the SDK on your harddrive.</div>
<h2>Setting up dependencies for Windows</h2>
<div id="_mcePaste">I&#8217;ve heard some rumor that the build fails if the NPAPI headers isn&#8217;t added before the Windows SDK headers. I&#8217;m not sure if this applies anymore and I didn&#8217;t bother to try.</div>
<h3>Directories to add to Include path:</h3>
<div id="_mcePaste"><em>&lt;GECKO SDK DIR&gt;\include\plugin</em></div>
<div id="_mcePaste"><em>&lt;GECKO SDK DIR&gt;\include\java</em></div>
<div id="_mcePaste"><em>&lt;GECKO SDK DIR&gt;\include\nspr</em></div>
<h3>Directories to add to Library path:</h3>
<div id="_mcePaste"><em>&lt;GECKO SDK DIR&gt;\lib</em></div>
<h2>Setting up dependencies for OS X</h2>
<div id="_mcePaste">If you haven&#8217;t figured it out by now I might as well admit it, I&#8217;m not that experienced with OSX.</div>
<div id="_mcePaste">If you want the project to work out of the box put the Gecko SDK in ~/Documents/sdk/. If you go mad from this prospect feel free to edit the project files.</div>
<h2>Plugins and dynamic linking</h2>
<div id="_mcePaste">On OSX they are called shared libraries (I think) and on Windows they are called dynamic linked libraries (DLLs). What ever they are called your Plugin will be compiled into one and dynamically loaded into the browser at runtime. This means that your problems are the browser&#8217;s problems. If you leak handles and resources the browser will also leak them. Take extra care to close down handles, free memory and for gods sake join up any dangling threads you&#8217;ve created before you shutdown!</div>
<h2>Asynchronous by nature</h2>
<div>NPAPI is single threaded by nature and though different browsers might separate a browser tab into a separate process all code written in an NPAPI plugin must be asynchronous and event driven. This means in plain English that if you block your code by sleeping, doing I/O or other waiting you will effectively block the browser and the user in front of the computer. Don&#8217;t make silly assumption about what time stuff takes when it comes to user experience. Threading, events and/or asynchronous I/O is the only sane way forward.</div>
<h2>Plugin methods exposed to the browser</h2>
<div id="_mcePaste">There are many more method the browser might call but here are the most important ones</div>
<h3>NPP_Initialize</h3>
<div id="_mcePaste">Called when your plugin module is first loaded. Here you can do global initialization stuff. Beware that this is not initialization of your plugin instance which is something else. The rule of thumb is that your module is usually just loaded once inside the browsers address space but you might have several plugin  instances running at the same time. Don&#8217;t use singletons unless you really want and know why.</div>
<h3>NPP_Shutdown</h3>
<div id="_mcePaste">Called when the browser is about to unload your module. Do global shutdown of stuff here.</div>
<h3>NPP_New</h3>
<div id="_mcePaste">Called when an instance of your plugin is to be created normally trough usage of the &lt;object&gt; or &lt;embed&gt; tag.</div>
<h3>NPP_Destroy</h3>
<div id="_mcePaste">Called when the browser destroys your instance. Usually when the web browser changes page.</div>
<h3>NPP_SetWindow</h3>
<div id="_mcePaste">Called when the browser has provided a NPWindow object for your plugin. A common problem (at least for me) was assuming that this function was called when it in fact had not been. Different browsers might call this function in different order from time to time. Don&#8217;t assume!</div>
<h3>NPP_GetValue</h3>
<div id="_mcePaste">Called for various reasons but usually for reading properties and exchanging the scriptable object needed for usage of the plugin from JavaScript.</div>
<h3>NPP_HandleEvent</h3>
<div id="_mcePaste">Only used in OSX. Called when event records related to the plugin are ready for processing.</div>
<h3>MIME description and naming</h3>
<div id="_mcePaste">A plugin is uniquely identified through a MIME type which you decide.</div>
<div id="_mcePaste">Be sure to do a proper search for “boilerplate” through code and resource files  and change it to something more suitable. I also recall that naming the plugin binary after it&#8217;s identification is a best practice or even a requirement in some browsers. Keep the casing the way I did it if you don&#8217;t want to get into trouble.</div>
<h2>Scriptable objects</h2>
<div id="_mcePaste">In order for a plugin to be accessible from JavaScript it must supply the browser with a Scriptable object. To object is represented as an NPObject which the browser will query you for through a call to the NPP_GetValue method, see npp_gate.cpp. The NPObject is at it&#8217;s core a struct with a bunch of function pointers the browser call for various reasons. The ScriptableObject class is simply a sanitized C++ way of dealing with it all.</div>
<div id="_mcePaste">When JavaScript tries to call a member function of the scriptable object it first calls the HasMethod function and if it returns true the invoke method is called. From there it&#8217;s all about serializing input and output parameters.</div>
<h2>Site locking in NPAPI</h2>
<div id="_mcePaste">Just as with Internet Explorer plugins (ActiveX) it&#8217;s possible to develop site locking for plugins which you intend to only be initialized from one specific website. There is no definite technique for doing this in NPAPI and I guess there are several ways of doing it. If you take a look at the NPP_New method in npp_gate.cpp you can see how I&#8217;ve chosen to do it and you can probably also remove the code if you don&#8217;t want any site locking at all.</div>
<h2>Installing the plugin on Windows</h2>
<div id="_mcePaste">There are more than one way of packaging and installing NPAPI plugins. You could use the browsers built in package system or create an installer of your own. It&#8217;s really up to you. I&#8217;ve included a registry patch for x64 Windows versions. To avoid explaining the registry virtualization used by 64-bit Windows I&#8217;ll just hint you that the 32-bit installers should write registry settings to <em>HKEY_LOCAL_MACHINE\SOFTWARE\\MozillaPlugins\</em> while 64-bit ones should write to <em>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MozillaPlugins\</em></div>
<h2>Installing the plugin on OS X</h2>
<div id="_mcePaste">Clean and simple, just copy the <em>./Debug/BoilerplatePlugin.bundle</em> to<em> /Library/Internet Plug-Ins</em> for system wide installation or <em>~Library/Internet Plug-ins</em> for local user installation .</div>
<div id="_mcePaste">Copying to <em>/Library</em> (of course) requires sudo privileges (or whatever it&#8217;s called on OS X)</div>
<h2>Downloading the project</h2>
<div id="_mcePaste">The code is <a href="http://github.com/jskorpan/BoilerplateNp">available on GitHub</a>. Feel free to contribute!</div>
]]></content:encoded>
			<wfw:commentRss>http://pushingtheweb.com/2010/06/boilerplate-for-a-npapi-plugin/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

