Giter Club home page Giter Club logo

spray-example's Introduction

Simple Example with Spray, Akka, and Squeryl

The basic setup is from the valuable spray template. The example covers

  • REST-Services with Spray
  • an event-driven architecture based on Akka
  • persistence with squeryl
  • Testing with Specs2

Structure

The project layout is corresponding to the classic maven style directory structure. All source code is located in src/main/scala and src/test/scala, respectively.

The source code is organized in the following packages:

  • api: The rest service stuff, i.e. definition of routes, Json marshallers
  • core: the rest agnostic business logic: message objects, operations
  • domain: the domain model as case class(es)
  • database: Squeryl schema definition, database configuration

Basic data flow

  1. a Request hits the defined routes in the webservice actor
  2. the Request is converted to a message object
  3. An intermediate Actor is created per request to handle the completion of the request (pre request pattern)
  4. the Message object is passed to the business logic actor via the per request Actor
  5. the business logic actor mainly triggers the database interaction
  6. the resulting data is passed back to the per request actor which completes the request

Performance

Performance and stability are pretty hard achieve in this setup. First I implemented the ask pattern, but the system crashed under heavy load. That is not tolerable in any serious system. Fiddling with akka settings doesn't help (or I couln't figure out how to configure everything correctly).

Then I switched to the pre request pattern. That solved the performance and stability problems for me as the blocking part of the system is encapsulated in a separate Actor per request. The overall performance is quite good now. Reading access gets up to 2000 req/s on a i5, which is quite nice.

TODO

Testing is broken right now.

Building

The project is built using sbt. Use

sbt gen-idea

to create Idea project files.

License

The project is released under the MIT license.

spray-example's People

Contributors

rguderlei avatar

Watchers

James Cloos avatar Makis Arvanitis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.