
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
rails-threaded-proxy
Advanced tools
Asynchronous high throughput reverse proxy for rails
Warning: experimental. Use at your own risk.
Rails concurrency is often limited to running many processes, which can be memory-intensive. Even for servers that support threads, it can be difficult running dozens or hundreds of threads. But you may have backend services that are slow to respond, and/or return very large responses. It is useful to put these services behind rails for authentication, but slow responses can tie up your rails workers preventing them from serving other clients.
rails-threaded-proxy
disconnects the proxying from the rack request/response cycle, freeing up workers to serve other clients. It does this by running the origin request in a thread. But running in a thread is not enough: we need to be able to respond to the rails request, but rack owns the socket. So it hijacks the request: rack completes immediately but dissociates from the socket. Then we're free to manage the socket ourselves. Copying between sockets, we can achieve high throughput (100MB/s+) with minimal CPU and memory overhead.
class MyController
include ThreadedProxy::Controller
def my_backend
proxy_fetch "http://backend.service/path/to/endpoint", method: :post do |config|
config.on_headers do |client_response|
# override some response headers coming from the backend
client_response['content-security-policy'] = "sandbox;"
end
end
end
end
Tested with Rails 7, but probably works in Rails 6+. Needs an application server that supports rack.hijack
. (only tested on https://puma.io/ so far)
Inspired by https://github.com/axsuul/rails-reverse-proxy, and tries to use similar API structure where possible. If you don't care about the specific benefits of rails-threaded-proxy
, you should consider using rails-reverse-proxy
instead.
See LICENSE
FAQs
Unknown package
We found that rails-threaded-proxy demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.