Skip to content

Add http client pool #25

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

Merged
merged 5 commits into from
Aug 5, 2016
Merged

Add http client pool #25

merged 5 commits into from
Aug 5, 2016

Conversation

joelwurtz
Copy link
Member

@joelwurtz joelwurtz commented Jul 22, 2016

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets fixes #8
Documentation php-http/documentation#134
License MIT

Add a Http Client Pool as discussed in #8


return $response;
}, function ($exception) {
$this->disable();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this is a good idea. it could mean that flaky backends would lead to random client objects being disabled over time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, found the reenable. but still, is your assumption that one client stops working while others continue to work? as this is not multithread or multiprocess code, i don't expect this to be a relevant use case.

or is the idea to use a bunch of clients to do round robin on the client to different instances of the same server application rather than on a load balancer in front of the servers?

Copy link
Member Author

@joelwurtz joelwurtz Jul 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or is the idea to use a bunch of clients to do round robin on the client to different instances of the same server application rather than on a load balancer in front of the servers?

Yes

Having this can remove SPOF from application, as every request / frontend / command act as load balancer, and not only one process

In fact this is something which his already existing in the elasticsearch-php, as my goal is to propose a solution to integrate httplug into their lib this will allow them to completly remove their code about http client and only relying on us.

Also i think this make sense as elasticsearch is not a exclusive solution using cluster mecanism.

@dbu
Copy link
Contributor

dbu commented Jul 25, 2016

the implementation looks sane enough to me. i am not sure if one is supposed to do this - i thought with ES the idea is you talk to the cluster and ES does heal itself and make sure one of its nodes is responding. if you are writing, this could even create a huge mess if the ES node runs into a split brain - you would then write to both halves...

*/
class HttpClientPoolItem extends FlexibleHttpClient
{
/** @var int Number of request this client is actually sending */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/actually/currently/ ?

@joelwurtz
Copy link
Member Author

joelwurtz commented Jul 29, 2016

the implementation looks sane enough to me. i am not sure if one is supposed to do this - i thought with ES the idea is you talk to the cluster and ES does heal itself and make sure one of its nodes is responding. if you are writing, this could even create a huge mess if the ES node runs into a split brain - you would then write to both halves...

It depends on your configuration, in our projects we mainly set all nodes to be master with data to have a real cluster and also always make sure that if a node fail the system is still responding.

Having one master fail to this principle, as if the master node is down the entire application is down, it's the same if we put a load balancer in front of elasticsearch as the SPOF will be on the loadbalancer. By directly load balancing into the code we are sure that they will never be a SPOF between our application and the elasticsearch cluster.

});

if (0 === count($clientPool)) {
throw new HttpClientNotFoundException('Cannot choose a http client as there is no one present in the pool');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just force-use a disabled client in this case rather than do a hard failure? it would reduce the time we have problems if the backend went away for a short time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done by setting 0 on the http client pool item

} catch (Exception $e) {
$this->disable();
--$this->sendingRequestCount;
$this->decrementRequestCount();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we where using php 5.5 only, we could use finally for this. but we are on 5.4 it seems :-(

@dbu
Copy link
Contributor

dbu commented Aug 3, 2016

can you add an entry to the changelog please?

apart from that looks ready to me.

@sagikazarmark
Copy link
Member

Sorry for not being active in this one. I am happy to merge when there is a change log entry.

@dbu dbu merged commit 55822ba into master Aug 5, 2016
@dbu dbu deleted the http-client-pool branch August 5, 2016 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HttpClientPool
4 participants