<feed xmlns="http://www.w3.org/2005/Atom"><title>Aaron Dunnington</title><id>tag:aarondunnington.com,2013:aarondunnington.com</id><link rel="self" href="//aarondunnington.com/feed"></link><updated>2015-03-21T11:00:00+00:00</updated><entry><title>Array-Based Queue on Aerospike</title><id>tag:aarondunnington.com,2013:aarondunnington.com/array-based-queue-on-aerospike</id><link rel="alternate" href="//aarondunnington.com/array-based-queue-on-aerospike"></link><published>2015-03-21T11:00:00+00:00</published><updated>2015-03-21T11:00:00+00:00</updated><author><name>Aaron Dunnington</name></author><summary type="html">&lt;a href=&#34;http://aerospike.com&#34; target=&#34;_blank&#34;&gt;Aerospike&lt;/a&gt; is a high-performance, horizontally scalable key-value store. Running 1M transactions per second without breaking a sweat, this NoSQL database is delivering &lt;a href=&#34;http://googlecloudplatform.blogspot.com/2015/01/Aerospike-demonstrates-RAM-like-performance-with-Local-SSDs.html&#34; target=&#34;_blank&#34;&gt;10-15x price-performance gains&lt;/a&gt;. Notably, through flash optimizations, RAM-like performance can be achieved using local SSDs. Further, Aerospike operates as an AP data store.&#xA;</summary><content type="html">&#xA;&#xA;  &#xA;  &#xA;    &#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    &lt;a href=&#34;http://aerospike.com&#34; target=&#34;_blank&#34;&gt;Aerospike&lt;/a&gt; is a high-performance, horizontally scalable key-value store. Running 1M transactions per second without breaking a sweat, this NoSQL database is delivering &lt;a href=&#34;http://googlecloudplatform.blogspot.com/2015/01/Aerospike-demonstrates-RAM-like-performance-with-Local-SSDs.html&#34; target=&#34;_blank&#34;&gt;10-15x price-performance gains&lt;/a&gt;. Notably, through flash optimizations, RAM-like performance can be achieved using local SSDs. Further, Aerospike operates as an AP data store.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Similar to &lt;a href=&#34;http://redis.io&#34; target=&#34;_blank&#34;&gt;Redis&lt;/a&gt;, Aerospike provides built-in support for complex data types such as &lt;a href=&#34;http://www.aerospike.com/docs/udf/api/list.html&#34; target=&#34;_blank&#34;&gt;lists&lt;/a&gt; and &lt;a href=&#34;http://www.aerospike.com/docs/udf/api/map.html&#34; target=&#34;_blank&#34;&gt;maps&lt;/a&gt;. If you a migrating a Redis based application for nice &lt;a href=&#34;http://www.aerospike.com/when-to-use-aerospike-vs-redis&#34; target=&#34;_blank&#34;&gt;performance rewards&lt;/a&gt;, you can conveniently use a complete &lt;a href=&#34;https://github.com/helipilot50/aerospike-redis&#34; target=&#34;_blank&#34;&gt;Redis veneer&lt;/a&gt;. Note, when storing built-in Aerospike data structures in records, you are bound by the typical record size limitation of 1MB. The &lt;a href=&#34;http://www.aerospike.com/docs/architecture/ldt.html&#34; target=&#34;_blank&#34;&gt;Large Data Type (LDT)&lt;/a&gt; Lua extensions, further, provide support for ordered lists, sets, stacks, and maps. Using &lt;a href=&#34;http://www.aerospike.com/docs/architecture/storage.html&#34; target=&#34;_blank&#34;&gt;sub-records&lt;/a&gt;, LDTs may grow freely, only limited by the underlying storage.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Through User Defined Function (UDF) modules, data structures can be managed directly within Aerospike on the server. The Redis veneer above provides a great example of this record management from which this UDF module is based on. To enable runtime characteristics similar to that of a memory resident &lt;a href=&#34;http://redis.io/commands#list&#34; target=&#34;_blank&#34;&gt;linked list in Redis&lt;/a&gt;, you can implement efficient queuing using two array list buffers. Let&amp;#39;s begin with the enqueue User Defined Function (UDF) in Lua. &lt;i&gt;NOTE: For a more scalable approach with similar runtime properties, please see the&lt;/i&gt;&#xA;&#xA;&#xA;    &lt;a href=&#34;https://github.com/helipilot50/aerospike-LDT-techniques&#34; target=&#34;_blank&#34;&gt;&lt;i&gt;aerospike-LDT-techniques&lt;/i&gt;&lt;/a&gt;&#xA;&#xA;&#xA;    &lt;i&gt;repo.&lt;/i&gt;&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;lua&#34;&gt;function enqueue(rec, bin, value)&#xA;    local q = rec[bin]&#xA;    if q == nil then&#xA;        q = map { size = 0, pos = 0 }&#xA;    end&#xA;&#xA;    if q.rear == nil then&#xA;        q.rear = list()&#xA;    end&#xA;    list.append(q.rear, value)&#xA;    q.size = q.size &amp;#43; 1&#xA;&#xA;    rec[bin] = q&#xA;    l_update(rec)&#xA;    return q.size&#xA;end&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    The UDF above participates in the main flow of the transaction. This method sets up a map to manage the queue data structure if it does not already exist. Subsequently, it appends the incoming value to a rear array list buffer before updating the record with the call to the local helper function l_update. Next, let&amp;#39;s take a look at the work of our dequeuing function which manages our second buffer.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;lua&#34;&gt;if q.front == nil then&#xA;    q.front = q.rear&#xA;    q.pos = 1&#xA;    map.remove(q, &amp;#34;rear&amp;#34;)&#xA;end&#xA;&#xA;local item = nil&#xA;local last = list.size(q.front)&#xA;&#xA;if last == 1 then&#xA;    item = q.front[1]&#xA;    map.remove(q, &amp;#34;front&amp;#34;)&#xA;else&#xA;    if q.pos &amp;lt; last then&#xA;        item = q.front[q.pos]&#xA;        q.front[q.pos] = q.front[last]&#xA;        q.pos = q.pos &amp;#43; 1&#xA;    else&#xA;        item = q.front[last]&#xA;    end&#xA;    list.remove(q.front, last)&#xA;end&#xA;q.size = q.size - 1&#xA;return item&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    The dequeuing logic above manages the front buffer of the queue. If no front buffer exists, it will move the rear buffer to the front. As we are using array lists for our buffers, it would be a linear operation to dequeue items from the beginning of the list since all subsequent items need to be shifted left. By maintaining a position in our queue, we can dequeue more efficiently. As items are dequeued, we iteratively reverse the list by copying the item currently in the last position into the old index of the item being dequeued. Once we hit the end of the list, we dequeue from the last position until the front buffer is empty.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    The complete queue.lua UDF module is &lt;a href=&#34;https://gist.github.com/aarondunnington/e540227fc398101a810b&#34; target=&#34;_blank&#34;&gt;available here&lt;/a&gt;. To install, use the udf-put command below.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;bash&#34;&gt;ascli udf-put queue.lua&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    To work with the queue through the aql console, it can be called with the execute command.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;bash&#34;&gt;aql&amp;gt; execute queue.enqueue(&amp;#39;Q&amp;#39;, 99) on demo.queues where pk=&amp;#39;q&amp;#39;&#xA;&amp;#43;---------&amp;#43;&#xA;| enqueue |&#xA;&amp;#43;---------&amp;#43;&#xA;| 1       |&#xA;&amp;#43;---------&amp;#43;&#xA;&#xA;aql&amp;gt; execute queue.dequeue(&amp;#39;Q&amp;#39;) on demo.queues where pk=&amp;#39;q&amp;#39;&#xA;&amp;#43;---------&amp;#43;&#xA;| dequeue |&#xA;&amp;#43;---------&amp;#43;&#xA;| 99      |&#xA;&amp;#43;---------&amp;#43;&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Using two buffers, we can achieve runtime characteristics similar to that of a linked list. As this queue example stores the data structure within a single Aerospike record, it is bound by the aforementioned record storage limits.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &lt;h4 id=&#34;TOC_1.1.&#34;&gt;References&lt;/h4&gt;&#xA;  &#xA;  &#xA;  &lt;p&gt;&#xA;    Thanks to &lt;a href=&#34;https://twitter.com/helipilot50&#34; target=&#34;_blank&#34;&gt;Peter Milne&lt;/a&gt; for creating the excellent &lt;a href=&#34;http://www.aerospike.com/blog/redis-operations-in-aerospike/&#34; target=&#34;_blank&#34;&gt;Redis veneer article&lt;/a&gt; which this UDF module is based on. Additionally, please see Peter&amp;#39;s &lt;a href=&#34;https://github.com/helipilot50/aerospike-LDT-techniques&#34; target=&#34;_blank&#34;&gt;aerospike-LDT-techniques&lt;/a&gt; repo for FIFO utilizing LDTs. As opposed to the in-record storage limitations discussed above, the LDT approach scales queueing by utilizing a LLIST as a map with counters positioned at the head and tail.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;&#xA;      &#xA;    &#xA;  &#xA;&#xA;</content></entry><entry><title>HTTP Request Context in Golang</title><id>tag:aarondunnington.com,2013:aarondunnington.com/http-request-context-in-golang</id><link rel="alternate" href="//aarondunnington.com/http-request-context-in-golang"></link><published>2015-01-07T11:00:00+00:00</published><updated>2015-01-07T11:00:00+00:00</updated><author><name>Aaron Dunnington</name></author><summary type="html">The &lt;a href=&#34;http://golang.org/pkg/net/http/&#34; target=&#34;_blank&#34;&gt;Go HTTP stack&lt;/a&gt; offers a very efficient web server implementation. As the &lt;a href=&#34;http://golang.org/pkg/net/http/#Request&#34; target=&#34;_blank&#34;&gt;Request&lt;/a&gt; object passed through to &lt;a href=&#34;http://golang.org/pkg/net/http/#Handler&#34; target=&#34;_blank&#34;&gt;Handlers&lt;/a&gt; does not support memory resident storage itself, context specific to the lifetime of each request needs to be managed outside net/http.&#xA;</summary><content type="html">&#xA;&#xA;  &#xA;  &#xA;    &#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    The &lt;a href=&#34;http://golang.org/pkg/net/http/&#34; target=&#34;_blank&#34;&gt;Go HTTP stack&lt;/a&gt; offers a very efficient web server implementation. As the &lt;a href=&#34;http://golang.org/pkg/net/http/#Request&#34; target=&#34;_blank&#34;&gt;Request&lt;/a&gt; object passed through to &lt;a href=&#34;http://golang.org/pkg/net/http/#Handler&#34; target=&#34;_blank&#34;&gt;Handlers&lt;/a&gt; does not support memory resident storage itself, context specific to the lifetime of each request needs to be managed outside net/http.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Go web frameworks such as &lt;a href=&#34;https://goji.io/&#34; target=&#34;_blank&#34;&gt;Goji&lt;/a&gt;, &lt;a href=&#34;http://beego.me/&#34; target=&#34;_blank&#34;&gt;Beego&lt;/a&gt;, and &lt;a href=&#34;http://revel.github.io/&#34; target=&#34;_blank&#34;&gt;Revel&lt;/a&gt; have built-in support for request context. Further, the &lt;a href=&#34;http://www.gorillatoolkit.org/&#34; target=&#34;_blank&#34;&gt;Gorilla&lt;/a&gt; &lt;a href=&#34;http://www.gorillatoolkit.org/pkg/context&#34; target=&#34;_blank&#34;&gt;context&lt;/a&gt; package provides support for global request variables, though it relies on mutex to guard access to request state. If you are running directly on net/http, you can also inject a context object at the beginning of the request lifecycle which flows through the handler chain. By passing context through, rather than relying a global context object, state specific to each request can be managed without introducing locks.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;go&#34;&gt;type Handler func(http.ResponseWriter, *http.Request, *Context)&#xA;&#xA;func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {&#xA;    ctx := &amp;amp;Context{&#xA;        Config: Config,&#xA;        DB:     DB,&#xA;        Items:  map[string]interface{}{},&#xA;    }&#xA;    h(w, r, ctx)&#xA;}&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    To build a chain of Handlers which accept context, the creation of the custom Handler type above can be wrapped. The outer Handler returned will contain a reference to the Handler chain passed in. Upon execution by the networking stack, the outer Handler&amp;#39;s ServeHTTP method will be invoked, creating the custom Context object before forwarding to the entire handler chain.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;go&#34;&gt;func Csrf(h Handler) Handler {&#xA;    return Handler(&#xA;        func(w http.ResponseWriter, r *http.Request, ctx *Context) {&#xA;&#xA;            // Your super secure CSRF logic here...&#xA;&#xA;            ctx.Items[&amp;#34;csrf&amp;#34;] = token&#xA;            h(w, r, ctx)&#xA;        })&#xA;}&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    As Handler implements the ServeHTTP method, the first handler instance in the chain can be registered with a given pattern on your router.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;go&#34;&gt;func home(w http.ResponseWriter, r *http.Request, ctx *Context) {&#xA;    Render(&amp;#34;home.tmpl&amp;#34;, ctx.Items[&amp;#34;csrf&amp;#34;])&#xA;}&#xA;router.Handle(&amp;#34;/&amp;#34;, Csrf(Handler(home)))&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    At runtime, the Csrf handler executes first, calling ServeHTTP to setup the request environment. Next, the Csrf handler itself is called which sets a token within the Context. Finally, the home Handler is invoked wherein request context state is made available.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;    &#xA;  &#xA;&#xA;</content></entry><entry><title>Autoscale Resque Workers on Heroku</title><id>tag:aarondunnington.com,2013:aarondunnington.com/autoscale-resque-workers-on-heroku</id><link rel="alternate" href="//aarondunnington.com/autoscale-resque-workers-on-heroku"></link><published>2011-11-27T11:00:00+00:00</published><updated>2011-11-27T11:00:00+00:00</updated><author><name>Aaron Dunnington</name></author><summary type="html">A common technique for autoscaling &lt;a href=&#34;https://github.com/blog/542-introducing-resque&#34; target=&#34;_blank&#34;&gt;Resque&lt;/a&gt; workers on Heroku uses the after_enqueue and after_perform hooks that run within each Resque worker to adjust the current worker scale up and down, respectively. The after_perform hook watches the pending job count. When no jobs remain, this hook will scale all workers down.&#xA;</summary><content type="html">&#xA;&#xA;  &#xA;  &#xA;    &#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    A common technique for autoscaling &lt;a href=&#34;https://github.com/blog/542-introducing-resque&#34; target=&#34;_blank&#34;&gt;Resque&lt;/a&gt; workers on Heroku uses the after_enqueue and after_perform hooks that run within each Resque worker to adjust the current worker scale up and down, respectively. The after_perform hook watches the pending job count. When no jobs remain, this hook will scale all workers down.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    When scaling workers up, the &lt;a href=&#34;https://github.com/heroku/heroku.rb&#34; target=&#34;_blank&#34;&gt;Heroku API&lt;/a&gt; is additive; thus, additional workers can be scaled while others are actively processing jobs. As the Heroku API does not currently allow individually specified workers to scale down, however, it is necessary to wait until all workers are inactive before performing a scale down operation.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    While the after_perform scale down approach mitigates against shutting an active worker down while pending jobs exist, a race condition can occur where the pending job count hits zero, and a scale down operation is invoked on the Heroku API prior to a subsequent job being enqueued from the app and reserved on a worker which will be shutdown in the current scale operation.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Recently, I have been working on the &lt;a href=&#34;http://github.com/aarondunnington/resque-heroku-scaler&#34; target=&#34;_blank&#34;&gt;resque-heroku-scaler gem&lt;/a&gt; which autoscales Resque workers through a separate monitor process. The scaler monitor process polls for pending jobs against the specified Resque Redis backend. When scaling down, this scaler process locks each worker from attempting to reserve any future pending jobs before a scale down operation is performed.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    To get started, include the scaler tasks in lib/tasks/scaler.rake&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;ruby&#34;&gt;require &amp;#39;resque/tasks&amp;#39;&#xA;require &amp;#39;resque/plugins/heroku_scaler/tasks&amp;#39;&#xA;&#xA;task &amp;#34;resque:setup&amp;#34; =&amp;gt; :environment&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    In your Procfile, configure the scaler process using:&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;bash&#34;&gt;scaler: bundle exec rake resque:heroku_scaler&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    To run the scaler process, use the following command.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;bash&#34;&gt;heroku scale scaler=1&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Require the worker extensions within the app running your workers. For example, in lib/tasks/resque.rake. These extensions to the worker run loop poll for a shared flag within the Redis backend set by the scaler process which indicates the worker should enter an inactive scaling state. After a worker has entered this scaling state, it will cease attempting to check for incoming pending jobs. Once all workers have indicated they are inactive, the scaler process issues the scale down operation using the Heroku API.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;ruby&#34;&gt;require &amp;#39;resque/tasks&amp;#39;&#xA;&#xA;task &amp;#34;resque:setup&amp;#34; =&amp;gt; :environment do&#xA;    require &amp;#39;resque-heroku-scaler&amp;#39;&#xA;    ENV[&amp;#39;QUEUE&amp;#39;] = &amp;#39;*&amp;#39;&#xA;end&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    In your development environment, the scaler process can run local worker processes using the rush library. To configure, use the following in your scaler rake file.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;ruby&#34;&gt;require &amp;#39;resque/tasks&amp;#39;&#xA;require &amp;#39;resque/plugins/heroku_scaler/tasks&amp;#39;&#xA;&#xA;task &amp;#34;resque:setup&amp;#34; =&amp;gt; :environment do&#xA;    if Rails.env.development?&#xA;        require &amp;#39;resque-heroku-scaler&amp;#39;&#xA;        ENV[&amp;#34;RUSH_PATH&amp;#34;] ||= File.expand_path(&amp;#39;/path/to/app&amp;#39;, __FILE__)&#xA;        Resque::Plugins::HerokuScaler.configure do |c|&#xA;            c.scale_manager = :local&#xA;        end&#xA;    end&#xA;end&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;    &#xA;  &#xA;&#xA;</content></entry><entry><title>Autoscale Delayed Job Workers on Heroku Cedar</title><id>tag:aarondunnington.com,2013:aarondunnington.com/autoscale-delayed-job-workers-on-heroku-cedar</id><link rel="alternate" href="//aarondunnington.com/autoscale-delayed-job-workers-on-heroku-cedar"></link><published>2011-07-23T11:00:00+00:00</published><updated>2011-07-23T11:00:00+00:00</updated><author><name>Aaron Dunnington</name></author><summary type="html">&lt;a href=&#34;http://www.heroku.com/&#34; target=&#34;_blank&#34;&gt;Heroku&lt;/a&gt; provides an excellent platform to scale your Ruby or Node.js application through the cloud. Built on top of &lt;a href=&#34;http://aws.amazon.com/ec2/&#34; target=&#34;_blank&#34;&gt;Amazon EC2&lt;/a&gt;, Heroku alleviates much of the server administration work typically associated with scaling applications out as user demand increases. Heroku is &lt;a href=&#34;http://en.wikipedia.org/wiki/Platform_as_a_service&#34; target=&#34;_blank&#34;&gt;PaaS&lt;/a&gt;; &lt;a href=&#34;http://blog.sforce.com/sforce/2010/12/what-i-love-about-heroku.html&#34; target=&#34;_blank&#34;&gt;Salesforce&lt;/a&gt; and &lt;a href=&#34;http://blog.heroku.com/archives/2011/7/12/matz_joins_heroku/&#34; target=&#34;_blank&#34;&gt;Matz&lt;/a&gt; agree.&#xA;</summary><content type="html">&#xA;&#xA;  &#xA;  &#xA;    &#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    &lt;a href=&#34;http://www.heroku.com/&#34; target=&#34;_blank&#34;&gt;Heroku&lt;/a&gt; provides an excellent platform to scale your Ruby or Node.js application through the cloud. Built on top of &lt;a href=&#34;http://aws.amazon.com/ec2/&#34; target=&#34;_blank&#34;&gt;Amazon EC2&lt;/a&gt;, Heroku alleviates much of the server administration work typically associated with scaling applications out as user demand increases. Heroku is &lt;a href=&#34;http://en.wikipedia.org/wiki/Platform_as_a_service&#34; target=&#34;_blank&#34;&gt;PaaS&lt;/a&gt;; &lt;a href=&#34;http://blog.sforce.com/sforce/2010/12/what-i-love-about-heroku.html&#34; target=&#34;_blank&#34;&gt;Salesforce&lt;/a&gt; and &lt;a href=&#34;http://blog.heroku.com/archives/2011/7/12/matz_joins_heroku/&#34; target=&#34;_blank&#34;&gt;Matz&lt;/a&gt; agree.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    On the new &lt;a href=&#34;http://devcenter.heroku.com/articles/cedar&#34; target=&#34;_blank&#34;&gt;Cedar stack&lt;/a&gt;, scaling your app’s web and background processes across N machines can be achieved using the &lt;a href=&#34;http://devcenter.heroku.com/articles/scaling&#34; target=&#34;_blank&#34;&gt;scale&lt;/a&gt; command. While explicit scale commands work well for web processes as traffic increases, background workers tend to have a lot of free time if not managed automatically, running $36 a month per worker.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Several libraries currently autoscale background workers. For &lt;a href=&#34;https://github.com/blog/542-introducing-resque&#34; target=&#34;_blank&#34;&gt;Resque&lt;/a&gt; based workers, Daniel Huckstep provides a &lt;a href=&#34;http://verboselogging.com/2010/07/30/auto-scale-your-resque-workers-on-heroku&#34; target=&#34;_blank&#34;&gt;cool approach&lt;/a&gt; to scale based on load. For Delayed Job, Heroku’s Pedro Belo has provided a &lt;a href=&#34;https://github.com/pedro/delayed_job/tree/autoscaling&#34; target=&#34;_blank&#34;&gt;DJ fork&lt;/a&gt; which supports autoscaling on &lt;a href=&#34;http://devcenter.heroku.com/articles/bamboo&#34; target=&#34;_blank&#34;&gt;Bamboo&lt;/a&gt; and &lt;a href=&#34;http://devcenter.heroku.com/articles/aspen&#34; target=&#34;_blank&#34;&gt;Aspen&lt;/a&gt;. Additional DJ autoscale libraries include &lt;a href=&#34;https://github.com/meskyanichi/hirefire&#34; target=&#34;_blank&#34;&gt;HireFire&lt;/a&gt; and &lt;a href=&#34;https://github.com/lostboy/workless&#34; target=&#34;_blank&#34;&gt;Workless&lt;/a&gt;.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    While I would prefer to use Github&amp;#39;s Resque for performance and manageability, to avoid an additional, potentially paid dependency on Redis at this stage, I am currently using Pedro&amp;#39;s Delayed Job autoscaling fork with a few changes to support Cedar.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    This implementation will autoscale a single worker up and down as background requests are generated by the application. Job retries are not currently supported. To use, create an initializer similar to below. In your local development environment, the &lt;a href=&#34;http://rush.heroku.com/&#34; target=&#34;_blank&#34;&gt;rush library&lt;/a&gt; provides process management.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;ruby&#34;&gt;Delayed::Worker.auto_scale = true&#xA;Delayed::Worker.max_attempts = 1&#xA;&#xA;if Rails.env.production?&#xA;    Delayed::Worker.auto_scale_manager = :cedar&#xA;else&#xA;    Delayed::Worker.auto_scale_manager = :local&#xA;end&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    To schedule a custom background job or delay send from a mailer, respectively:&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;ruby&#34;&gt;Delayed::Job.enqueue YourAwesomeJob.new&#xA;UserMailer.delay.welcome_email(context)&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    In your Procfile, add:&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;bash&#34;&gt;worker: bundle exec rake jobs:work&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Efficiently autoscaling your background workers eliminates spending for idle dynos. For a background load of 20 hours per month, you’d pay $1 autoscaling compared to $36 for an idle background worker running the entire month.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;    &#xA;  &#xA;&#xA;</content></entry><entry><title>Recurring Billing with Braintree&#39;s Transparent Redirect</title><id>tag:aarondunnington.com,2013:aarondunnington.com/recurring-billing-with-braintree-s-transparent-redirect</id><link rel="alternate" href="//aarondunnington.com/recurring-billing-with-braintree-s-transparent-redirect"></link><published>2011-07-18T11:00:00+00:00</published><updated>2011-07-18T11:00:00+00:00</updated><author><name>Aaron Dunnington</name></author><summary type="html">Over the past several years, &lt;a href=&#34;https://www.pcisecuritystandards.org/&#34; target=&#34;_blank&#34;&gt;PCI DSS&lt;/a&gt; has prompted quite a bit of change on the web in credit card processing. There is &lt;a href=&#34;http://en.wikipedia.org/wiki/Payment_Card_Industry_Data_Security_Standard&#34; target=&#34;_blank&#34;&gt;much&lt;/a&gt; to be read on the topic; though, in short, since 2004 a &lt;a href=&#34;https://www.pcisecuritystandards.org/organization_info/executive-committee.php&#34; target=&#34;_blank&#34;&gt;consortium&lt;/a&gt; of credit card companies have established the &lt;a href=&#34;https://www.pcisecuritystandards.org/security_standards/&#34; target=&#34;_blank&#34;&gt;governing standard&lt;/a&gt; for how merchants must deal with credit cards online. Achieving compliance, however, can be quite costly.&#xA;</summary><content type="html">&#xA;&#xA;  &#xA;  &#xA;    &#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Over the past several years, &lt;a href=&#34;https://www.pcisecuritystandards.org/&#34; target=&#34;_blank&#34;&gt;PCI DSS&lt;/a&gt; has prompted quite a bit of change on the web in credit card processing. There is &lt;a href=&#34;http://en.wikipedia.org/wiki/Payment_Card_Industry_Data_Security_Standard&#34; target=&#34;_blank&#34;&gt;much&lt;/a&gt; to be read on the topic; though, in short, since 2004 a &lt;a href=&#34;https://www.pcisecuritystandards.org/organization_info/executive-committee.php&#34; target=&#34;_blank&#34;&gt;consortium&lt;/a&gt; of credit card companies have established the &lt;a href=&#34;https://www.pcisecuritystandards.org/security_standards/&#34; target=&#34;_blank&#34;&gt;governing standard&lt;/a&gt; for how merchants must deal with credit cards online. Achieving compliance, however, can be quite costly.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Enter &lt;a href=&#34;http://www.braintreepayments.com/&#34; target=&#34;_blank&#34;&gt;Braintree&lt;/a&gt;, a service based payment solution providing a merchant account, your processing gateway, and recurring billing on a single platform. By externalizing the credit card surface area within your application, Braintree’s unique &lt;a href=&#34;http://www.braintreepayments.com/services/pci-compliance&#34; target=&#34;_blank&#34;&gt;Transparent Redirect&lt;/a&gt; technology allows you to preserve the sales experience within the context of your site while alleviating the hurdles associated with achieving PCI compliance.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    In concert with the Braintree&amp;#39;s Vault, Transparent Redirect enables developers to productively integrate recurring subscription billing. To remotely create customers within the vault using transparent redirect, call the create customer data method to embed the redirect data within the form as a hidden field.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;ruby&#34;&gt;class PaymentController &amp;lt; ApplicationController&#xA;  def signup&#xA;    @tr_data = Braintree::TransparentRedirect.create_customer_data(&#xA;      :redirect_url =&amp;gt; &amp;#34;http://example.com/payment/confirm&amp;#34;&#xA;    )&#xA;  end&#xA;end&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    This data field will include the callback location to your confirmation action to be invoked after sensitive credit card data has been externalized to Braintree in the initial remote form post.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;erb&#34;&gt;&amp;lt;%= form_tag Braintree::TransparentRedirect.url, :method =&amp;gt; :post do %&amp;gt;&#xA;  &amp;lt;%= hidden_field_tag &amp;#34;tr_data&amp;#34;, @tr_data %&amp;gt;&#xA;  &amp;lt;%= text_field_tag &amp;#34;customer[credit_card][number]&amp;#34; %&amp;gt;&#xA;  &amp;lt;%= text_field_tag &amp;#34;customer[credit_card][expiration_date]&amp;#34; %&amp;gt;&#xA;&amp;lt;% end %&amp;gt;&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    In your confirmation callback action, the customer record can be confirmed using the query string parameter below. The result will contain the identifier tokens which represent the remote customer and credit card, respectively.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;ruby&#34;&gt;result = Braintree::TransparentRedirect.confirm(request.query_string)&#xA;customer_id = result.customer.id&#xA;payment_token = result.customer.credit_cards[0].token&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Lastly, to establish a recurring subscription associated with the remote credit card, use the payment token along with the selected plan.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;ruby&#34;&gt;result = Braintree::Subscription.create(&#xA;  :payment_method_token =&amp;gt; payment_token,&#xA;  :plan_id =&amp;gt; &amp;#34;super_awesome_plan&amp;#34;&#xA;)&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Braintree&amp;#39;s innovative approach to externalizing credit card information through transparent redirection takes the pain out of PCI compliance while preserving the user experience within the context of your site. Braintree is paving the way in today’s demanding world of web based credit card processing. Use them.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;    &#xA;  &#xA;&#xA;</content></entry><entry><title>Asynchronous MongoDB in Tornado with asyncmongo</title><id>tag:aarondunnington.com,2013:aarondunnington.com/asynchronous-mongodb-in-tornado-with-asyncmongo</id><link rel="alternate" href="//aarondunnington.com/asynchronous-mongodb-in-tornado-with-asyncmongo"></link><published>2010-12-05T11:00:00+00:00</published><updated>2010-12-05T11:00:00+00:00</updated><author><name>Aaron Dunnington</name></author><summary type="html">&lt;i&gt;EDIT: This blog now runs on&lt;/i&gt;&#xA;&lt;a href=&#34;http://golang.org/&#34; target=&#34;_blank&#34;&gt;&lt;i&gt;Golang&lt;/i&gt;&lt;/a&gt;&#xA;</summary><content type="html">&#xA;&#xA;  &#xA;  &#xA;    &#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    &lt;i&gt;EDIT: This blog now runs on&lt;/i&gt;&#xA;&#xA;&#xA;    &lt;a href=&#34;http://golang.org/&#34; target=&#34;_blank&#34;&gt;&lt;i&gt;Golang&lt;/i&gt;&lt;/a&gt;&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    This blog runs on the &lt;a href=&#34;http://www.tornadoweb.org/&#34; target=&#34;_blank&#34;&gt;Tornado&lt;/a&gt; web framework. Tornado is one of &lt;a href=&#34;http://en.wikipedia.org/wiki/C10k_problem&#34; target=&#34;_blank&#34;&gt;a handful&lt;/a&gt; of &lt;a href=&#34;http://www.kegel.com/c10k.html&#34; target=&#34;_blank&#34;&gt;C10K&lt;/a&gt; web servers which scale concurrent requests through a single threaded, event-driven asynchronous architecture. By using a single thread to manage multiple requests, a single C10K server can scale to thousands of concurrent requests.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    One thread for the entire web server, doesn&amp;#39;t that block other requests when hitting the database you might ask? Absolutely it does if you&amp;#39;re using blocking style I/O. Tornado differs from conventional web servers which use multiple threads to handle concurrent requests. When using traditional threaded web servers, each blocking call to the database or a remote service will be isolated in a separate thread to unblock execution of other requests. While multi-threaded servers provide a very clean programming model to handle concurrency, the overhead of managing multiple threads can pose challenges when C10K scale is required. Over the past decade, this has led many large web offerings to take a bet on event-driven servers. Some notable sites using C10K servers include YouTube, Wikipedia, Wordpress, FriendFeed, and bit.ly.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    So, what&amp;#39;s the catch? While the single-threaded nature of event-driven servers is great for scaling concurrency, additional care is required in the mid-tier to preserve the non-blocking programming style. For remote web service calls, Tornado includes a &lt;a href=&#34;http://www.tornadoweb.org/en/stable/httpclient.html&#34; target=&#34;_blank&#34;&gt;non-blocking HTTP client&lt;/a&gt;.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    While this is great for HTTP based services, most database access in Tornado has typically been blocking. FriendFeed &lt;a href=&#34;http://groups.google.com/group/python-tornado/browse_thread/thread/9a08f5f08cdab108&#34; target=&#34;_blank&#34;&gt;uses a blocking MySQL client&lt;/a&gt; under the assumption that if database queries were causing concurrency issues in the mid-tier, the database servers would not be able to scale to the corresponding load. FriendFeed also uses nginx as a load balancer in front of Tornado which helps to distribute any momentary blocking calls to the database amongst several frontend machines.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Bummer, all that C10K perf only to block on every call to the database? Not a problem anymore for MongoDB users. Bit.ly recently &lt;a href=&#34;http://groups.google.com/group/python-tornado/browse_thread/thread/d4a9b60b5e679b26&#34; target=&#34;_blank&#34;&gt;contributed&lt;/a&gt; their work on &lt;a href=&#34;https://github.com/bitly/asyncmongo&#34; target=&#34;_blank&#34;&gt;asyncmongo&lt;/a&gt; to the community which provides non-blocking access to mongo over the &lt;a href=&#34;https://github.com/mongodb/mongo-python-driver&#34; target=&#34;_blank&#34;&gt;PyMongo API&lt;/a&gt;.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;python&#34;&gt;import asyncmongo&#xA;import tornado.web&#xA;&#xA;class Handler(tornado.web.RequestHandler):&#xA;    @tornado.web.asynchronous&#xA;    def get(self):&#xA;        db = asyncmongo.Client(pool_id=&amp;#39;mypool&amp;#39;, host=&amp;#39;localhost&amp;#39;, &#xA;            port=27107, dbname=&amp;#39;mydb&amp;#39;)&#xA;&#xA;        db.users.find_one({&amp;#39;username&amp;#39;: self.current_user}, &#xA;            callback=self._on_response)&#xA;&#xA;    def _on_response(self, response, error):&#xA;        if error:&#xA;            raise tornado.web.HTTPError(500)&#xA;        self.render(&amp;#39;template&amp;#39;, first_name=response[&amp;#39;first_name&amp;#39;])&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Bit.ly&amp;#39;s asyncmongo fills a huge gap in data access for Tornado. This client driver preserves the non-blocking programming style required by event-driven architecture in the mid-tier to a major NoSQL player &lt;a href=&#34;http://gigaom.com/cloud/mongodb-raises-6-5m-to-dominate-the-nosql-space/&#34; target=&#34;_blank&#34;&gt;focused&lt;/a&gt; on scaling big data. Looking forward to seeing other client libraries follow suite. &lt;a href=&#34;https://github.com/pycassa/pycassa&#34; target=&#34;_blank&#34;&gt;Pycassa&lt;/a&gt; users have been &lt;a href=&#34;http://groups.google.com/group/python-tornado/browse_thread/thread/8a8c671eaa95ee6f/2d3989c89763f2d9&#34; target=&#34;_blank&#34;&gt;calling&lt;/a&gt; for it.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;    &#xA;  &#xA;&#xA;</content></entry><entry><title>Data-Driven iPhone Apps with Property Lists and PHP</title><id>tag:aarondunnington.com,2013:aarondunnington.com/data-driven-iphone-apps-with-property-lists-and-php</id><link rel="alternate" href="//aarondunnington.com/data-driven-iphone-apps-with-property-lists-and-php"></link><published>2009-12-16T11:00:00+00:00</published><updated>2009-12-16T11:00:00+00:00</updated><author><name>Aaron Dunnington</name></author><summary type="html">When driving iPhone apps with data from the cloud, the device&amp;#39;s underlying connection speed is often a potential performance bottleneck. As devices consume increasingly larger sets of data over the air, an app&amp;#39;s ability to provide a smooth experience can be constrained. Thus, when selecting payload formats or compression techniques, service aware mobile apps can really benefit from a healthy respect for just how much an EDGE or 3G connection can hose your transfer rates.&#xA;</summary><content type="html">&#xA;&#xA;  &#xA;  &#xA;    &#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    When driving iPhone apps with data from the cloud, the device&amp;#39;s underlying connection speed is often a potential performance bottleneck. As devices consume increasingly larger sets of data over the air, an app&amp;#39;s ability to provide a smooth experience can be constrained. Thus, when selecting payload formats or compression techniques, service aware mobile apps can really benefit from a healthy respect for just how much an EDGE or 3G connection can hose your transfer rates.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    One way to add a performance optimization to the payload format consumed by data driven iPhone apps is through Property Lists. &lt;a href=&#34;http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/PropertyLists/AboutPropertyLists/AboutPropertyLists.html&#34; target=&#34;_blank&#34;&gt;Property Lists&lt;/a&gt; provide a great mechanism for iPhone apps to transparently marshal data in and out of an app using either XML or binary formats.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    As great as XML is for exposing data to a wide range of clients, it is &lt;a href=&#34;http://www.w3.org/XML/1999/XML-in-10-points&#34; target=&#34;_blank&#34;&gt;verbose by design&lt;/a&gt;, and often bloats wire payloads in favor of interoperability. If you can afford to introduce a little coupling of your mobile app to your service, the binary serialization format of Property Lists may potentially &lt;a href=&#34;http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaPerformance/Articles/GeneralInfo.html&#34; target=&#34;_blank&#34;&gt;boost perf 5 to 20 times&lt;/a&gt; over text based Property Lists. Though, even the XML based Property List schema arguably would add some coupling to the Mac platform. On the other hand, if you&amp;#39;d rather give up the seamless interaction the Property List APIs have with native data types on the iPhone, it would be interesting to see how a minimalistic &lt;a href=&#34;http://en.wikipedia.org/wiki/Plain_Old_XML&#34; target=&#34;_blank&#34;&gt;POX&lt;/a&gt; based format performs against binary Property Lists.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Nevertheless, there are a number of options for exposing Property Lists on the server depending on your language. I&amp;#39;ve seen Property List implementations for &lt;a href=&#34;http://docs.python.org/dev/library/plistlib.html&#34; target=&#34;_blank&#34;&gt;Python&lt;/a&gt;, &lt;a href=&#34;http://search.cpan.org/~kyoki/Data-Plist-0.1/lib/Data/Plist.pm&#34; target=&#34;_blank&#34;&gt;Perl&lt;/a&gt;, and &lt;a href=&#34;http://code.google.com/p/cfpropertylist/&#34; target=&#34;_blank&#34;&gt;PHP&lt;/a&gt;. If you&amp;#39;re running OSX on the server, of course both &lt;a href=&#34;http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSPropertyListSerialization_Class/Reference/Reference.html&#34; target=&#34;_blank&#34;&gt;Cocoa&lt;/a&gt; and &lt;a href=&#34;http://developer.apple.com/mac/library/documentation/CoreFoundation/Reference/CFPropertyListRef/Reference/reference.html&#34; target=&#34;_blank&#34;&gt;Core Foundation&lt;/a&gt; offer Property List APIs; or, you could run &lt;a href=&#34;http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/plutil.1.html&#34; target=&#34;_blank&#34;&gt;plutil&lt;/a&gt; from the shell. Lastly, there&amp;#39;s always parsing the raw bytes if that&amp;#39;s more your bag. Though, unless you really want to understand Apple&amp;#39;s binary serialization format for Property Lists by parsing it yourself, the Cocoa, Core Foundation, plutil, PHP, and Perl implementations are the options I&amp;#39;ve seen thus far that offer binary support.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    The CFPropertyList project provides a Property List implementation for PHP. Here&amp;#39;s a simple &lt;a href=&#34;http://www.zend.com/&#34; target=&#34;_blank&#34;&gt;Zend&lt;/a&gt; controller that exposes a list of entries using CFPropertyList.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;php&#34;&gt;&amp;lt;?php&#xA;&#xA;require_once &amp;#39;CFPropertyList/CFPropertyList.php&amp;#39;;&#xA;require_once &amp;#39;models/Entry.php&amp;#39;;&#xA;&#xA;class BlogController extends Zend_Controller_Action&#xA;{&#xA;    public function init()&#xA;    {&#xA;        $this-&amp;gt;_helper-&amp;gt;viewRenderer-&amp;gt;setNoRender();&#xA;        $this-&amp;gt;_helper-&amp;gt;layout-&amp;gt;disableLayout();&#xA;    }&#xA;&#xA;    public function indexAction()&#xA;    {&#xA;        $table = new Entry();&#xA;&#xA;        $select = $table-&amp;gt;select();&#xA;        $rows = $table-&amp;gt;fetchAll($select);&#xA;&#xA;        $plist = $this-&amp;gt;createPropertyList($rows);&#xA;&#xA;        $this-&amp;gt;getResponse()-&amp;gt;setHttpResponseCode(200);&#xA;        $this-&amp;gt;getResponse()-&amp;gt;setHeader(&amp;#39;Content-Type&amp;#39;, &#xA;            &amp;#39;application/octet-stream&amp;#39;, true);&#xA;        $this-&amp;gt;getResponse()-&amp;gt;setBody($plist-&amp;gt;toBinary());&#xA;    }&#xA;}&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Here, we grab some entries from the database, then call createPropertyList (which we&amp;#39;ll write next) with the results, and lastly serialize the response in the binary format by calling the toBinary method on the returned plist object. Now, let&amp;#39;s generate the property list from our data set below.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;php&#34;&gt;private function createPropertyList($rows)&#xA;{&#xA;    $entries = new CFArray();&#xA;    foreach ($rows as $row)&#xA;    {&#xA;        $entry = new CFDictionary();&#xA;        $entry-&amp;gt;add(&amp;#39;id&amp;#39;, new CFNumber($row-&amp;gt;entry_id));&#xA;        $entry-&amp;gt;add(&amp;#39;title&amp;#39;, new CFString($row-&amp;gt;title));&#xA;        $entry-&amp;gt;add(&amp;#39;author&amp;#39;, new CFString($row-&amp;gt;author));&#xA;        $entry-&amp;gt;add(&amp;#39;summary&amp;#39;, new CFString($row-&amp;gt;summary));&#xA;        $entries-&amp;gt;add($entry);&#xA;    }&#xA;&#xA;    $d = new CFDictionary();&#xA;    $d-&amp;gt;add(&amp;#39;feed&amp;#39;, $entries);&#xA;&#xA;    $plist = new CFPropertyList();&#xA;    $plist-&amp;gt;add($d);&#xA;&#xA;    return $plist;&#xA;}&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    This method iterates over the result set while creating corresponding Property List structures. The CFPropertyList PHP library provides type wrappers for the corresponding property list data type, for example, CFDictionary, CFArray, CFNumber, and CFString in the above snippet. This function produces a Property List with a top level CFDictionary that has one item named &amp;#34;feed&amp;#34;. The value of the &amp;#34;feed&amp;#34; item is a CFArray which contains a CFDictionary object for each entry.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Then, on the client, here&amp;#39;s a quick look at how to consume the property list based service. Here, we make a remote call to the service, and turn the resulting NSData into a Property List to print out the title of each entry. The remote call in this code blocks with the invocation of sendSynchronousRequest:returningResponse:error: for the sake of brevity; though, in practice, processing the request asynchronously with NSURLConnection may be more appropriate.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;div class=&#34;code&#34;&gt;&lt;pre class=&#34;objectivec&#34;&gt;NSURL *url = [NSURL URLWithString:@&amp;#34;http://localhost/blog&amp;#34;];&#xA;NSURLRequest *request = [NSURLRequest requestWithURL:url];&#xA;&#xA;NSData *data = [NSURLConnection &#xA;                    sendSynchronousRequest:request&#xA;                    returningResponse:&amp;amp;response&#xA;                    error:&amp;amp;error];&#xA;&#xA;id pList = [NSPropertyListSerialization&#xA;                propertyListFromData:data&#xA;                mutabilityOption:NSPropertyListImmutable&#xA;                format:&amp;amp;format&#xA;                errorDescription:&amp;amp;errorStr];&#xA;&#xA;NSDictionary *d = (NSDictionary *)pList;&#xA;NSArray *entries = (NSArray *)[d objectForKey:@&amp;#34;feed&amp;#34;];&#xA;&#xA;for (NSDictionary *entry in entries) {&#xA;    NSLog(@&amp;#34;Title: %@&amp;#34;, [entry objectForKey:@&amp;#34;title&amp;#34;]);&#xA;}&lt;/pre&gt;&lt;/div&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    CFPropertyList&amp;#39;s baked in support for binary is cool. It provides a great way for PHP services to shrink the wire payloads compared to text based formats in order to serve data hungry iPhone apps over constrained connection speeds. Given the growth in machine readable formats across service offerings over the past couple years, coupled with the huge demand for data centric iPhone apps, it&amp;#39;d be interesting to see how common the various hydration approaches are in the market today.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;    &#xA;  &#xA;&#xA;</content></entry><entry><title>AJAX: Great Stuff, Why Now?</title><id>tag:aarondunnington.com,2013:aarondunnington.com/ajax-great-stuff-why-now</id><link rel="alternate" href="//aarondunnington.com/ajax-great-stuff-why-now"></link><published>2005-09-04T11:00:00+00:00</published><updated>2005-09-04T11:00:00+00:00</updated><author><name>Aaron Dunnington</name></author><summary type="html">Those into web applications have no doubt heard the buzz of late on &lt;a href=&#34;http://www.adaptivepath.com/ideas/essays/archives/000385.php&#34; target=&#34;_blank&#34;&gt;Asynchronous JavaScript and XML (AJAX)&lt;/a&gt;, an approach to web development that focuses on harnessing the existing client side processing capabilities of modern browsers. In short, a larger portion of web application code, typically JavaScript, can be downloaded to and executed on the client machine. Further, the client code leverages the &lt;a href=&#34;http://www.xml.com/pub/a/2005/02/09/xml-http-request.html&#34; target=&#34;_blank&#34;&gt;XMLHttpRequest&lt;/a&gt; object built in to most browser engines to communicate with the server in the background using XML and HTTP.&#xA;</summary><content type="html">&#xA;&#xA;  &#xA;  &#xA;    &#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Those into web applications have no doubt heard the buzz of late on &lt;a href=&#34;http://www.adaptivepath.com/ideas/essays/archives/000385.php&#34; target=&#34;_blank&#34;&gt;Asynchronous JavaScript and XML (AJAX)&lt;/a&gt;, an approach to web development that focuses on harnessing the existing client side processing capabilities of modern browsers. In short, a larger portion of web application code, typically JavaScript, can be downloaded to and executed on the client machine. Further, the client code leverages the &lt;a href=&#34;http://www.xml.com/pub/a/2005/02/09/xml-http-request.html&#34; target=&#34;_blank&#34;&gt;XMLHttpRequest&lt;/a&gt; object built in to most browser engines to communicate with the server in the background using XML and HTTP.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    The most compelling reason for using the AJAX technique is that it enables a more fluid user experience. In other words, the user is not constantly interrupted to jump to a new page. Thus, with the understanding that client processing is far less expensive than network communication, the AJAX approach allows web applications to behave more like desktop applications.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    As more and more code moves from server to client, however, intellectual property vulnerabilities may become an issue. Of course, this is very specific to the organization responsible for the application. If the organization is driving an open source effort or primarily focused on providing a service that is coupled to hosting infrastructure, exposing the client application may not be as much of an issue. On the other hand, if the corporate advantage resides in the client application, depending on customer audience, intellectual property exposures should be evaluated. Preventative measures can be taken through JavaScript obfuscation and potentially the future development of JavaScript security standards. Further, for very large applications, the amount of code downloaded to the client machine may pose interesting performance challenges. Could we use AJAX precepts to download more AJAX precepts?&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Overall, I am very excited to see the improvement of the user experience in web applications. One parting question: what has changed recently to cause the flurry of AJAX activity? Was it the acronym itself? These technologies have &lt;a href=&#34;http://blogs.msdn.com/dmassy/archive/2005/03/20/399412.aspx&#34; target=&#34;_blank&#34;&gt;been around since 1998&lt;/a&gt;. Why haven&amp;#39;t application infrastructures and tools been maturing over the years? Possibly more importantly, is there a technology out there now that will raise similar questions seven years from now?&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;    &#xA;  &#xA;&#xA;</content></entry><entry><title>Trailblazing Application Frameworks</title><id>tag:aarondunnington.com,2013:aarondunnington.com/trailblazing-application-frameworks</id><link rel="alternate" href="//aarondunnington.com/trailblazing-application-frameworks"></link><published>2005-06-16T11:00:00+00:00</published><updated>2005-06-16T11:00:00+00:00</updated><author><name>Aaron Dunnington</name></author><summary type="html">Developer productivity, or said another way, budget, is usually of paramount concern in the majority of business application projects. There are several application frameworks addressing this ubiquitous need for an increase in productivity in innovative ways. These frameworks, moreover, have been gaining considerable momentum and popularity. &lt;a href=&#34;http://rubyonrails.org/&#34; target=&#34;_blank&#34;&gt;Ruby on Rails&lt;/a&gt;, &lt;a href=&#34;http://www.springsource.org/&#34; target=&#34;_blank&#34;&gt;Spring Framework&lt;/a&gt; (as well as &lt;a href=&#34;http://www.castleproject.org/&#34; target=&#34;_blank&#34;&gt;Castle&lt;/a&gt;), and &lt;a href=&#34;http://www.zope.org/&#34; target=&#34;_blank&#34;&gt;Zope&lt;/a&gt; are a few such projects that I am very excited about.&#xA;</summary><content type="html">&#xA;&#xA;  &#xA;  &#xA;    &#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Developer productivity, or said another way, budget, is usually of paramount concern in the majority of business application projects. There are several application frameworks addressing this ubiquitous need for an increase in productivity in innovative ways. These frameworks, moreover, have been gaining considerable momentum and popularity. &lt;a href=&#34;http://rubyonrails.org/&#34; target=&#34;_blank&#34;&gt;Ruby on Rails&lt;/a&gt;, &lt;a href=&#34;http://www.springsource.org/&#34; target=&#34;_blank&#34;&gt;Spring Framework&lt;/a&gt; (as well as &lt;a href=&#34;http://www.castleproject.org/&#34; target=&#34;_blank&#34;&gt;Castle&lt;/a&gt;), and &lt;a href=&#34;http://www.zope.org/&#34; target=&#34;_blank&#34;&gt;Zope&lt;/a&gt; are a few such projects that I am very excited about.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    To start us out, Ruby on Rails, an open-source web application framework, unifies web development with a single language and particular assumptions about application architecture as well as coordination with an underlying model en leu of a proprietary architecture and verbose configuration files. As a result, Ruby on Rails drastically reduces coding time to create applications that process and move data around. Okay, at a this level, sounds like a magic bullet. Curt Hibbs has written a great introduction to Ruby on Rails that depicts just exactly how Ruby on Rails jives. Basically, by using certain naming conventions from relational model to object model (although this can be circumvented at the expense of a little more time), Ruby on Rails is able to automate persistence, object relationships, basic request processing, presentation, and validation. Lastly, Ruby is an interpreted, cross-platform language and the Ruby on Rails framework provides database drivers for the popular RDBMSs. Thus, Ruby on Rails provides an extremely productive programming environment that alleviates the developer from the minutia while staying decoupled from any particular platform.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Next, the Spring Framework and Castle project provide light-weight, container-based frameworks that rely on Inversion of Control (IoC) for Java and .NET, respectively. These two frameworks are very similar in their application of dependency injection and Aspect Oriented Programming (AOP). These concepts facilitate the testability and API neutrality of our code as well as allow us to flip switches for security, transactions, and the like. Furthermore, they are alike in that they both offer basic Model-View-Controller (MVC) get-ups that enable us to plug in different view components like Velocity and NVelocity. Spring and Castle both even allow the usage of different persistence engines, for example, Hibernate and NHibernate. Where these two outfits differ, however, is in their assumptions about domain model. This is where I believe that Castle shines. Whereas Spring relies on lengthy XML configuration files to direct Hibernate, Castle&amp;#39;s NHibernate provider is able to reflect upon the object model and automatically generate persistence configuration. This is a huge time saver. While tinkering with Castle, I sicked the ActiveRecord Generator on a database of approximately 200 tables and in a matter of minutes, I had a comprehensive, persistent object model. The code-reduction was quite impressive. All in all, these frameworks are very comparable, Castle leaning more towards a Ruby on Rails paradigm of assumptions. Of course, Spring and Castle are rooted in static languages; consequently, these frameworks are not quite as flexible and dynamic as Ruby on Rails. Yet, they have gotten quite close with reflection, AOP, and transparent proxy classes.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Last, we have Zope, a full-fledged application server written in Python. Unlike the previous frameworks, Zope relies heavily on an internal object database, or ODBMS. Several years ago, object databases were predicted to make a big splash; however, many would say that they never fulfilled this expectation. Well, Zope begs to differ. Python, like Ruby, is an interpreted, object-oriented language. This allows applications written towards the Zope framework to benefit from all the productivity gains of these pragmatic, dynamic approaches wherein the Linux Apache MySQL PHP/Perl/Python (LAMP) camp is very popular as well. Another effort that contributes to Zope&amp;#39;s promise is &lt;a href=&#34;http://www.erp5.org/&#34; target=&#34;_blank&#34;&gt;ERP5&lt;/a&gt;, an open-source enterprise framework built on top of Zope. The &amp;#34;5&amp;#34; in ERP5 stems from the ERP5 Universal Business Model which, at an abstract level describes business entities as Paths, Nodes, Movements, Items, and Resources. What has me so excited about the combination of these projects is ERP5&amp;#39;s design and usage of Zope&amp;#39;s foundation. Dr. Jean-Paul Smets, CEO of Nexedi, wrote &lt;a href=&#34;http://www.python.org/about/success/nexedi/&#34; target=&#34;_blank&#34;&gt;a great introduction on ERP5 and the interplay with Zope&lt;/a&gt; where he describes how they mitigated typical performance problems in the object-database world by indexing objects in a traditional relational database. The Zope application framework combines the pragmatic approach of Python with the elegance of an object database, and when used in concert with a relational database as an indexing facility, is extremely powerful. Performance of relational databases with no impedance mismatch. Now, that is pretty cool.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    To sum it up, Ruby on Rails, Spring, Castle, and Zope are all exploring new avenues for application development. Each with their unique approach to increasing developer productivity, I believe these frameworks are cultivating the foundation for the next generation of web applications. I would like to thank all that have contributed to these projects; I look forward to seeing how each project affects the way that we develop web applications.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;    &#xA;  &#xA;&#xA;</content></entry><entry><title>Web Services: Interoperable or Easy to Develop?</title><id>tag:aarondunnington.com,2013:aarondunnington.com/web-services-interoperable-or-easy-to-develop</id><link rel="alternate" href="//aarondunnington.com/web-services-interoperable-or-easy-to-develop"></link><published>2005-06-14T11:00:00+00:00</published><updated>2005-06-14T11:00:00+00:00</updated><author><name>Aaron Dunnington</name></author><summary type="html">The World Wide Web Consortium (W3C) &lt;a href=&#34;http://www.w3.org/2002/ws/Activity&#34; target=&#34;_blank&#34;&gt;defines&lt;/a&gt; Web Services as a &amp;#34;standard means of interoperating between different software applications.&amp;#34; Well, that is pretty cool. If only we, the industry, could do that.&#xA;</summary><content type="html">&#xA;&#xA;  &#xA;  &#xA;    &#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    The World Wide Web Consortium (W3C) &lt;a href=&#34;http://www.w3.org/2002/ws/Activity&#34; target=&#34;_blank&#34;&gt;defines&lt;/a&gt; Web Services as a &amp;#34;standard means of interoperating between different software applications.&amp;#34; Well, that is pretty cool. If only we, the industry, could do that.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Some really bright guys at HP, Steve Loughran and Edmund Smith, recently authored an article entitled &amp;#34;Rethinking the Java SOAP Stack.&amp;#34; Basically, they suggest, with quite sound evidence, that the current Web service stacks have failed to realize what Web services set out to do in the first place, that is, interoperate. Many current Web service stacks (emphasis on SOAP) take this great idea of Service Oriented Architecture and bastardize it by applying classic middleware approaches.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Steve and Edmund do a great job at depicting how we are currently experiencing an impedance mismatch from message (documents) to objects much like we see in the relational database to object mapping world. In short, these really great, flexible technologies like XML and XML Schema are shoved onto OOP. Since XSD and WSDL are at the very least mildly unpleasant to write by hand, the Web service stacks try to help us by making assumptions about document to object mapping. As a result, we as programmers are spared the details of schema and WSDL; however, the framework just serialized a definition of some platform specific data type:-) Now, that won&amp;#39;t be very pleasant in another world.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    So, Steve and Edmund accurately point out that what we are left with is a brittle, constrictive approach (much like RMI, Remoting, etc) to some great open, interoperable standards. How did that happen?&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Enter Alpine. The HP crew suggest a lightweight SOAP stack that is only a SOAP stack. By delegating the mapping to the user application, the framework imposes no blanket assumptions about mapping. The caveat, we have more work to do with XML. But, at least, in theory, Alpine will get closer to that interoperable thing that Web services are supposed to do.&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Okay, so now some questions:&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Why are objects so hard to map to? Impedance. Are our modern-day programming languages in need of some rethinking (in particular, message documents and relational models sort of throw a wrench into OOP when a mapping paradigm is used)? Are SOA concepts creeping into OOP? How could we express SOA better in a high-level language like Java or C#? I mean annotations (and attributes) are great; but, are they really the answer to making services easier to deal with? Personally, I think Steve and Edmund are right; we should suck it up and do contract-first development and work with message objects until there is a better form of expression for services. But, what and when will that form of expression be?&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;        &#xA;  &#xA;  &lt;p&gt;&#xA;    Thanks Steve and Edmund; I look forward to hearing more about Alpine!&#xA;  &lt;/p&gt;&#xA;  &#xA;&#xA;      &#xA;    &#xA;  &#xA;&#xA;</content></entry></feed>