The Parallel Universe Blog

January 22, 2014

Introducing COMSAT and the Parallel Universe Stack

By Ron

Today we are happy to announce the launch of our latest open source product: COMSAT. COMSAT, or Comsat, is a set of libraries that help you develop fast and scalable web applications while continuing to use popular and standard APIs. To achieve this, Comsat integrates common JVM web technologies with Quasar, so before we explain what Comsat is exactly, let’s go back for a second and explain what Quasar is.

What’s Quasar?

Quasar is a library that adds true lightweight threads to the JVM. Lightweight threads, or fibers, are like regular threads, except they consume far less resources, and are able to task-switch much faster than plain Java (OS) threads. You can easily have hundreds of thousands, or even millions of running fibers on one JVM instance.

What are fibers good for? They allow you to enjoy the performance and scalability (across cores) of asynchronous, callback based, code, while keeping the natural, simple and intuitive blocking style of threaded code. Quasar includes various constructs for inter-fiber communication, including channels for CSP-style programming (just like those in the Go language). On top of this core, Quasar provides a full Erlang-like actor system, complete with behaviors, supervisors and selective receive, as well as distribution across a cluster.

Quasar also has a Clojure API, called Pulsar, that closely mimics Erlang functionality.

Today we are also releasing Quasar (and Pulsar) version 0.4.0, which includes hot code swapping and channel transformations (AKA “reactive extensions”).

So What’s Comsat

Java web or enterprise APIs have traditionally used thread-blocking operations: JDBC is blocking, Servlets assign one thread per request etc.. This style makes code simple, as program flow is easy to follow and understand, but it hinders scalability. Beyond a few thousand threads system performance deteriorates, usually while there’s still plenty of CPU to spare, and often long before IO bandwidth is saturated. This can easily happen when users pile up or when HTTP requests take longer than a couple of seconds to complete.

In the last few years, Java web APIs have added support for asynchronous usage: you’ve got async servlets, async JAX-RS (REST) resources, async HTTP clients etc.. But while this helps exploit system resources to their fullest, application code becomes much harder to follow. Not only that, this coding style introduces concurrency bugs much more easily.

Comsat uses Quasar’s ability to transform any callback-based, asynchronous API into fiber-blocking calls, and applies it to Java’s web technologies. Quasar uses the same familiar and simple blocking APIs, but turns them from (OS-)thread-blocking to fiber-blocking; under the hood, the scalable but more obtuse async APIs are used. Comsat gives you the best of both worlds: familiar, simple blocking APIs, with the scalability of callbacks.

Comsat Modules

Comsat is comprised of a number of modules, each implementing a single standard Java API:

  • comsat-servlet – each HTTP request runs in its own fiber, rather than a thread. This means you can have many tens-of-thousands of concurrent requests without latency suffering.
  • comsat-jersey-server – run REST requests (JAX-RS) in fibers.
  • comsat-jdbc – fiber-blocking JDBC
  • comsat-jax-rs-client - a very fast fiber-blocking HTTP client (based on JAX-RS client, AsyncHttpClient, and Jetty Client).

Currently, only direct JDBC calls are supported, but we plan on adding integration for JDBI and/or jOOQ. Support for more complex ORM frameworks (JPA) is not currently planned. We do, however, plan to support popular NoSQL databases.

Web Actors

So far we mentioned the standard APIs Comsat implements, but Comsat adds an additional, optional API: Web Actors. Web Actors let you write web services using the actor model, which feels very natural particularly for interactive applications. All communication to and from the client is modeled as messages passed between actors. Web Actors have especially nice support for WebSockets and SSE (Server-Sent Events).

Because Quasar now supports hot code swapping for actors, if you choose to use Web Actors, you’ll gain the ability to modify your application code at runtime.

Here’s an example of a Web Actors application that communicates with plain HTTP requests, WebSockets and SSE.

What’s Ahead

We want Comsat to integrate smoothly with most popular JVM web technologies. We intend to integrate with Spring. We will support Clojure’s Ring, and then frameworks for additional JVM languages (probably Ruby’s Sinatra).

The Parallel Universe Stack

With the addition of Comsat, Parallel Universe now provides a complete server-side stack, with Comsat at the web layer, Quasar for the application logic, and Galaxy for clustering and fault tolerance. SpaceBase, along with a future similarly highly-concurrent, though non-spatial database called Dark Matter, form the database layer. The Parallel Universe stack is intended to help you write performant, highly scalable, and fault tolerant software, that takes full advantage of modern multi- and many-core hardware, while at the same time emphasizes a simple programming model.

With CPUs no longer getting (much) faster, taking full advantage of modern hardware is one of the biggest challenges facing modern software development, and we intend help. We favor adopting well proven APIs where applicable and working hand-in-hand with other technologies we think are suitable to face this challenge.

Get Started Now

Comsat, like Quasar, Pulsar and Galaxy, is free software and can be found on GitHub. You can read the Comsat documentation here, and, perhaps most importantly, check out the Comsat examples.

Join our mailing list

Sign up to receive news and updates.

Tags: ,

comments powered by Disqus