Richard Searle's Blog

Thoughts about software

Archive for the ‘play’ Category

Play as an ESB

Posted by eggsearle on July 31, 2013

Back in 2007 Mark Nottingham suggested squid could serve as an ESB , which was probably considered a rather radical idea.  Certainly I never came across any further references to the concept.  This recent Play blog post  triggered my recollection of that half decade old idea.

It has many functions that one might expect from an ESB:

  1. Caching
  2. Rate limiting (via timeouts and return codes)
  3. Proxying (via REST call to external service)
  4. Data conversion (http response to json)

The sample is compact, easily understand and easily extended via composition. (characteristics that are rarely encountered using the big name ESBs)

 

 

 

 

Advertisements

Posted in play, Scala | Leave a Comment »

Play 2 Server Sent Events and Ajax performance

Posted by eggsearle on October 20, 2012

Consider a “dumb client” Single Page App where the domain logic resides on the server.
The UI events are delivered via Ajax, with the server responses flowing over SSE to update the UI.
This minimizes the size of Javascript code while (hopefully) retaining the responsive interaction.

The key question is thus latency and server load.

A simple experiment wires an Ajax call to the SSE event handler, where the call delivers a new data element over the SSE connection, forming an infinite loop.
That provides a simple measurement of the total request/response chain.

Both Play 2 and Jetty Continuations based implementations were tested, using Fedora Core 17, Google Chrome running on AMD Phenom II X6 1100T.

Implementation latency (ms) CPU Load (%) JRE Load (%)
Play 16 52 7
Jetty 12 5 1

CPU Load is reported by top and JRE Load by JConsole.

Play uses Iteratees and NIO, which are both designed for concurrency rather than raw throughput.
A 10x difference is a surprising high cost to pay for the concurrency and expressiveness of the Play API.

The proposed user case would have less than a score of clients, which would be feasible even with a vanilla block Servlet implementation.

Posted in play, Scala | 4 Comments »

Surprises with call-by-name and unary functions

Posted by eggsearle on March 27, 2012

I recently created a subtle defect while using the Play2 enumerators

Both  pushee and fromCallback are passed an onComplete that is executed when the target Iteratee can no longer accept any input. The signatures are slightly different

pushee:onComplete: ⇒ Unit
fromCallback:onComplete: () ⇒ Unit

I did not notice the difference and used {() => println("completed")} in each case. That prints the expected output for fromCallback but is not executed for pushee. The compiler does not generate any errors, making this a completely silent failure. Thanks to sadek for pointing out my error.

The next step was to gain a better understanding of this corner of the Scala language

def f(a: => Unit){a}
def g(a:() => Unit){a()}
def h(a: => String)={a}
def i(a:() => String)={a()}

f{println("1")}
f{() => println("2")}
g{() => println("3")}
println(h{"5"})
println(h{()=>"6"})
println(i{() => "7"})

The result is
1
3
5
<console>:9: error: type mismatch;
found : () => java.lang.String
required: String
println(h{()=>”6″})
^
7

So there is something special about () => Unit

Posted in play, Scala | Leave a Comment »