On 15/07/13 21:42, Brad Orego wrote:
> Best Practices typically refer to what the standard way of doing things
> within the language/framework are. It shouldn't be application dependent,
> and should guide the way to write and structure code.
>
> Basically what we're doing right now is we declare one HttpClient object
> globally ("gnClient =
> vertx.createHttpClient().host(container.config.api_host).port(container.config.api_port)") and
> then reuse it throughout the server.js file, sometimes sending multiple
> requests per RouteMatcher match function.
Do you mean you are creating one instance of the Http Client per
JavaScript verticle? A code example would be useful here...
How many instances of your verticle are you creating?
What pool size are you using?
>
> What we've found so far is that without explicitly closing the client
> within the RouteMatcher functions,
If you have a single instance of the http client per verticle, and you
close it in a routematcher function, then it's going to closed, and not
usable for any more requests. This doesn't make sense to me. But, again,
without seeing any code it's hard to know what you are actually doing.
> it's slower and tends to hang more
> readily, but even with explicit (maybe even overzealous) client closing, we
> can get the system to hang if it sits idle for a period of time.
I don't see how anything would work if you have an instance of the
client per verticle and you close it after every request.
>
> What happens when it hangs is that all of the server-side code is fine
> (e.g. routes match properly, execution within the RM function is fine), but
> none of the outgoing HTTP requests come back from the external API
> (gnClient.get's callback never executes).
If you have a non closed client and you aren't seeing responses from
requests that implies the servers you're talking to aren't sending back
responses.
>
> As I said, I can show you snippets, but I'd much rather there be some way
> to already know if what we're doing is wrong and can fix it ourselves.
Without seeing code, we're just playing 20 questions. It's a fun game
but unlikely to be the best way to resolve the problem ;)
By far the best way to resolve this would be to create the simplest
possible test case that demonstrates the issue and show it to us (you
can send it to me privately if you prefer) :)