<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="weebly" -->
<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/" >

<channel><title><![CDATA[Distributed Information System (DIS) - The blog]]></title><link><![CDATA[http://www.disnetwork.info/the-blog.html]]></link><description><![CDATA[The blog]]></description><pubDate>Thu, 27 May 2010 10:39:11 -0800</pubDate><generator>Weebly</generator><item><title><![CDATA[Distributed Version Constrol System (DVCS) usage model]]></title><link><![CDATA[http://www.disnetwork.info/1/post/2010/03/development-model-using-distributed-version-constrol-system-dvcs.html]]></link><comments><![CDATA[http://www.disnetwork.info/1/post/2010/03/development-model-using-distributed-version-constrol-system-dvcs.html#comments]]></comments><pubDate>Sun, 28 Mar 2010 04:00:07 -0800</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">http://www.disnetwork.info/1/post/2010/03/development-model-using-distributed-version-constrol-system-dvcs.html</guid><description><![CDATA[Subversion has been my software version c [...] ]]></description><content:encoded><![CDATA[<span  style=" position: relative; float: left; z-index: 10; "><a><img src="http://www.disnetwork.info/uploads/3/8/0/1/38014/7510252.jpg" style="margin-top: 5px; margin-bottom: 10px; margin-left: 0px; margin-right: 10px; border-width:1px;padding:3px;" alt="Picture" class="galleryImageBorder" /></a><div style="display: block; font-size: 90%; margin-top: -10px; margin-bottom: 10px; text-align: center;"></div></span><div  class="paragraph" style=" text-align: left; display: block; ">Subversion has been my software version control system for years now. It is simple and straightforward but is inappropriate for some usage patterns that required sharing intermediate development code between developer or combining an official release version track with one or more development tracks. <br /><br />Distributed Version Control Systems with <a href="http://git-scm.com/">Git</a>, <a href="http://mercurial.selenic.com/">Mercurial </a>or <a href="http://bazaar.canonical.com/en/">Bazaar</a> solves these problems. The best way to understand this is by reading Vincent Driessen's blog post titled "<a href="http://nvie.com/git-model">A successful Git branching model</a>". It presents a usage model for Distributed Version Control System (DVCS) using git, but it work as well with Mercurial or Bazaar. <br /><br />The <a href="http://hginit.com/">Mercurial tutorial</a> provided by Joel Spolsky provides a very good introduction which explains why DVCS are better than the centralized version control systems like subversion. <br /><br />I still have to chose between the three. For now my preference is Git for technical reasons. The ergonomic aspect is important too, but fore this I usually rely on desktop integrated tools like <a href="http://code.google.com/p/tortoisegit/">turtoiseGit</a>. I'm currently a very happy user of <a href="http://rabbitvcs.org/">RabitVCS </a>which currently supports only Subversion. I hope they will support Git or Mercurial soon.<br /></div><hr  style=" visibility: hidden; width: 100%; clear: both; "></hr>]]></content:encoded></item><item><title><![CDATA[Log structured database]]></title><link><![CDATA[http://www.disnetwork.info/1/post/2010/03/log-structured-database.html]]></link><comments><![CDATA[http://www.disnetwork.info/1/post/2010/03/log-structured-database.html#comments]]></comments><pubDate>Mon, 01 Mar 2010 04:29:31 -0800</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">http://www.disnetwork.info/1/post/2010/03/log-structured-database.html</guid><description><![CDATA[The distributed information system (DIS) n [...] ]]></description><content:encoded><![CDATA[<span  style=" float: left; z-index: 10; position: relative; "><a><img src="http://www.disnetwork.info/uploads/3/8/0/1/38014/695970.jpg" style="margin-top: 5px; margin-bottom: 10px; margin-left: 0px; margin-right: 10px; border-width:1px;padding:3px;" alt="Picture" class="galleryImageBorder" /></a><div style="display: block; font-size: 90%; margin-top: -10px; margin-bottom: 10px; text-align: center;"></div></span><div  class="paragraph" style=" text-align: left; display: block; ">The distributed information system (DIS) needs a database to store its  information and a simple key value database would do the job. Today, <a href="http://1978th.net/tokyocabinet/">Tokyo Cabinet</a> seems the best  choice for such type of database.<br /><br /><span style="font-weight: bold;">Why a log structured database ?</span><br />  <br />My attention was recently caught by the blog post <a title="Links  active once published" href="http://blog.notdot.net/2009/12/Damn-Cool-Algorithms-Log-structured-storage">Damn  cool Algorithms: log structured storage</a>. The white paper presenting  <a href="http://www.rethinkdb.com/papers/whitepaper.pdf">RethinkDB</a>  provides a more exhaustive view of the benefits of this data structure  and some disadvantages too. The LWN.net article <a title="Links active  once published" href="http://lwn.net/Articles/353411/">Log-structured  file systems: There's one in every SSD</a> covers the use of log  structure in SSD file systems.<br /></div><hr  style=" width: 100%; visibility: hidden; clear: both; "></hr><div  class="paragraph" style=" text-align: left; ">While surfing the web to get more informations on log structured database, I found the following blog note presenting the experimental <a href="http://www.lshift.net/blog/2009/08/21/yet-another-key-value-database">YDB</a> log structured database with some interesting benchmark showing that YDB is roughly 5.6 time faster than Tokyo Cabinet and 8 time faster than Berkeley DB with random writes. These numbers justify some deeper investigation.<br /><br />The performance benefit is mainly due to constraining write operations to the end of the file because read access can benefit from memory caches, writes not. With random location writes, the disk writing head needs to move into position (seek) and this has a huge latency compared to transistor state changes or data transmission speed.<br /><br />Reducing disk head movements may thus yield a significant performance increase. Note that this won't be true with SSD disks anymore, but other constrains come in play too where a log structured database may still be attractive (evenly distributed and grouped writes).&nbsp; <br /><br /><span style="font-weight: bold;">The Record Index</span><br /><br />As you may guess writing data to the end of the file implies that modified records are copied. The record offset is then modified which implies an update of the index too. If the index, generally tree structured, is also stored in the log database, it result in cascade of changes which increases the amount of data to write to disk. <br /><br />This makes log structured database less attractive, especially if the index is a BTree of record keys. A BTree key index is not very compact and not trivial to manipulate, especially if keys are of varying length.<br /><br />I finally found a better solution derived from reading the white paper presenting the <a href="http://www.primebase.org/download/pbxt_white_paper.pdf">The PrimeBase XT Transactional Engine</a> describing a log structured table with <a href="http://en.wikipedia.org/wiki/ACID">ACID</a> property for an RDMS table, and more recently the article <a href="http://research.swtch.com/2008/03/using-uninitialized-memory-for-fun-and.html">Using Uninitialized Memory for Fun and Profit</a> describing a simple data structure to use an uninitialized array. <br /><br />The idea is to use an intermediate <span style="font-style: italic;">record index</span> which is basically a table of record offset and size. The entry index in the table is the record identifier and is used as key to locate the record in the file. The record identifier is associated to a record for its life time and may be reused for a new record after the record has been deleted. <br /><br /><span style="font-weight: bold;">Benefits of the record index</span><br /><br />The record index is stored as a tree index where non lead nodes hold the  offset to the lower level nodes of the tree. Changing an offset in a  leaf node will still imply a change in all the nodes up to the root of  the tree, but the index is much more compact than a conventional BTree  associating the record key with its offset and size. The record  identifier doesn't need to be stored in the index because it is its  relative position in it.&nbsp; <br /><br />Another benefit of this intermediate record index is that the record key index will now refer to the record identifier and this doesn't change when the record is modified. It is then possible to have multiple index to the records or to use the record identifier inside the user data to support record reference graphs (i.e. linked lists, etc.).<br /><br />By storing the record identifier along with the record data, the garbage collector or the crash recovery process can easily determine if a record is valid or. It simply has to compare the record offset and size with the one found in the record index. If it is the same, the record is the latest valid version. <br /><br /><span style="font-weight: bold;">Snapshots and recovery points</span><br /><br />The dirty pages of the record index need only to be saved at snapshot time. In case of process or system crash, the database should be restored to the last saved snapshot. A snapshot correspond to a coherent state of the database. A snapshot is saved any time the user closes the database. Restoring the database to some snapshot saved state boils down to truncate the file after the last valid record of the file. <br /><br />If snapshots saving is very frequent and crash recovery very rare, it is possible to use lightweight snapshots. For such snapshot only a small record is appended to the record stream which tags the point in the file where the snapshot occurred. When the database is recovered at some saved snapshot point, the recovery process can continue the recovery process beyond that recovery point by replaying all the changes until the last valid lightweight snapshot. The state of the database can then be restored to the latest lightweight snapshot, but with a slightly bigger effort than a saved snapshot recovery. <br /><br /><span style="font-weight: bold;">Garbage collector</span><br /><br />For the garbage collector (GC) the classical method may be applied which consist in opening a secondary log file and progressively copy valid records into it in background while it is used. A database backup is as simple as copying the file. <br /><br />When the lifetime duration of records varies a lot, it might be better to use generational log files, an algorithm used with memory garbage collector. The idea is to avoid copying constant records due to some other records short lifetime of frequent change generated garbage. The idea is to group records according to their change frequency into separated log structured database.&nbsp; <br /><br />A first log structured database contains all new or changed records. The garbage collector progress then at the same speed as records are written to the end of the file. Every valid data it finds is then copied in a second generation record log file. These records have lasted a GC cycle without a change. Additional generation database may be added for even slower changing records. <br /><br />The use of multiple log files will induce some disk writing head movements, but it will be balanced by saving the effort to repeatedly copy constant records. <br /><br /><span style="font-weight: bold;">Conclusion</span> <br /><br />It is not my intent to implement this shortly. I just wanted to document  the method which seems to be the canonical way to handle the record index  problem and for which I couldn't find a description on the web.<br /> </div>]]></content:encoded></item><item><title><![CDATA[The 8 fallacies of distributed computing]]></title><link><![CDATA[http://www.disnetwork.info/1/post/2009/10/the-8-fallacies-of-distributed-computing.html]]></link><comments><![CDATA[http://www.disnetwork.info/1/post/2009/10/the-8-fallacies-of-distributed-computing.html#comments]]></comments><pubDate>Sat, 17 Oct 2009 09:54:35 -0800</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">http://www.disnetwork.info/1/post/2009/10/the-8-fallacies-of-distributed-computing.html</guid><description><![CDATA[The following two paragraphs are the introductory paragraphs of the document Fallacies of distributed computing (pdf) by Arnon Rotem-Gal-Oz that presents the 8 fallacies of distributed computed. "Distributed systems already exist for a long tThe software industry has been writing distributed systems for several decades. Two examples incl [...] ]]></description><content:encoded><![CDATA[<div  class="paragraph" style=" text-align: left; ">The following two paragraphs are the introductory paragraphs of the document <a href="http://www.rgoarchitects.com/Files/fallacies.pdf">Fallacies of distributed computing (pdf)</a> by Arnon Rotem-Gal-Oz that presents the 8 fallacies of distributed computed. <br /><br /><span style="font-style: italic;">"Distributed systems already exist for a long tThe software industry has been writing distributed systems for several decades. Two examples include The US Department of Defense ARPANET (which eventually evolved into the Internet) which was established back in 1969 and the SWIFT protocol (used for money transfers) was also established in the same time frame [Britton2001]. </span><br /> <br /><span style="font-style: italic;"> Nevertheless, In 1994, Peter Deutsch, a sun fellow at the time, drafted 7 assumptions architects and designers of distributed systems are likely to make, which prove wrong in the long run - resulting in all sorts of troubles and pains for the solution and architects who made the assumptions. In 1997 James Gosling added another such fallacy [JDJ2004]. The assumptions are now collectively known as the "The 8 fallacies of distributed computing" [Gosling]:</span><br /><ol style="font-style: italic;"><li>The network is reliable</li><li>Latency is zero</li><li>Bandwidth is infinite</li><li>The network is secure</li><li>Topology doesn't change</li><li>There is one administrator</li><li>Transport cost is zero</li><li>The network is homogeneous</li></ol><span style="font-style: italic;">..."</span><br /><br />While in the process of designing a new distributed information system, it a good idea to check how it position itself regarding these 8 fallacies.<br /><br /><span style="font-weight: bold;">The network is reliable</span><br /><br />DIS uses TCP which was designed to be reliable and robust. Reliable means that data is transmitted uncorrupted to the other end and robust means that it may resist to a certain amount of errors. There is however a limit to the robustness of a TCP connection, and in some conditions connection to a remote service may even not be possible. <br /><br />DITP, the communication protocol of DIS, is of course designed to handle connection failures. Higher level and distributed services will have to take it in account too. <br /><br />Making a distribute information system robust implies to anticipate connection failures at any stage of the communication. For instance, a flock of servers designed to synchronize with each other may suddenly be partitioned in two or more unconnected flocks because of a network failure, and be connected back together later. <br /><br /><span style="font-weight: bold;">The latency is zero</span><br /><br />Latency was a major focus in the design of the DITP protocol because DIS is intended to be used for World Area Network (WAN) applications. DITP reduces latency impact by supporting asynchronous requests. These requests are batched and processes sequentially by the server in the order of emission. If a request in the batch is aborted by an exception, subsequent requests of the batch are ignored. This provides a fundamental functionality to support transactional applications. <br /><br />In addition to this, DIS may also support the ability to send code to be executed by a remote service. This provides the same functionality as JavaScript code embedded in web pages and executed by browsers, allowing to implement powerful and impressive web 2.0 applications. <br /><br />With DIS, remote code execution is taken care by services made available by the server manager if he wants to support them. The services may then process different types of pseudo-codes: JavaScript, Haxe, JVM, Python, ... Many different pseudo-codes services may then coexist and evolve independently of DIS. Such functionality is of course also exposed to security issues. See the secure network fallacy for an insight on how DIS addresses it. <br /><br /><span style="font-weight: bold;">Bandwidth is infinite</span><br /><br />This fallacy is the rational of the Information Data Representation (IDR) design. It uses binary and native data representation. In addition to be very fast and easy to Marshall, it is also very compact. <br /><br />DITP supports also user defined processing of transmitted data so that compression algorithms may be applied to them. DITP is also multiplexing concurrent communication channels in the same connections, allowing to apply different transmitted data processing to each channel. By choosing the channel the user may decide to compress transmitted data or not.&nbsp; <br /><br /><span style="font-weight: bold;">The network is secure</span><br /><br />A distributed system designed for a world wide usage must obviously take security in account. This means securing the transmitted data by mean of authentication and cyphering, as well as authenticating communicating parties and enforce access or action restriction rules. <br /><br />Communication security is provided by the DITP protocol by mean of the user specified transmitted data processing. As data compression, these can also handle data authentication and cyphering. Different authentication and cyphering methods and algorithms can coexist in DIS and may evolve independently of the DITP protocol. <br /><br />Authentication and access control may use conventional passwords methods as well as user identification certificates. But instead of using x509 certificates, DIS uses IDR encoded certificates corresponding to instances of certificate classes. Users may then derive their own certificates with class inheritance. They may extend the information carried in the certificate or combine different certificate types together. <br /><br />An authentication based on password checking or user identity certificate matching doesn't scale well for a world wide distributed system because they need to access a reference database. With distributed services, accessing a remote database introduces latencies and replicating it (i.e. caches) weakens its security by multiplying the number breach points. <br /><br />The authentication mechanism favored in DIS uses member certificates. These certificates are like club or company member access cards. When trying to access a service, the user present the corresponding certificate and the service needs simply to check the certificate validity. <br /><br />With such authentication mechanism, the service can be scattered all over the Internet and remain lightweight as is required for embedded applications (i.e. smart phones, car computers, ...). The authentication domain can also handle billions of members as well and easily as a few ones. Member certificates may be extended to carry specific informations and connection parameters. <br /><br /><span style="font-weight: bold;">Topology doesn't change</span><br /><br />The ability to handle network topology changes initiated the conception of DIS in 1992. It is thus designed from the start to address this issue in a simple, robust and efficient way. It is not a coincidence that the DIS acronym resembles the one of DNS. DIS is a distributed information system as the DNS is a distributed naming system. DIS uses the proven architecture of the DNS and applies it to generic information with additional functionalities like allowing to remotely manage the information. The DNS is known to be a corner stone of the network topology change solution, as will be DIS. <br /><br /><span style="font-weight: bold;">There is one administrator</span><br /><br />As the DNS, DIS supports a distributed administration. Information domain administrator have full liberty and authority in the way they organize and manage their information domain as long as the interface to DIS respects some standard rules. As for the DNS, there will be a central administration that defines the operational rules and control their application. If DIS becomes a broadly adopted system, the central administration will be composed of members elected democratically and coordinated with the Internet governance administration if such structures happens to be created. <br /><br /><span style="font-weight: bold;">Transport cost is zero</span><br /><br />The transport cost is indeed not zero but most of it is distributed and shared by the users. There remains however a residual cost for the central services and administration for which a revenue has to be identified. The DIS system will allow to obtain such a revenue and there is a rational reason why it ought to. <br /><br />Imposing a financial cost to some domains or features of DIS which are limited or artificially limited resources provides a mean to apply a perceptible pressure on its misbehaving users (i.e. spam). <br /><br /><span style="font-weight: bold;">The network is homogeneous</span><br /><br />DITP is designed to support different types of underlying transport connections. The information published in DIS is treated like an opaque byte block and may be of any type as well as its description language. It may be XML with its DTD description, binary with C like description syntax, python pickles or anything else. Of course it will also contain IDR encoded information with its Information Type Description. <br /><br /><span style="font-weight: bold;">Conclusion</span><br /><br />The conclusion is that DIS, DITP and IDR have been designed without falling on any of the common fallacies. This is partly due to the long maturation process of its conception. While this may be considered as a shortcoming, it may also be its strength since it allowed to examine all aspects wisely with time.<br /></div>]]></content:encoded></item><item><title><![CDATA[A Distributed Information System ? Nice, but what for ? ]]></title><link><![CDATA[http://www.disnetwork.info/1/post/2009/09/recommended-reading-snakes-on-the-web.html]]></link><comments><![CDATA[http://www.disnetwork.info/1/post/2009/09/recommended-reading-snakes-on-the-web.html#comments]]></comments><pubDate>Sat, 05 Sep 2009 05:16:06 -0800</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">http://www.disnetwork.info/1/post/2009/09/recommended-reading-snakes-on-the-web.html</guid><description><![CDATA[Here is a (long) blog note I would recommend reading : "Snakes on the web" written by Jackob Kaplan-Moss                                           (September 4, 2009). It is a talk given at PyCon Argentina and PyCon Brazil,&nbsp;2009.It presents an analysis on the current situation of web edition and desirable future system properties. My impression, and this i [...] ]]></description><content:encoded><![CDATA[<div  class="paragraph" style=" text-align: left; ">Here is a (long) blog note I would recommend reading : <a href="http://jacobian.org/writing/snakes-on-the-web/">"Snakes on the web</a>" written by Jackob Kaplan-Moss                                           (September 4, 2009). It is a talk given at PyCon Argentina and PyCon Brazil,&nbsp;2009.<br /><br />It presents an analysis on the current situation of web edition and desirable future system properties. <br /><br />My impression, and this is not a coincidence, is that DIS matches most of these requirements since it was designed to address the short comings of the actual systems.<br /></div>]]></content:encoded></item><item><title><![CDATA[DITP and The black triangle]]></title><link><![CDATA[http://www.disnetwork.info/1/post/2009/07/ditp-and-the-black-triangle.html]]></link><comments><![CDATA[http://www.disnetwork.info/1/post/2009/07/ditp-and-the-black-triangle.html#comments]]></comments><pubDate>Sat, 11 Jul 2009 01:39:34 -0800</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">http://www.disnetwork.info/1/post/2009/07/ditp-and-the-black-triangle.html</guid><description><![CDATA[A hacker news submission references the "The black triangle" blog note. I can only backup the author since I have experienced this many time. For short, with some programs the visible part of it is merely just a black triangle while the invisible part may be complex or required a lot of efforts to achieve. The black triangle is then gen [...] ]]></description><content:encoded><![CDATA[<p  style=" text-align: left; ">A <a href="http://news.ycombinator.com/news">hacker news</a> submission references the "<a href="http://rampantgames.com/blog/2004/10/black-triangle.html">The black triangle</a>" blog note. I can only backup the author since I have experienced this many time. <br /><br />For short, with some programs the visible part of it is merely just a black triangle while the invisible part may be complex or required a lot of efforts to achieve. The black triangle is then generally just a simple visual example to prove that the underlying system works. <br /><br />That is the state of progress of DITP. I'm working to get the black triangle to become visible. In doing so I'm also writing the protocol specification so that the protocol may be reviewed and implemented by third parties in other languages or libraries.<br /><br />The black triangle is like the first fruits of a fruiterer tree that may, sometime, took a long time to grow up to the point to be able to produce fruits.<br /><br /></p>]]></content:encoded></item><item><title><![CDATA["A note on distributed computing" (1994)]]></title><link><![CDATA[http://www.disnetwork.info/1/post/2009/07/a-note-on-distributed-computing-1994.html]]></link><comments><![CDATA[http://www.disnetwork.info/1/post/2009/07/a-note-on-distributed-computing-1994.html#comments]]></comments><pubDate>Tue, 07 Jul 2009 13:40:15 -0800</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">http://www.disnetwork.info/1/post/2009/07/a-note-on-distributed-computing-1994.html</guid><description><![CDATA["A note on distributed computing"Jim Waldo, Geoff Wyant, Ann Wollrath, Sam Kendall. Nov 1994.Abstract:We argue that objects that interact in a distributed system need to be dealt with in ways that are intrinsically differe [...] ]]></description><content:encoded><![CDATA[<p  style=" text-align: left; "><a href="http://research.sun.com/techrep/1994/smli_tr-94-29.pdf"><br />"A note on distributed computing"</a><br /><br />Jim Waldo, Geoff Wyant, Ann Wollrath, Sam Kendall. Nov 1994.<br /><br /><span style="font-style: italic; font-weight: bold;">Abstract:</span><span style="font-style: italic;"><br /><br />We argue that objects that interact in a distributed system need to be dealt with in ways that are</span> <span style="font-style: italic;">intrinsically different from objects that interact in a single address space. These differences are </span><span style="font-style: italic;">required because distributed systems require that the programmer be aware of latency, have a different </span><span style="font-style: italic;">model of memory access, and take into account issues of concurrency and partial failure.<br /><br /><span style="font-style: italic;">We look at a number of distributed systems that have attempted to paper over the distinction</span> <span style="font-style: italic;">between local and remote objects, and show that such systems fail to support basic requirements </span><span style="font-style: italic;">of robustness and reliability. These failures have been masked in the past by the small size of the </span><span style="font-style: italic;">distributed systems that have been built. In the enterprise-wide distributed systems foreseen in the </span><span style="font-style: italic;">near future, however, such a masking will be impossible.<br /><br /><span style="font-style: italic;">We conclude by discussing what is required of both systems-level and application-level programmers</span> <span style="font-style: italic;">and designers if one is to take distribution seriously.</span><br /><br /></span></span></p>]]></content:encoded></item><item><title><![CDATA[What is wrong with HTTP ?]]></title><link><![CDATA[http://www.disnetwork.info/1/post/2009/06/what-is-wrong-with-http.html]]></link><comments><![CDATA[http://www.disnetwork.info/1/post/2009/06/what-is-wrong-with-http.html#comments]]></comments><pubDate>Thu, 25 Jun 2009 01:43:05 -0800</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">http://www.disnetwork.info/1/post/2009/06/what-is-wrong-with-http.html</guid><description><![CDATA[Here is a document presenting a review on what is good an bad with HTTP. It provides some light on the choices I made for DIS. I couldn't identify the author's name in the text. Sorry.&nbsp; What is wrong with HTTP ?In this essay, the first of a pair on browser  [...] ]]></description><content:encoded><![CDATA[<p  style=" text-align: left; ">Here is a document presenting a review on what is good an bad with HTTP. It provides some light on the choices I made for DIS. I couldn't identify the author's name in the text. Sorry.&nbsp; <br /><a href="http://lists.canonical.org/pipermail/kragen-tol/2006-November/000841.html"><br /><span style="font-weight: bold; font-style: italic;">What is wrong with HTTP ?</span></a><br /><br /><span style="font-style: italic;">In this essay, the first of a pair on browser apps, I explore how</span><span style="font-style: italic;"> they are better than traditional desktop apps in some ways, but</span><span style="font-style: italic;"> worse in others.  Some of the disadvantages of browser apps are</span><span style="font-style: italic;"> deeply rooted in the use of HTTP URLs for naming.  In the second</span><span style="font-style: italic;"> essay, I will present a design sketch for a new platform, a</span><span style="font-style: italic;">re placement for HTTP combining both styles' advantages.</span><span style="font-style: italic;">Right now, we're seeing a massive shift to browser apps, largely</span><span style="font-style: italic;"> server-side browser apps.  As I warned in "People, places, things,</span><span style="font-style: italic;">and ideas," [18] this move to server-side browser apps imperils</span><span style="font-style: italic;"> our software freedom; I outlined how to solve this problem in "The </span><span style="font-style: italic;">equivalent of free software for online services."  [19] This pair </span><span style="font-style: italic;">of essays represents more detail on this problem and proposed </span><span style="font-style: italic;">solution.</span><br /><br /><a href="http://lists.canonical.org/pipermail/kragen-tol/2006-November/000841.html">read more ...</a><br /><br /></p>]]></content:encoded></item><item><title><![CDATA[Median value selection algorithm]]></title><link><![CDATA[http://www.disnetwork.info/1/post/2009/06/median-value-selection-algorithm.html]]></link><comments><![CDATA[http://www.disnetwork.info/1/post/2009/06/median-value-selection-algorithm.html#comments]]></comments><pubDate>Tue, 09 Jun 2009 13:11:15 -0800</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">http://www.disnetwork.info/1/post/2009/06/median-value-selection-algorithm.html</guid><description><![CDATA[At work I'm currently working on tomographic reconstruction algorithms. I have to implement a Bayesian iterative algorithm that requires to select the median value in a set of the 27 float values from a cube of 3x3x3 voxels. This operation must be performed for each voxel and for each iteration. We have to expect 256 million voxels to process for each iteration, but "only" 60 to 100 iterations. Trying to find the most efficient algorithm I came up with [...] ]]></description><content:encoded><![CDATA[<p  style=" text-align: left; ">At work I'm currently working on tomographic reconstruction algorithms. I have to implement a Bayesian iterative algorithm that requires to select the median value in a set of the 27 float values from a cube of 3x3x3 voxels. This operation must be performed for each voxel and for each iteration. We have to expect 256 million voxels to process for each iteration, but "only" 60 to 100 iterations. <br /><br />Trying to find the most efficient algorithm I came up with a new algorithm considering the one described on the <a href="http://en.wikipedia.org/wiki/Selection_algorithm.">select algorithm page of wikipedia</a>. I then submitted a question on <a href="http://stackoverflow.com/questions/810657/fastest-code-c-c-to-select-the-median-in-a-set-of-27-floating-point-values">StackOverflow</a> to get some feedback. And I did get valuable feedback. I was first pointed to the C++ nth_element function I didn't know at the time. It was also suggest to optimize by sharing intermediate information which is indeed a smart thing to do to get a better initial guess on the median value. <br /><br />After multiple tests and changes to the code I finally reached what seem to be a very efficient algorithm. The ratio is so good that I'm still unsure about it, but I checked everything. It could be due to memory cache or particularly favorable parallelization opportunities with sse instructions. I don't know. <br /><br />Here is the outline of the algorithm. We have 27 values and have to find the value that split the set in two with 13 values smaller or equal to it and 13 values bigger or equal to it. This value is called the median value. <br /><br />The fundamental idea of the algorithm is to use a heap data structure which has its smallest or biggest value at the top. Such data structure is very efficient for adding an element or to extract its top most element. It can also be very easily mapped into an array. <br /><br />The algorithm uses two heaps initially empty, with a common top value which is the median value. Each heap has a capacity of at most 14 elements, where one is common to the two heaps, their top value and also the median value.<br />The algorithm proceed in two phases. In the first phase, the algorithm picks a value as initial median value guess. Subsequent values are then compare with this median value and added to the corresponding heap until one heap becomes full and contains 14 elements. <br /><br />At this point the median value is a value in the full heap or in the remaining set of values to process. The second phase of the algorithm then starts where the remaining values are processed. Values that would not be inserted in the full heap are ignored. The other values are inserted in the full heap after deleting its top most value. The heap then gets a new top most value and thus also a new median value. When all the remaining elements have been processed, the median of the 27 value set is the top most value of the full heap. <br /><br />Here are some benchmark results. See <a href="http://stackoverflow.com/questions/810657/fastest-code-c-c-to-select-the-median-in-a-set-of-27-floating-point-values">StackOverflow</a> for more detailed information.<br /><br /><span>HeapSort</span><span> &nbsp; &nbsp;&nbsp; &nbsp; </span><span>:</span><span>2.287</span><span>&nbsp; <br /></span><span>QuickSort</span><span> &nbsp; &nbsp;&nbsp;&nbsp; </span><span>:</span><span>2.297</span><span>&nbsp; </span><span><br />QuickMedian1 </span><span>:</span><span>0.967&nbsp; </span><span><br />HeapMedian1 &nbsp;</span><span>:</span><span>0.858</span><span>&nbsp; <br /></span><span>NthElement</span><span> &nbsp;&nbsp;&nbsp; </span><span>:</span><span>0.616</span><span>&nbsp; </span><span><br />QuickMedian2 </span><span>:</span><span>1.178</span><span>&nbsp; </span><span><br />HeapMedian2 &nbsp;</span><span>:</span><span>0.597</span><span>&nbsp; </span><span><br />HeapMedian3 &nbsp;</span><span>:</span><span>0.015</span><span>&nbsp; </span><span>&lt;--</span><span> best</span><br /><br />It thus seem that HeapMedian3 is 33 times faster than NthElement. I used a 3GHz Intel E8400 processor and the Intel C++ compiler with options -03 and -xS for benchmarking. <br /><br />Here is the code :<br /><br /><span>// return the median value in a vector of 27 floats pointed to by a</span><span><br />float</span><span> heapMedian3</span><span>( </span><span>float</span><span>*</span><span>a </span><span>)<br /></span><span>{</span><span><br />&nbsp; &nbsp;</span><span>float</span><span> left</span><span>[</span><span>14</span><span>],</span><span> right</span><span>[</span><span>14</span><span>],</span><span> median</span><span>,</span><span>*</span><span>p</span><span>;</span><span><br />&nbsp; &nbsp;</span><span>unsigned</span><span> char</span><span> nLeft</span><span>,</span><span> nRight</span><span>;</span><span><br /><br />&nbsp; &nbsp;</span><span>// pick first value as median candidate</span><span><br />&nbsp; &nbsp;p </span><span>=</span><span> a</span><span>;</span><span><br />&nbsp; &nbsp;median </span><span>=</span><span> *</span><span>p</span><span>++;</span><span><br />&nbsp; &nbsp;nLeft </span><span>=</span><span> nRight </span><span>=</span><span>1</span><span>;</span><span><br /><br />&nbsp; &nbsp;</span><span>for</span><span>(;;)</span><span><br />&nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp;</span><span>// get next value</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp;</span><span>float</span><span> val </span><span>= </span><span>*</span><span>p</span><span>++;</span><span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp;</span><span>// if value is smaller than median, append to left heap</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp;</span><span>if</span><span>(</span><span> val </span><span>&lt;</span><span> median </span><span>)</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>// move biggest value to the heap top</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>unsigned</span><span> char</span><span> child </span><span>=</span><span> nLeft</span><span>++,</span><span> parent </span><span>= </span><span>(</span><span>child </span><span>-</span><span>1</span><span>)</span><span>/</span><span>2</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>while</span><span>(</span><span> parent </span><span>&amp;&amp;</span><span> val </span><span>&gt;</span><span> left</span><span>[</span><span>parent</span><span>]</span><span> )</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;left</span><span>[</span><span>child</span><span>]</span><span> =</span><span> left</span><span>[</span><span>parent</span><span>];</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;child </span><span>=</span><span> parent</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;parent </span><span>=</span><span>(</span><span>parent </span><span>-</span><span>1</span><span>)</span><span>/</span><span>2</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>}</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;left</span><span>[</span><span>child</span><span>]</span><span> =</span><span> val</span><span>;</span><span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>// if left heap is full</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>if</span><span>(</span><span> nLeft </span><span>== </span><span>14</span><span>)</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>// for each remaining value</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>for</span><span>(</span><span> unsigned</span><span> char</span><span> nVal </span><span>=</span><span> 27</span><span>-</span><span>(</span><span>p </span><span>-</span><span> a</span><span>);</span><span> nVal</span><span>;</span><span> --</span><span>nVal </span><span>)</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>// get next value</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;val </span><span>=</span><span> *</span><span>p</span><span>++;</span><span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>// if value is to be inserted in the left heap</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>if</span><span>(</span><span> val </span><span>&lt;</span><span> median </span><span>)</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;child </span><span>=</span><span> left</span><span>[</span><span>2</span><span>] </span><span>&gt;</span><span> left</span><span>[</span><span>1</span><span>] </span><span>? </span><span>2 </span><span>: </span><span>1</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>if</span><span>(</span><span> val </span><span>&gt;=</span><span> left</span><span>[</span><span>child</span><span>]</span><span>)</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;median </span><span>=</span><span> val</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>else</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;median </span><span>=</span><span> left</span><span>[</span><span>child</span><span>];</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;parent </span><span>=</span><span> child</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;child </span><span>=</span><span> parent</span><span>*</span><span>2</span><span> + </span><span>1</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>while</span><span>(</span><span> child </span><span>&lt;</span><span>14</span><span> )</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>if</span><span>(</span><span> child </span><span>&lt;</span><span> 13 </span><span>&amp;&amp;</span><span> left</span><span>[</span><span>child</span><span>+</span><span>1</span><span>]</span><span> &gt;</span><span> left</span><span>[</span><span>child</span><span>] </span><span>)</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>++</span><span>child</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>if</span><span>(</span><span> val </span><span>&gt;=</span><span> left</span><span>[</span><span>child</span><span>] </span><span>)</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>break</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;left</span><span>[</span><span>parent</span><span>]</span><span> =</span><span> left</span><span>[</span><span>child</span><span>];</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;parent </span><span>=</span><span> child</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;child </span><span>=</span><span> parent</span><span>*</span><span>2</span><span> + </span><span>1</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>}</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;left</span><span>[</span><span>parent</span><span>]</span><span> =</span><span> val</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>}</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>}</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>}</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>return</span><span> median</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>}</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp;</span><span>}</span><span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp;</span><span>// else append to right heap</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp;</span><span>else</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>// move smallest value to the heap top</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>unsigned</span><span> char</span><span> child </span><span>=</span><span> nRight</span><span>++,</span><span> parent </span><span>=</span><span> (</span><span>child </span><span>-</span><span>1</span><span>)</span><span>/</span><span>2</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>while</span><span>(</span><span> parent </span><span>&amp;&amp;</span><span> val </span><span>&lt;</span><span> right</span><span>[</span><span>parent</span><span>]</span><span> )</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;right</span><span>[</span><span>child</span><span>] </span><span>=</span><span> right</span><span>[</span><span>parent</span><span>];</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;child </span><span>=</span><span> parent</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;parent </span><span>=</span><span> (</span><span>parent </span><span>-</span><span>1</span><span>)</span><span>/</span><span>2</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>}</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;right</span><span>[</span><span>child</span><span>]</span><span> =</span><span> val</span><span>;</span><span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>// if right heap is full</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>if</span><span>(</span><span> nRight </span><span>==</span><span> 14 </span><span>)</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>// for each remaining value</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>for</span><span>(</span><span> unsigned</span><span> char</span><span> nVal </span><span>=</span><span> 27</span><span>-</span><span>(</span><span>p </span><span>-</span><span> a</span><span>);</span><span> nVal</span><span>;</span><span> --</span><span>nVal </span><span>)</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>// get next value</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;val </span><span>= </span><span>*</span><span>p</span><span>++;</span><span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>// if value is to be inserted in the right heap</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>if</span><span>(</span><span> val </span><span>&gt;</span><span> median </span><span>)</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;child </span><span>=</span><span> right</span><span>[</span><span>2</span><span>]</span><span> &lt;</span><span> right</span><span>[</span><span>1</span><span>]</span><span> ?</span><span> 2</span><span> :</span><span> 1</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>if</span><span>(</span><span> val </span><span>&lt;=</span><span> right</span><span>[</span><span>child</span><span>] </span><span>)</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;median </span><span>=</span><span> val</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>else</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;median </span><span>=</span><span> right</span><span>[</span><span>child</span><span>];</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;parent </span><span>=</span><span> child</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;child </span><span>=</span><span> parent</span><span>*</span><span>2</span><span> +</span><span> 1</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>while</span><span>(</span><span> child </span><span>&lt;</span><span>14 </span><span>)</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>{</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>if</span><span>(</span><span> child </span><span>&lt;</span><span> 13</span><span> &amp;&amp;</span><span> right</span><span>[</span><span>child</span><span>+</span><span>1</span><span>] </span><span>&lt;</span><span> right</span><span>[</span><span>child</span><span>] </span><span>)</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>++</span><span>child</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>if</span><span>(</span><span> val </span><span>&lt;=</span><span> right</span><span>[</span><span>child</span><span>]</span><span> )</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>break</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;right</span><span>[</span><span>parent</span><span>]</span><span> =</span><span> right</span><span>[</span><span>child</span><span>];</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;parent </span><span>=</span><span> child</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;child </span><span>=</span><span> parent</span><span>*</span><span>2 </span><span>+ </span><span>1</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>}</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;right</span><span>[</span><span>parent</span><span>]</span><span> =</span><span> val</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>}</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>}</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>}</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>return</span><span> median</span><span>;</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span>}</span><span><br />&nbsp; &nbsp; &nbsp; &nbsp;</span><span>}</span><span><br />&nbsp; &nbsp;</span><span>}<br /></span><span>}</span><br /><br /></p>]]></content:encoded></item><item><title><![CDATA[50 scientifically proven ways to be persuasive]]></title><link><![CDATA[http://www.disnetwork.info/1/post/2009/05/post-title-click-and-type-to-edit1.html]]></link><comments><![CDATA[http://www.disnetwork.info/1/post/2009/05/post-title-click-and-type-to-edit1.html#comments]]></comments><pubDate>Sun, 17 May 2009 23:23:48 -0800</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">http://www.disnetwork.info/1/post/2009/05/post-title-click-and-type-to-edit1.html</guid><description><![CDATA[When sketching out your business model or marketing strategy, read the following blog note or referenced book. There are easy ways to increase your efficiency. Yes! 50 Scientifically Proven Ways to Be&nbsp;Persuasive. [...] ]]></description><content:encoded><![CDATA[<p  style=" text-align: left; ">When sketching out your business model or marketing strategy, read the following blog note or referenced book. There are easy ways to increase your efficiency. <br /><br /><a href="http://www.moskalyuk.com/blog/yes-50-scientifically-proven-ways-to-be-persuasive/1624">Yes! 50 Scientifically Proven Ways to Be&nbsp;Persuasive<span style="text-decoration: underline;">.</span></a></p>]]></content:encoded></item><item><title><![CDATA[Object deserialization handling]]></title><link><![CDATA[http://www.disnetwork.info/1/post/2009/02/object-deserialization-handling.html]]></link><comments><![CDATA[http://www.disnetwork.info/1/post/2009/02/object-deserialization-handling.html#comments]]></comments><pubDate>Sat, 07 Feb 2009 05:27:52 -0800</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">http://www.disnetwork.info/1/post/2009/02/object-deserialization-handling.html</guid><description><![CDATA[In the last month I rewrote the IDR prototype from scratch and translated the IDR specification document in English. During this process I made a few enhancements in the IDR encoding. I removed an ambiguity with exceptions decoding in some very unlikely situations. The other change was to integrate the update of IEEE 754 specification in 2008 that now defines four types of floating point values, 2 Bytes,  [...] ]]></description><content:encoded><![CDATA[<p  style=" text-align: left; ">In the last month I rewrote the IDR prototype from scratch and translated the IDR specification document in English. During this process I made a few enhancements in the IDR encoding. I removed an ambiguity with exceptions decoding in some very unlikely situations. The other change was to integrate the update of IEEE 754 specification in 2008 that now defines four types of floating point values, <a href="http://en.wikipedia.org/wiki/Half_precision">2 Bytes</a>, <a href="http://en.wikipedia.org/wiki/Single_precision">4 Bytes</a>, <a href="http://en.wikipedia.org/wiki/Double_precision">8 Bytes</a> and <a href="http://en.wikipedia.org/wiki/Quadruple_precision">16 Bytes</a>. It may take some time until these types reach your desk, but IDR should better stick to the standards. So these will be the floating point encodings supported by IDR. <br /><br />Beside these, there was a much bigger problem left in the API of object deserialization. The problem is to determine what to do when the decoder doesn't recognize the class type of a serialized object. The solution I came up is very satisfying since it matches all the requirements I had. It remains to check its usage convenience with real examples. <br /><br /><span style="font-weight: bold;">The problem</span><br /><br />Object deserialization is a process in which the decoder reconstruct the serialized object aggregate. To do so it has to reconstruct each object of the aggregate and&nbsp; restore their pointers to each other. Objects are reconstructed by using object factories, a classic in design pattern. An object factory is an object that "knows" how to reconstruct some types of objects. <br /><br />The decoder has thus a collection of factories to which it delegates the reconstruction of the different types of objects found in the serialized aggregate. But what happens if the decoder can't find an appropriate factory for some type of serialized object ? In some use case this should be considered as an error, but in others it might be an acceptable and even desirable situation.&nbsp; <br /><br />Consider for instance exceptions. In IDR an exception is an object and handled as such. There is no point, and even impossible,  for a decoder to have a factory for all possible exceptions in the world. It is enough for the decoder to have a factory for the common exception base classes and, of course, the one it has to deal with. It should then be enough to reconstruct the object as an instance of the parent class it has a factory for, a process called <span style="font-style: italic;">object slicing</span>. <br /><br />The worst case is when the decoder may not even slice the object because none of the parent class is "known" by the decoder. In this case the best the decoder can do is to ignore the object and set all references to it to NULL. We'll call this process <span style="font-style: italic;">object pruning</span>. As for slicing, it may be considered as an acceptable and even desirable behavior with some use cases (i.e optional properties), and an error in others since the lobotomized data structured may end up too crippled or even invalid. <br /><br />The problem is thus to define the appropriate behaviour of the decoder when a slicing or pruning occurs. In some case it is an error, in others not, and in some case it depends on what part of the aggregate the slicing or pruning took place. <br /><br /><span style="font-weight: bold;">The solution</span><br /><br />The decision whether it is an error or not is obviously context specific and have thus to be put in the hands of the user. So the problem boiled down to determine how the user would able to select the appropriate behavior. <br /><br />The solution I came up was to provide three object deserialization methods. <br /><br />1. A strict object decoder that would throw an exception and abort object decoding as soon as a missing object factory is detected. With this you get an exact reconstruction or a failure. <br /><br />2. A lax object decoder that would slice and prune at will and return whatever comes out of it, and nothing else. This object decoder would for instance be used for exceptions. <br /><br />3. Another lax object decoder, like the previous one, but that would also return a feedback on the missing object factories. The feedback on slicing would be an associative index mapping sliced object references to the list of their unrecognized classs types. The feedback on pruning would be a list of the different types of pruned object with a list of the unrecognized class type and the number of instance pruned. <br /><br />The later method would make it possible and easy for the user to determine if slicing and pruning occurred, what are the missing factories and test for specific objects if slicing took place and to what extend. Since this method would give an easy way to test if slicing or pruning took place, the strict object decoder may seem unnecessary. The reason of its presence is that it may stop the decoding process as soon as a missing factory is detected and thus avoid wasting resources when an exact reconstruction is required and no feedback is needed. <br /><br />I'm very satisfied by this solution because it keeps the API simple with only a small effort on the decoder implementation. What I still need to validate is how convenient it is to use. <br /></p>]]></content:encoded></item></channel></rss>
