Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement http client for mruby handler #637

Merged
merged 39 commits into from
Dec 27, 2015
Merged

implement http client for mruby handler #637

merged 39 commits into from
Dec 27, 2015

Conversation

kazuho
Copy link
Member

@kazuho kazuho commented Dec 23, 2015

Still WIP.

As discussed in http://blog.kazuhooku.com/2015/11/mruby.html, by running the Rack application in a fiber context it is possible to return execution context to the event loop of h2o when a ruby method is called from the application.

This PR adopts the approach and will implement a HTTP client that can be called from the mruby handler. The feature will allow users to develop sophisticated reverse proxy on H2O (see #565).

@kazuho kazuho added this to the v1.7 milestone Dec 23, 2015
@kazuho
Copy link
Member Author

kazuho commented Dec 23, 2015

At 66677d3, the performance of a minimal Rack application decreased from 77,000 reqs / sec. to 68,000 reqs / sec. due to the overhead of context switch (between fibers).

@kazuho kazuho force-pushed the kazuho/mruby-fiber branch from 66467c4 to f48b355 Compare December 23, 2015 06:32
@kazuho
Copy link
Member Author

kazuho commented Dec 24, 2015

With commit e2f6d9e, it is now possible to write a mruby handler like below that issues HTTP requests. And the HTTP request issued by http_request method does not block the event loop of H2O.

mruby.handler: |
  Proc.new do |env|
    # return response from example.com
    http_request("GET", "http://example.com/#{env["PATH_INFO"]}")
  end

(note: snippet update to reflect latest commit)

ToDo:

  • accept headers passed to http_request method
  • pass request body to mruby handler in a way that can be passed effectively to the http_request method (relates to mruby: support env[rack.input] #515)
  • separate timeout for http_request?
  • find a way to handle 399 response returned after async calls
  • add tests

@kazuho kazuho force-pushed the kazuho/mruby-fiber branch from 5940c74 to e2f6d9e Compare December 24, 2015 05:13
@kazuho kazuho force-pushed the kazuho/mruby-fiber branch from b273cd7 to a077740 Compare December 24, 2015 21:42
@kazuho kazuho force-pushed the kazuho/mruby-fiber branch from c26d84c to a6b6dfb Compare December 27, 2015 18:24
kazuho added a commit that referenced this pull request Dec 27, 2015
implement http client for mruby handler
@kazuho kazuho merged commit 63fddde into master Dec 27, 2015
@kazuho kazuho mentioned this pull request Dec 27, 2015
15 tasks
kazuho added a commit that referenced this pull request Feb 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants