Page MenuHomePhabricator

Asynchronous requests: Use Hack's curl_multi_await() in Elastica extension
Closed, InvalidPublic

Description

Search results could be delivered to the user more quickly if instead of blocking on the HTTP request to ElasticSearch, we make the request asynchronous, and proceed to do whatever work is still pending and not contingent on the response (such as building the user interface).

Because Elastica is an extension, and because it supports pluggable ElasticSearch middleware, it is a viable place in our stack to experiment with Hack. The impact could be substantial.

See http://docs.hhvm.com/manual/en/function.hack.curl-multi-await.php

Event Timeline

ori raised the priority of this task from to Needs Triage.
ori updated the task description. (Show Details)
ori added subscribers: ori, EBernhardson.
ori set Security to None.
ori added a subscriber: GWicke.

Elastica is an upstream library: http://elastica.io/

Yes, but the Elastica extension (which extends the Elastica library) is not: http://www.mediawiki.org/wiki/Extension:Elastica

Legoktm renamed this task from Use Hack's curl_mutli_await() in Elastica to Use Hack's curl_mutli_await() in Elastica extension.May 20 2015, 1:13 AM
Legoktm removed a project: Upstream.

I don't know if this will be directly possible without heavy refactoring of the upstream Elastica library and the SpecialSearch page.

When you use async/await in a function that function now returns Awaitable<T> instead of whatever it was returning previously. In this case we would probably extend Elastica\Transport\HttpTransport to override the exec() method, but then that method returns an Awaitable<Elastica\Response>, rather than an Elastica\Response directly. All of the functions in the stack between our calling code and the AbstractTransport then also need to become async, awaiting on the async method they call. To generate the interface while this async code is working, the code that generates the interfaces also has to be marked async. It doesn't have to be async IO, it can simple give up to the async scheduler via await RescheduleWaitHandle::create(0, 0); There isn't a ton of interface to be drawn though, with the exception of the skin. But the skin is the last thing to be drawn and would also have to be made async.

In a short talk with one of the hhvm developers, they suggested there should be a single Awaitable::join() call in the entire application at the top level. In short, my limited understanding of async in hhvm is that it is very invasive, everything you want to do at the same time has to be async and converted to hacklang (if only superficially). The amount of interface drawn in SpecialSearch is pretty minimal, I'm not sure it would be a big win here.

I should add it's not really the Elastica library changes that will be particularly hard, although it can't be done nicely with inheritence. For the most part that is just adding async and await keywords in all the right places. More difficult will be that the core SearchEngine and SpecialSearch also have to be converted to hacklang and made await/async aware. This is because CirrusSearch isn't responsible itself for any of the interface that is being drawn.

I did some investigation over the weekend, performing a (mostly broken) port of the Elastica client library to use hacklang and async/await. The (mostly broken) code for that can be found on my github[1]. This is mostly a proof of concept, if we wanted to move forward i would need to spend several more days just getting all the tests to pass for this async version of Elastica.

[1] https://github.com/ebernhardson/Elastica/tree/async

Deskana triaged this task as Medium priority.Sep 9 2015, 2:43 AM
Deskana subscribed.
EBernhardson renamed this task from Use Hack's curl_mutli_await() in Elastica extension to Asyncronous requests: Use Hack's curl_mutli_await() in Elastica extension.Sep 9 2015, 7:23 PM
EBernhardson added a project: CirrusSearch.
Gilles renamed this task from Asyncronous requests: Use Hack's curl_mutli_await() in Elastica extension to Asyncronous requests: Use Hack's curl_multi_await() in Elastica extension.Sep 9 2015, 7:58 PM
Deskana renamed this task from Asyncronous requests: Use Hack's curl_multi_await() in Elastica extension to Asynchronous requests: Use Hack's curl_multi_await() in Elastica extension.Sep 9 2015, 9:06 PM