<?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>James Tetler Consulting</title> <atom:link href="http://jamestetler.com/feed/" rel="self" type="application/rss+xml" /><link>http://jamestetler.com</link> <description>Scalable High Performance PHP</description> <lastBuildDate>Mon, 30 Aug 2010 05:58:07 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <item><title>Using Life as a Model for Valid-Time State Tables</title><link>http://jamestetler.com/2010/08/using-life-as-a-model-for-valid-time-state-tables/</link> <comments>http://jamestetler.com/2010/08/using-life-as-a-model-for-valid-time-state-tables/#comments</comments> <pubDate>Tue, 10 Aug 2010 05:32:42 +0000</pubDate> <dc:creator>James Tetler</dc:creator> <category><![CDATA[Databases]]></category> <category><![CDATA[Software Architecture]]></category> <category><![CDATA[System Design]]></category> <category><![CDATA[Valid-Time State Tables]]></category><guid
isPermaLink="false">http://jamestetler.com/?p=44</guid> <description><![CDATA[Valid-Time State tables are common in many different types of software design. They are used to store and track an objects history over its life time. The typical implementation, using, [...]]]></description> <content:encoded><![CDATA[<p>Valid-Time State tables are common in many different types of software design. They are used to store and track an objects history over its life time. The typical implementation, using, as an example, an employee&#8217;s pay rate, would look something like the table below.</p><h2 class="wp-table-reloaded-table-name">Traditional Valid-Time State Table</h2><table
id="wp-table-reloaded-id-1-no-1" class="wp-table-reloaded wp-table-reloaded-id-1"><thead><tr
class="row-1 odd"><th
class="column-1">Employee ID</th><th
class="column-2">Salary</th><th
class="column-3">FROM_TIME</th><th
class="column-4">TO_TIME</th></tr></thead><tbody><tr
class="row-2 even"><td
class="column-1">4</td><td
class="column-2">40,000</td><td
class="column-3">2010-06-01</td><td
class="column-4">2011-06-01</td></tr><tr
class="row-3 odd"><td
class="column-1">4</td><td
class="column-2">35,000</td><td
class="column-3">2009-01-01</td><td
class="column-4">2010-06-01</td></tr></tbody></table><p>This is certainly a valid and widely used method, but I find that when coding this creates difficulties in coding, especially when working with these records as definitions of different methods in a continuous piecewise  calculation.</p><p>I find it preferable, and more efficient to model these tables after life. In the case of the employee, the logic works out like this:</p><ol><li> If no record exists for a given Employee  ID, then the Employee does not exist. This is analogous to a birth certificate, we could not have a record of a birth that has not yet happened. This is consistent with the traditional model.</li><li>An employee&#8217;s salary is effective beginning with the time recorded and ending when another record is encountered with an effective time &gt; than the record being examined.</li><li>An employee ceases to exist when a death certificate is filed, (In this example NULL is used to denote the termination of an employee.)</li></ol><p>The table below shows how this implementation would work with the same data from the previous table.</p><h2 class="wp-table-reloaded-table-name">Existence Model Valid-Time State Table</h2><table
id="wp-table-reloaded-id-2-no-1" class="wp-table-reloaded wp-table-reloaded-id-2"><thead><tr
class="row-1 odd"><th
class="column-1">Employee ID</th><th
class="column-2">Salary</th><th
class="column-3">EFFECTIVE_TIME</th></tr></thead><tbody><tr
class="row-2 even"><td
class="column-1">4</td><td
class="column-2">NULL</td><td
class="column-3">2011-06-01</td></tr><tr
class="row-3 odd"><td
class="column-1">4</td><td
class="column-2">40,000</td><td
class="column-3">2010-06-01</td></tr><tr
class="row-4 even"><td
class="column-1">4</td><td
class="column-2">35,000</td><td
class="column-3">2009-01-01</td></tr></tbody></table><p>The existence model clearly would be beneficial from a maintenance point of view, as it requires a new record only for each change in salary, unlike the traditional model which would require an update for each contract extension, new year, etc. Additionally it is always possible to calculate the same information stored in from date and to date by collecting the desired record and a more recent record if available.</p><p>The two models are very similar, but consider the existence model in the case of a real time system (not to say that this would be efficient for millisecond level state recording). The current state of an entity can always be found by finding the most recent record. The previous state can always be found by querying for the second most recent record and so on. This also simplifies the logic necessary to find the state at any given time. A sample query would look like this:</p><p
style="text-align: center;"><em>SELECT * FROM SALARY WHERE EMPLOYEE ID = 4 AND EFFECTIVE DATE &lt;= INPUT DATE ORDER BY DATE DESC LIMIT 1</em></p><p
style="text-align: left;">Because we are modeling this after existence, a result is guaranteed to be returned as long as an employee exists.</p><p
style="text-align: left;">The same query in the traditional model would look like this</p><p
style="text-align: center;"><em>SELECT * FROM SALARY WHERE <em>EMPLOYEE ID = 4 AND</em> FROM_DATE &lt;= INPUT DATE AND END_DATE &gt;= INPUT DATE</em></p><p
style="text-align: left;">Which provides no guarantee of a result and is thus prone to misconfiguration by the end user(assuming salary renewals are not automated).</p><p
style="text-align: left;">Neither model is perfect for every use case, but I believe and I think you will find, that the existence model makes much more sense logically from a developer and end user perspective for a majority of applications.</p><p
style="text-align: left;">Here is a post from the fantastic blog EXPLAIN EXTENDED on how to <a
href="http://explainextended.com/2009/11/12/inverting-date-ranges-mysql/" target="_blank">adapt existing range based tables to produce time gap results</a>.</p><p
style="text-align: justify;"><p
style="text-align: left;"><em> </em></p><p
style="text-align: left;"><em><br
/> </em></p><p
style="text-align: center;"><em><br
/> </em></p> ]]></content:encoded> <wfw:commentRss>http://jamestetler.com/2010/08/using-life-as-a-model-for-valid-time-state-tables/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Keep Your Objects Naked For Flexibility And Faster Development</title><link>http://jamestetler.com/2010/07/keep-your-objects-naked-for-flexibility-and-faster-development/</link> <comments>http://jamestetler.com/2010/07/keep-your-objects-naked-for-flexibility-and-faster-development/#comments</comments> <pubDate>Thu, 29 Jul 2010 01:27:42 +0000</pubDate> <dc:creator>James Tetler</dc:creator> <category><![CDATA[Software Architecture]]></category> <category><![CDATA[Naked Objects]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Software Architecure]]></category><guid
isPermaLink="false">http://jamestetler.com/?p=29</guid> <description><![CDATA[When building web applications (or any application for that matter) there&#8217;s a tendency to merge the object and presentation layers. This happens for many reasons, but usually its a result [...]]]></description> <content:encoded><![CDATA[<p>When building web applications (or any application for that matter) there&#8217;s a tendency to merge the object and presentation layers. This happens for many reasons, but usually its a result of too little time spent on architecture design and rushing to meet the current spec of the project. This results in difficult and costly work at each subsequent revision to the original design on the application.</p><p>The solution to this problem is beginning your application design with the Naked Object architecture in mind. Naked Objects is a relatively new design pattern for implementing business logic in a flexible way. Richard Pawson formalized the concept in his PHD thesis in 2004 (<a
title="Pawson, R., Naked Objects, Ph.D Thesis, 2004, Trinity College, Dublin, Ireland" href="http://downloads.nakedobjects.net/resources/Pawson%20thesis.pdf" target="_blank">pdf</a>). I recommend reading it if you have the time.</p><p>The idea is a simple one, traditional business logic patterns like MVC (Model View Controller) have been misconstrued by their implementers into architectures in which the design limits the abilities of the user. (<a
title="Trygve Reenskaug" href="http://en.wikipedia.org/wiki/Trygve_Reenskaug" target="_blank">Trygve Reenskaug</a>, the man behind MVC, wrote a great introduction the Pawson&#8217;s thesis describing this.) The Naked Objects Pattern removes the controller and places all of the logic on the object thus allowing the object to define the view. (There are frameworks built around this which automatically generate GUIs).</p><div
id="attachment_31" class="wp-caption alignright" style="width: 313px"><a
href="http://jamestetler.com/wp-content/uploads/2010/07/nakedObjArch.jpg"><img
class="size-full wp-image-31" title="Naked Object Architecture" src="http://jamestetler.com/wp-content/uploads/2010/07/nakedObjArch.jpg" alt="Naked Object Architecture" width="303" height="224" /></a><p
class="wp-caption-text">Naked Object Architecture</p></div><p>The real benefit of implementing your design in this way is that it allows for quick development of new features and application layers. There is currently no PHP framework for implementing true Naked Objects design (it looks like <a
href="http://giorgiosironi.blogspot.com/2009/07/naked-objects-in-php.html" target="_blank">this attempt</a> has been abandoned), but you can apply the basic philosophy to your application.</p><p>The immediate argument that comes to mind for its use, besides the obvious development speed increase for GUI features, is easily implementing an API on top of your sites data. Think about Twitter for example. You have three basic objects <strong>user, feed, </strong>and <strong>post</strong>. If all of the interaction is defined in an MVC type pattern then you would have to invoke several controllers to authenticate a user and retrieve a feed of the 10 most recent posts. The architecture is too limiting and difficult to be easily adapted to support basic API requests. Getting the 10 most recent posts from naked objects would be simple. Authenticate against a method from the user object, call the most recent method from the feed given the user specified, and request the content of the posts given from the post object. The actual implementation of this API call would likely be ~10 &#8211; 15 lines of code (not including all of the protocol stuff).</p><p>The other major advantage is easy unit and performance testing. Supposed you wanted to unit test the new post / retrieve post logic for Twitter. In MVC you would invoke the controller which in turn invokes the model. Hunting down a problem in a simple storage and retrieval like this could be simple. But how would you know where exactly, the model or controller, your code broke down in a controller function with 100 lines of code and a model with 50 lines of storage logic? You end up with stack traces and that&#8217;s just a mess (though always useful). With the methods defined on the objects you can simply implement and unit test these calls (assuming you have a well tested data storage layer). This seriously helps in avoiding problems with feature creep if you use a standard GET / SET methodology on your data members. More complicated functions call on simple ones and you can unit test up the complexity tree.</p><p>There&#8217;s an argument against over coding your objects though, especially in PHP. This is due mostly to a lack of inlining / compilation. Every function all has considerable overhead when you&#8217;re thinking on a microsecond scale. I think however you would find that the savings in development costs far outweigh any costs for extra resources needed to support the extra capacity in terms of page views and response times. As a developer it seriously decreases the amount of days high on the headache index when your boss comes running down the hall asking for new features.</p> ]]></content:encoded> <wfw:commentRss>http://jamestetler.com/2010/07/keep-your-objects-naked-for-flexibility-and-faster-development/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Horizontally Scalable Parallel Database Layer</title><link>http://jamestetler.com/2010/07/horizontally-scalable-parallel-database-layer/</link> <comments>http://jamestetler.com/2010/07/horizontally-scalable-parallel-database-layer/#comments</comments> <pubDate>Tue, 27 Jul 2010 00:55:29 +0000</pubDate> <dc:creator>James Tetler</dc:creator> <category><![CDATA[Databases]]></category> <category><![CDATA[Software Architecture]]></category> <category><![CDATA[Gearman]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[Shard-Query]]></category><guid
isPermaLink="false">http://jamestetler.com/?p=23</guid> <description><![CDATA[Below is a sample architecture for using Shard-Query and Gearman to build and efficient, scalable and fault tolerant database layer to support your N-Tier architecture. Obviously more job servers and [...]]]></description> <content:encoded><![CDATA[<p>Below is a sample architecture for using Shard-Query and Gearman to build and efficient, scalable and fault tolerant database layer to support your N-Tier architecture.</p><div
id="attachment_25" class="wp-caption aligncenter" style="width: 577px"><a
href="http://jamestetler.com/wp-content/uploads/2010/07/dblayer.png"><img
class="size-full wp-image-25" title="Horizontally Scalable DB Layer Using Gearman and Shard Query" src="http://jamestetler.com/wp-content/uploads/2010/07/dblayer.png" alt="" width="567" height="406" /></a><p
class="wp-caption-text">Horizontally Scalable DB Layer Using Gearman and Shard Query</p></div><p>Obviously more job servers and worker nodes can be added to this structure to meet demand.</p> ]]></content:encoded> <wfw:commentRss>http://jamestetler.com/2010/07/horizontally-scalable-parallel-database-layer/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Run a Query in Parallel to Improve Speed</title><link>http://jamestetler.com/2010/07/run-a-query-in-parallel-to-improve-speed/</link> <comments>http://jamestetler.com/2010/07/run-a-query-in-parallel-to-improve-speed/#comments</comments> <pubDate>Sun, 25 Jul 2010 23:12:52 +0000</pubDate> <dc:creator>James Tetler</dc:creator> <category><![CDATA[Databases]]></category> <category><![CDATA[Gearman]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Shard-Query]]></category><guid
isPermaLink="false">http://jamestetler.com/?p=5</guid> <description><![CDATA[Shard-Query (http://code.google.com/p/shard-query/) is a library built in PHP which leverages the power of Net Gearman to partition MySQL queries over multiple connections to increase speed in retrieving datasets. This allows you to distribute [...]]]></description> <content:encoded><![CDATA[<p>Shard-Query (<a
href="http://code.google.com/p/shard-query/">http://code.google.com/p/shard-query/</a>) is a library built in PHP which leverages the power of Net Gearman to partition MySQL queries over multiple connections to increase speed in retrieving datasets. This allows you to distribute load over replication slaves and to leverage multi-core processors.</p><p>Take as an example a data set with a DATETIME field. A sample query over this data set would be﻿</p><blockquote><p>SELECT * FROM EXAMPLE_TABLE WHERE DATE &gt; &#8217;2009-01-01&#8242; AND DATE &lt; &#8217;2010-01-01&#8242;</p></blockquote><p>MySQL handles this as a single process. Shard-Query, however, automatically partitions the query across Gearman workers.</p><p>With two worker nodes the query would become two queries.</p><blockquote><p>SELECT * FROM EXAMPLE_TABLE WHERE DATE &gt; &#8217;2009-01-01&#8242; AND DATE &lt; &#8217;2009-6-01&#8242;</p><p>SELECT * FROM EXAMPLE_TABLE WHERE DATE &gt; &#8217;2009-06-01&#8242; AND DATE &lt; &#8217;2010-01-01&#8242;</p></blockquote><p>Connections would be established to the DBMS from each worker and when both data sets had been returned, Shard-Query combines them and returns them as a single result set.</p><p>See the graph below for a performance comparison between Shard-Query and standard query execution.</p><div
id="attachment_6" class="wp-caption aligncenter" style="width: 522px"><a
href="http://jamestetler.com/wp-content/uploads/2010/07/shard_query_parallelism.png"><img
class="size-full wp-image-6" title="Shard Query Parallelism" src="http://jamestetler.com/wp-content/uploads/2010/07/shard_query_parallelism.png" alt="" width="512" height="366" /></a><p
class="wp-caption-text">Shard Query Parallelism</p></div> ]]></content:encoded> <wfw:commentRss>http://jamestetler.com/2010/07/run-a-query-in-parallel-to-improve-speed/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching using disk
Object Caching 383/419 objects using disk

Served from: jamestetler.com @ 2010-09-03 06:58:41 -->