<?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>Brainwave Blog &#187; Prateek Sureka</title>
	<atom:link href="http://www.brainwavelive.com/blog/author/prateeksureka/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brainwavelive.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 11 Nov 2011 06:50:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Suggestion for removing the Python Global Interpreter Lock</title>
		<link>http://www.brainwavelive.com/blog/technology/suggestion-for-removing-the-python-global-interpreter-lock/</link>
		<comments>http://www.brainwavelive.com/blog/technology/suggestion-for-removing-the-python-global-interpreter-lock/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 05:15:58 +0000</pubDate>
		<dc:creator>Prateek Sureka</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.brainwavelive.com/wordpress/?p=32</guid>
		<description><![CDATA[This post is inspired by Guido van Rossum&#8217;s post on Python&#8217;s Global Interpreter Lock (GIL). There has been some recent buzz on efforts to remove the GIL in Python 3000 to enable real threading of applications in an effort take advantage of the trend towards multi-core systems.
This is a hard problem (as evidenced by Greg [...]]]></description>
			<content:encoded><![CDATA[<p>This post is inspired by <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=214235">Guido van Rossum&#8217;s post on Python&#8217;s Global Interpreter Lock (GIL)</a>. There has been some recent buzz on efforts to remove the GIL in Python 3000 to enable real threading of applications in an effort take advantage of the trend towards multi-core systems.</p>
<p>This is a hard problem (as evidenced by Greg Stein and Mark Hammond?&#8217;s efforts in 1999) mainly from a performance point of view. GvR himself has stated that although he doesn&#8217;t have the time to do it himself, he would be willing to accept any patches to CPython which removes the GIL (as a compile time option) which does not negatively affect performance of single threaded applications and significantly improves I/O bound multi-threaded apps.</p>
<p>As I learnt at PyCon 2007, the problems in general have to do with Python&#8217;s garbage collection mechanism which uses reference counting and hence requires synchronized access to objects to ensure that the increfs and decrefs are done properly. Additionally, the GIL protects various caches (notably the integer (and some other types?) free lists so that creating and destroying those items don&#8217;t take too much time because the PyObjects are recycled.</p>
<p>So far, the solutions discussed involve some type of fine grained locking around critical code sections. The problem here is that beyond two or three cores, this doesn&#8217;t scale well because of lock contention (since so much stuff needs to be synchronized).</p>
<p>Well, what if we tried a different approach&#8230; Locks don&#8217;t seem like they&#8217;re going to solve the problem in a scalable way and if we&#8217;re going to take the effort to do this, might as well do it so that the benefits scale in an environment of more than 100 cores (its possible &#8211; see Azul Systems).</p>
<p>What if we dedicated one core for running synchronized code? Naturally this can&#8217;t be done without support from the kernel (perhaps some sort of kernel module/VxD).</p>
<p>At process initialization time, the kernel dedicates a single core to be the &#8220;synchronization server&#8221; and provides an instruction queue for it. This can vary between processes. When the interpreter tries to acquire the GIL, the kernel simply does a context switch and queues the thread to the dedicated sync server. The thread is run normally by the sync server by popping it from the queue. When the GIL is released, another kernel call is made which simply switches the thread out from the sync server to a different core.</p>
<p>Since we are guaranteeing that synchronized code is running on a single core, it is the equivalent of a lock at the cost of a context switch. All other code can run in parallel on the remaining cores without problems. Moreover, this requires no changes to existing Python code or extension modules which acquire and release the GIL properly.</p>
<p>Obviously, the benefits from two cores will be negligible (possibly even negative because of the context switches and zero parallelism). However, every additional core you add will contribute to the parallelism of the process. Optimizing the context switches shouldn&#8217;t be too difficult because no memory pages are copied (no shared memory or IPC).</p>
<p>Limitations: The main limitation that I can foresee where scalability is limited by the sync server. The more code which needs to be synchronized, the greater the CPU usage on the sync core. Once that core is maxed out, the queue length may start increasing as the other cores wait around for the sync core. It looks to me that notwithstanding the cost of context switches this is at least as good as running everything on one core.</p>
<p>The core acting as sync server does not need to be special in any way. Neither does it need to be dedicated to the process alone. If the sync queue is empty (or even if its not), the kernel can always use the core for other processes like normal. The only guarantee we need from the kernel module is that the core will never be used for non-synchronized code within a process where it is designated as the sync server.</p>
<p>Does this make sense or am I crazy?</p>
<p>-Prateek Sureka</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brainwavelive.com/blog/technology/suggestion-for-removing-the-python-global-interpreter-lock/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pycon 2007 Lessons on Security and Parallelism</title>
		<link>http://www.brainwavelive.com/blog/pycon/pycon-2007-lessons-on-security-and-parallelism/</link>
		<comments>http://www.brainwavelive.com/blog/pycon/pycon-2007-lessons-on-security-and-parallelism/#comments</comments>
		<pubDate>Fri, 02 Mar 2007 18:03:15 +0000</pubDate>
		<dc:creator>Prateek Sureka</dc:creator>
				<category><![CDATA[Pycon]]></category>

		<guid isPermaLink="false">http://www.brainwavelive.com/wordpress/?p=25</guid>
		<description><![CDATA[Pycon 2007 was a great experience. I got to meet Guido and heard him speak on Python 3000 which I thought was quite illuminating.
One key point I took away is that there is a big difference between the language and its implementation. Currently, the implementation of choice is CPython but there are many promising new [...]]]></description>
			<content:encoded><![CDATA[<p>Pycon 2007 was a great experience. I got to meet Guido and heard him speak on Python 3000 which I thought was quite illuminating.</p>
<p>One key point I took away is that there is a big difference between the language and its <a href="http://www.python.org/dev/implementations.html">implementation</a>. Currently, the implementation of choice is CPython but there are many promising new projects like IronPython, PyPy and Jython (to which I am now a contributor) which hope to bridge the gap between Python and various other languages and fix some of the commonly raised complaints with the CPython implementation.</p>
<p>This is particularly relevant to Brainwave. Although we don&#8217;t expect to move to a different implementation anytime soon, there are some key areas which generated a lot of buzz in terms of lectures, open space talks and BoF sessions. The ones I&#8217;m specifically interested in today are 1) Security and 2) Parallelism</p>
<p>Python is an extremely introspective language. The dir() and eval() functions give you a lot of power to work with objects in ways the original creators never intended. This is a double edged sword. The problem is implementing security at the object level. The deep introspective nature of Python seems to be better suited to a capabilities based approach as opposed to a pure permissions model. <a href="http://sayspy.blogspot.com/">Brett Cannon</a> and I discussed a lot of options &#8211; running multiple instances of the interpreter as separate sandboxes in the same process space (not possible because of the way the CPython implementation caches object references) to adding keywords to the language (doesn&#8217;t seem like a good idea to change the language to serve the implementation). Brett is working on an <a href="http://us.pycon.org/common/talkdata/PyCon2007/062/PyCon_2007.pdf">interesting project</a> to run a separate interpreter process in secure mode (very much like the old rexec solution, which, according to Brett, was dropped because of the number of bugs it caused in the implementation).</p>
<p>At any rate, you can always drop into C to get around all these obstacles (obviously not very pythonic!). It does mean that newcomers and enterprise developers will have a harder time getting to grips with some of these nuances. (Note: The IronPython and Jython teams get around this issue by leaving the security to the underlying VM &#8211; just like CPython).</p>
<p>Parallelism was another hot topic of discussion. .. and the guys at <a href="http://ipython.scipy.org/">IPython</a> are doing some really <a href="http://us.pycon.org/common/talkdata/PyCon2007/061/ipython1_pycon_2007.pdf">interesting things</a>. The fundamental problem is with CPython&#8217;s global interpreter lock. Any thread in CPython needs access to the interpreter to run which requires acquiring a global lock. Hence, true parallelism cannot be achieved. It isn&#8217;t possible to eliminate the GIL because of the way CPython does garbage collection (reference counting). If<br />
multiple threads had simultaneous access to the same objects, it would be pretty hard to track references across them. Stackless python (which is the first thing most people mention when this topic arises) solves the problem with concurrency but does nothing for true parallelism.<br />
IronPython and Jython do not have a GIL because they once again use the underlying VM&#8217;s threading and GC models to implement true parallelism.</p>
<p>One good solution is once again to use multiple processes and either share objects between them (a la the <a href="http://poshmodule.sourceforge.net/">POSH project</a>) or do some form of RMI (<a href="http://pyro.sourceforge.net/">Pyro</a>, MPI4Py, PyMPI etc.)</p>
<p>Brainwave is currently using some of these workarounds. We have a capabilities based security model at the meme level. Each database query also carries with it information regarding the user context (i.e. who is logged in &#8211; effectively the users key). This is used at the end of the query to filter the result set of any protected data. Only accessible data is returned to the client. Since this data transfer is happening over the process boundary, it is harder (impossible?) for the client to subvert the server&#8217;s memory space.</p>
<p>The parallelism is currently implemented using Pyro. The engine is smart enough to use a host-process namespace so as to be able to identify all processes across all hosts (multiple processes can run on the same host to take advantage of multiple cores/processors). The code is still under heavy development so I don&#8217;t have all the answers yet regarding exactly what algorithms are being used for the multiple master transaction based data synchronization. We expect to prototype a few options (let me know if you have suggestions) and go with whatever has the best benchmarks.</p>
<p>I&#8217;m going to keep an eye on what the CPython guys come up with to deal with these issues.</p>
<p>-Prateek Sureka</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brainwavelive.com/blog/pycon/pycon-2007-lessons-on-security-and-parallelism/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Brainwave Code Repository</title>
		<link>http://www.brainwavelive.com/blog/technology/brainwave-code-repository/</link>
		<comments>http://www.brainwavelive.com/blog/technology/brainwave-code-repository/#comments</comments>
		<pubDate>Thu, 14 Dec 2006 23:46:49 +0000</pubDate>
		<dc:creator>Prateek Sureka</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.brainwavelive.com/wordpress/?p=20</guid>
		<description><![CDATA[I&#8217;ve been working for a while on a code repository where we can put up our open source projects and get some community participation going and I think we&#8217;ve finally got something&#8230;
JUnpickler: This is a Java based unpickler for Python pickle data. The idea is that you can serialize some data in Python and then [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working for a while on a code repository where we can put up our open source projects and get some community participation going and I think we&#8217;ve finally got something&#8230;</p>
<p>JUnpickler: This is a Java based unpickler for Python pickle data. The idea is that you can serialize some data in Python and then get the string into Java and deserialize it to get a Java object.</p>
<p>The code is released under the Eclipse Public License v1.0 (EPL). It&#8217;s one of the least restrictive licenses I could find.</p>
<p>Please let us know what you think or if you want to contribute.</p>
<p>Prateek Sureka</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brainwavelive.com/blog/technology/brainwave-code-repository/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My First Entry</title>
		<link>http://www.brainwavelive.com/blog/technology/my-first-entry/</link>
		<comments>http://www.brainwavelive.com/blog/technology/my-first-entry/#comments</comments>
		<pubDate>Tue, 12 Dec 2006 14:48:57 +0000</pubDate>
		<dc:creator>Prateek Sureka</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.brainwavelive.com/wordpress/?p=5</guid>
		<description><![CDATA[June 2004&#8230;
I had just returned from Peru after a trek to Machu Picchu to find India had changed since I left five years ago. College in the United States had been an amazing experience and I was set to return for a stint at a fast growing technology company on the East Coast. But in [...]]]></description>
			<content:encoded><![CDATA[<p>June 2004&#8230;<br />
I had just returned from Peru after a trek to Machu Picchu to find India had changed since I left five years ago. College in the United States had been an amazing experience and I was set to return for a stint at a fast growing technology company on the East Coast. But in the few months I had before I started work, I set forth to rediscover my homeland.</p>
<p>I found people teeming with optimism. Looking towards the stars &#8211; proud and egotistical about the future of the country. But something seemed amiss. The rest of the world still looked at India as a land of cheap labor, annoying tele-marketers, customer service reps and gut wrenching curry.</p>
<p>Yes we&#8217;re smart. Yes we&#8217;re enterprising. So why wait for the wage arbitrage to run out? The time was ripe to create an institution that was committed to technical excellence. Why not create our own &#8220;insanely great&#8221; products? But first you need a better hammer and chisel. I was back soon. Inspired by those who go against the grain to challenge the assumptions, affect the masses and make a difference, Brainwave was founded on the following principles.</p>
<ul>
<li>
<p style="margin-bottom: 0cm;">product centric</p>
</li>
<li>
<p style="margin-bottom: 0cm;">design oriented</p>
</li>
<li>
<p style="margin-bottom: 0cm;">technology driven</p>
</li>
<li>
<p style="margin-bottom: 0cm;">mecca for developers</p>
</li>
</ul>
<p>The Sureka Group was perfectly positioned to take advantage of this opportunity. Cash rich and ready for a challenge, the group was full of encouragement. Enthused with its success in manufacturing and real estate, its combined experience has been a boon to this fledgling enterprise with lofty goals.</p>
<p>And so we begin. As we proceed through this endeavor, we promise to always&#8230;</p>
<ul>
<li>
<p style="margin-bottom: 0cm;">deliver cutting edge products</p>
</li>
<li>
<p style="margin-bottom: 0cm;">tackle tough technical challenges</p>
</li>
<li>
<p style="margin-bottom: 0cm;">never cease to amaze</p>
</li>
</ul>
<p style="margin-bottom: 0cm;" align="right">- <em>Prateek Sureka</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.brainwavelive.com/blog/technology/my-first-entry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

