● Brief Description on:
6. Node.JS vs EM
● Grape_Goliath Gem and Usage
● REST-like API micro-framework for
● Designed to run on Rack or
complement existing web application
● Grape APIs are Rack applications
that are created by subclassing
● No need of rails to create simple
● Grape allows you to build lightweight
APIs with Ruby when you don't need
the heavy lifting power of large
frameworks like Rails.
● Non-blocking Ruby web server
● Serves to requests using a
● Uses a Fiber to process a request.
5. Significance of Goliath
● Bare metal performance
● Rack API and middleware support
● Simple configuration
● Fully asynchronous processing
● Readable and maintainable code
6. Goliath Advantage
● Major advantage over other frameworks is
that by leveraging Ruby fibers introduced
in Ruby 1.9+, it can untangle the
complicated callback-based code into a
● Linear execution, leads to more
maintainable and readable code.
● Each HTTP request within Goliath is
executed within its own Ruby fiber and all
asynchronous I/O operations can
transparently suspend and later resume
the processing without requiring the
developer to write any additional code.
● Both request processing and response
processing can be done in fully
streaming uploads, firehose API's,
request/response, websockets, and so on.
8. Goliath compared to
other servers like Thin
● Goliath is able to run on different Ruby
● It uses a different HTTP parser, supports
HTTP keepalive & pipelining.
● Offers a fully asynchronous API for both
request and response processing.
● Goliath claims to works its magic by
“leveraging Ruby fibers introduced in Ruby
● Fibers are primitives for implementing light
weight cooperative concurrency in Ruby.
Basically they are a means of creating
code blocks that can be paused and
resumed, much like threads.
● The main difference is that they are never
preempted and that the scheduling must
be done by the programmer.
● EventMachine is an event-driven I/O and
lightweight concurrency library for Ruby.
● It provides event-driven I/O using the
Reactor pattern, much like JBoss Netty,
Apache MINA, Python's Twisted, Node.js,
libevent and libev.
11. EM Significance
● Extremely high scalability, performance and
stability for the most demanding production
● An API that eliminates the complexities of
high-performance threaded network
programming, allowing engineers to
concentrate on their application logic.
● This unique combination makes
EventMachine a premier choice for critical
networked applications, including Web
servers and proxies, email and IM production
processors, and many more.
12. EventMachine Usage
● Scalable event-driven servers. Examples:
Thin or Goliath.
● Scalable asynchronous clients for various
protocols, RESTful APIs and so on.
Examples: em-http-request or amqp gem.
● Efficient network proxies with custom
logic. Examples: Proxymachine.
● File and network monitoring tools.
Examples: eventmachine-tail and logstash.
● Primitives for implementing light weight
cooperative concurrency in Ruby.
● They are never preempted and that the
scheduling must be done by the
programmer and not the VM.
● Small 4KB stack enables it to be paused
from deeply nested function calls within
the fiber block.
● Run using the Fiber#resume method. The
code running inside the fiber can give up
control by calling Fiber.yield.
14. Client Example
15. Server Example
16. Node.JS vs EM
17. Pros and Cons
● Clever DSL
● Also Fast
● Its Ruby
● Restricted EM Libraries.
● More difficult to write
than normal ruby.
● Shared Code
● Lightning Fast
● Callback Hell
● Less Mature.
18. EventMachine Better
● EventMachine’s concurrent processing
ability is stronger than Node.js 50%.
● When request number goes up, Node.js’s
connection rate goes down.
19. Gem Grape_Goliath
Gem which creates an application with
tree structure specified for a Goliath
application having Grape API framework.
● Included Gems in tree structure :
grape, goliath, em_synchrony
● Added dependencies of rubigen included.
20. Basic tree structure
21. Important Gems Used
● A framework to allow Ruby applications to
generate file/folder stubs.
● RubiGen will be normally integrated into
another RubyGem, such as newgem, rails or
● Here we have used newgem.
● Quickly bundle any Ruby libraries into a
RubyGem and share it with the world.
● There are two types :
1. Application generators – Used by
developers for the framework to get started.
Generally used to generate a basic stub
2. Component generators - Used by
developers to extend their application.
● Here we have used application generator for
basic goliath app tree structure generation.
● Application generator for the gem.
● Its manifest method includes the
directories that are to be created and the
files that should be inlcuded in the tree
● The files that should get added with
specified code are to be included in the
templates folder in the path
● grape_goliath application_name
● cd application_name
● bundle install (To install all dependencies)
● ruby server.rb -vs (To run the Goliath server)
● For further info visit: