2

I need a a simple webserver which parses the url it receives, calls som other ruby scripts which do some heavy processing and thereafter return the resulting JSON.

Is Goliath appropriate for this? As far as I can see the requests are being handled sequentially. What should I do to get this right?

class MyServer < Goliath::API
  def response(env)
    res = create_json_response(env["REQUEST_URI"])
    [200, {}, res]
  end
end
dj2
  • 9,534
  • 4
  • 29
  • 52
user1204271
  • 131
  • 1
  • 4

1 Answers1

4

Take a look at the "echo" example for a more complete example: https://github.com/postrank-labs/goliath/blob/master/examples/echo.rb

Goliath intentionally makes you build up your stack and tries to assume little by default - this gives you the flexibility of optimizing the stack, at a cost of some upfront setup.

The requests are handled "sequentially" in a sense that they're served from an event-loop. If you're blocked on IO, goliath will begin processing the next request. But, if you decide to do CPU intensive computation for a while, then you'll block the reactor. In other words, this is exactly the same behavior as any other "evented" framework (node, etc).

If you do need to do some heavy CPU processing, then you should spin out that work to a work queue or a dedicated worker.

igrigorik
  • 9,433
  • 2
  • 29
  • 30