Skip to content

Reuse LBClient to avoid duplicate servo registrations#187

Closed
bstick12 wants to merge 1 commit into
OpenFeign:masterfrom
bstick12:issue-182-noguava
Closed

Reuse LBClient to avoid duplicate servo registrations#187
bstick12 wants to merge 1 commit into
OpenFeign:masterfrom
bstick12:issue-182-noguava

Conversation

@bstick12

Copy link
Copy Markdown
Contributor

issue #182 found that the default configuration of servo does static registration for each LBClient instance. This creates problems at runtime. The solution proposed here is to avoid duplicating LBClient instances by caching them.

@cloudbees-pull-request-builder

Copy link
Copy Markdown

NetflixOSS » feign » feign-pull-requests #55 SUCCESS
This pull request looks good

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: always linkedhashmap
Discussed in the past, but this has consistent ordering which costs almost nothing. when tests are written and/or JREs switch, this pays dividends.

@codefromthecrypt

Copy link
Copy Markdown

Nice, brendan. I think this is ready for tests.

@codefromthecrypt

Copy link
Copy Markdown

once this is all tidy, squash and rename the commit to something like..

Reuses LBClient

Ribbon does not expect multiple LBClient instances for the same client. This
introduces a cache to avoid redundantly creating them.

closes #182

@codefromthecrypt codefromthecrypt mentioned this pull request Feb 18, 2015
Ribbon does not expect multiple LBClient instances for the same client. This
introduces a cache to avoid redundantly creating them.

closes OpenFeign#182
@cloudbees-pull-request-builder

Copy link
Copy Markdown

NetflixOSS » feign » feign-pull-requests #57 SUCCESS
This pull request looks good

@bstick12

Copy link
Copy Markdown
Contributor Author

@adriancole Changes for #182 and #183 should done now. Could these be merged back to the 7.x?

@codefromthecrypt

codefromthecrypt commented Feb 19, 2015 via email

Copy link
Copy Markdown

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

change from volatile to final. final ensures threads can see this. volatile isn't needed as we aren't changing the reference, rather the contents.

@codefromthecrypt codefromthecrypt changed the title Fix for Issue 182 with Guava removed and using non static map Reuse LBClient to avoid duplicate servo registrations Feb 19, 2015
@codefromthecrypt

Copy link
Copy Markdown

Pinging spring cloud folks for a second opinion. @philwebb @spencergibb @dsyer

So, here's the deal. Brendan hunted through ribbon stack traces and found that each time a LBClient is created, a call to this static beauty ends up happening.

Monitors.registerObject("Client_" + clientName, this);

With default config, there's a race possible leading to an exception.

The attached code caches the LBClient. Since Monitors.registerObject ends up doing static singleton things, the right cache scope seems also to be static singleton. That implies locking, etc. but then again a lot of ribbon is as well.

So, point is this.. do you see any issue merging this code w/notes? Or do you think it is better to punt and say "don't use the default servo registration"? Or do you think there's another solution?

@dsyer

dsyer commented Feb 19, 2015

Copy link
Copy Markdown
Contributor

I don't think we use RibbonClient in Spring Cloud (we duplicate some of it to provide a load balancer to our own Feign client, but we don't register anything in Servo), so I doubt this will affect us much directly. Of course there's nothing to stop users grabbing the native Feign configuration/factories instead of the ones we provide, so anything that improves things is good.

The only alternative approach I can think of would put the cache and locking in Servo, and give monitor clients the option to obtain the current object by name if it already exists.

I can see calls to Monitors.registerObject() elsewhere in Spring Cloud, that we should maybe look at, but that's off topic.

@codefromthecrypt

Copy link
Copy Markdown

closing this and will comment in 182 why

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.

4 participants