-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finagle: mv ConcurrentLoadBalanacerFactory into finagle-memcached
Summary: Problem / Solution ConcurrentLoadBalanacerFactory is only used in one place – finagle-memcached. It doesn't seem generally useful since it is specific to pipelined protocols that have stateless sessions, of which we only have one (finagle-memcached). This patch moves it into the finagle-memcached directory and fixes up source to reflect the change. Test Plan: ./pants test <relevant projects> Reviewers: O22826 source:/src/scala/com/twitter/mediascience/!, banderson, O22963 source:/src/scala/com/twitter/taxi/!, vkostyukov, O1553 source:/media-analysis-service/!, mnakamura, O1805 source:/notifications-delivery/!, jillianc, O5308 source:/user-image-service/!, koliver, O1567 source:/mediaservices/!, yao, O5146 source:/thumbingbird/!, ryano, O1802 source:/mynahbird/!, dschobel, O948 source:/iesource/!, jdonham, O523 source:/bouncer/!, O5276 source:/udaan/!, O536 source:/cache/!, O8689 source:/ads/review/common/!, cflanagan Reviewed By: jillianc, koliver, dschobel Subscribers: ee-phabricator-cron, #rb_traffic, #rb_notifications-infra-team, #rb_sss, #rb_media-platform, #rb_csl, #rb_media-science-eng, #rb_growth-bangalore-eng, #rb_te-eng, #rb_cache-team, #rb_core-data-metrics, #rb_abuse-eng JIRA Issues: CSL-4067 TBR: TBR=true Differential Revision: https://phabricator.twitter.biz/D29215
- Loading branch information
Ruben Oanta
authored and
jenkins
committed
Feb 24, 2017
1 parent
29f3fef
commit 36ab44e
Showing
28 changed files
with
157 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
finagle-core/src/main/scala/com/twitter/finagle/param/ConcurrentLoadBalancingParams.scala
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
finagle-core/src/main/scala/com/twitter/finagle/param/WithConcurrentLoadBalancer.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...main/scala/com/twitter/finagle/memcached/loadbalancer/ConcurrentLoadBalancerFactory.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.twitter.finagle.memcached.loadbalancer | ||
|
||
import com.twitter.finagle.loadbalancer.LoadBalancerFactory | ||
import com.twitter.finagle.{Addr, Address, Stack, ServiceFactory, Stackable} | ||
|
||
/** | ||
* Exposes a [[StackModule]] which composes over the [[LoadBalancerFactory]] to | ||
* change the way the way endpoints are created for a load balancer. In particular, | ||
* each endpoint that is resolved is replicated by the given [[Param]]. This, increases | ||
* concurrency for each identical endpoint and allows them to be load balanced over. This | ||
* is useful for pipelining protocols that may incur head-of-line blocking without | ||
* this replication. | ||
*/ | ||
object ConcurrentLoadBalancerFactory { | ||
private val ReplicaKey = "concurrent_lb_replica" | ||
|
||
// package private for testing | ||
private[finagle] def replicate(num: Int): Address => Set[Address] = { | ||
case Address.Inet(ia, metadata) => | ||
for (i: Int <- (0 until num).toSet) yield | ||
Address.Inet(ia, metadata + (ReplicaKey -> i)) | ||
case addr => Set(addr) | ||
} | ||
|
||
/** | ||
* A class eligible for configuring the number of connections | ||
* a single endpoint has. | ||
*/ | ||
case class Param(numConnections: Int) { | ||
def mk(): (Param, Stack.Param[Param]) = (this, Param.param) | ||
} | ||
object Param { | ||
implicit val param = Stack.Param(Param(4)) | ||
} | ||
|
||
private[finagle] def module[Req, Rep]: Stackable[ServiceFactory[Req, Rep]] = | ||
new LoadBalancerFactory.StackModule[Req, Rep] { | ||
val description = "Balance requests across multiple connections on a single " + | ||
"endpoint, used for pipelining protocols" | ||
|
||
override def make(params: Stack.Params, next: Stack[ServiceFactory[Req, Rep]]) = { | ||
val Param(numConnections) = params[Param] | ||
val LoadBalancerFactory.Dest(dest) = params[LoadBalancerFactory.Dest] | ||
val newDest = dest.map { | ||
case bound@Addr.Bound(set, _) => | ||
bound.copy(addrs = set.flatMap(replicate(numConnections))) | ||
case addr => addr | ||
} | ||
super.make(params + LoadBalancerFactory.Dest(newDest), next) | ||
} | ||
} | ||
} |
Oops, something went wrong.