3 ms·
I was the original author of this gem, so it is nice to see it here on HN, I have since passed it on the the caring hands of Semaphore since they wanted to main
by kawsper 9y ago
I was the original author of this gem, so it is nice to see it here on HN, I have since passed it on the the caring hands of Semaphore since they wanted to maintain and improve it :-)
The software was built for a forum where the admin buttons was only for specific users, but the rest of the frontend was the same, so we used render_async to render some content for some users, and other content for admins, and the rest of the page could be cached statically.
We later changed it to use edge side includes with Varnish. An example of this is where you add the to your HTML:
<esi:include src="http://example.com/1.html" alt="http://bak.example.com/2.html" onerror="continue"/>
This will make Varnish fetch the URL(s), assemble the page and present it to the client, so your backend might see more requests, but the client only sees one.
- ksec 9y agoSo you are suggesting using a front end cache server like Varnish is better then what you originally programmed for?
- kawsper 9y agoIt depends - Varnish is great, but in case of error-handling I think it is better to handle that with JavaScript, so you can retry, and you avoid that a timeout or slowdown doesn't block your clients. On the other hand, I really like to just throw HTML at the user without involving asynchronous JavaScript.
- gingerlime 9y agoIt's an interesting approach. It's only async from the client perspective though. Right? The server still processes the action/render inline? (i.e. it's not spawning a sidekiq process as far as I can tell). We recently implemented something that's async on the server, using a combination of pusher and sidekiq. This was particularly useful for cases where we access an external API and don't want to hold the unicorn process for too long. So when the response comes back we push it back to the client and display it. Would be interesting to maybe combine this approach with some server-push and background workers and what this gem is doing.
- kawsper 9y agoRender-async lets the client render the page, and then request "partials" from the server, the backend sees two different requests from the browser The inline includes that Varnish does is synchronous for the client, but asynchronous in your backend, your backend sees multiple requests. I am interested in your pusher+sidekiq implementation, it is a good idea, but it might be a lot of work :)
- gingerlime 9y agoIt's definitely more involved, and might be slightly more complex to generalize, but in essence it's quite straight-forward: 1. Client sends a request via Ajax to a rails controller and simultaneously opens a private pusher channel to wait for a response. 2. Controller returns a response immediately and fires-off a sidekiq job. 3. The sidekiq job does the heavy lifting and pushes the results back via pusher (it can be JSON data, or a rendered partial). 4. Client receives the response via the pusher channel and shows it on the page.
- matthewmacleod 9y agoThat's a good use-case!