Skip to content

Commit 786f06c

Browse files
Anton Ivanovjenkins
Anton Ivanov
authored and
jenkins
committed
[home-mixer] don't offload scoredCandidateFeaturesCache
scoredCandidateFeaturesCache accounts for 60% of offload tasks issued by client OffloadFilter. These tasks are very short (p999 is 50us), nobody waits for their reply (it's a side effect) and therefore can be safely executed by a Netty thread without context switch. JIRA Issues: STOR-8861 Differential Revision: https://phabricator.twitter.biz/D1190370
1 parent 7954703 commit 786f06c

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

finagle-core/src/main/scala/com/twitter/finagle/filter/OffloadFilter.scala

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ object OffloadFilter {
6565
private[finagle] def server[Req, Rep]: Stackable[ServiceFactory[Req, Rep]] =
6666
new ServerModule[Req, Rep]
6767

68+
private[this] val offloadsDisabledLocal = new Local[Unit]
69+
70+
/**
71+
* Disables offloads for the enclosed scope.
72+
* The scope must return Unit,
73+
* this ensures no callbacks can be added to the result.
74+
*/
75+
def withOffloadsDisabled(f: => Unit): Unit = {
76+
offloadsDisabledLocal.let(()) {
77+
f
78+
}
79+
}
80+
6881
final class Client[Req, Rep](pool: FuturePool, statsReceiver: StatsReceiver)
6982
extends SimpleFilter[Req, Rep] {
7083

@@ -98,21 +111,26 @@ object OffloadFilter {
98111
// You would be surprised but this can happen. Same simulations report that we lose a race in
99112
// about 1 in 1 000 000 of cases this way (0.0001%).
100113
val response = service(request)
101-
val shifted = Promise.interrupts[Rep](response)
102-
response.respond { t =>
103-
pool {
104-
val startNs = System.nanoTime()
105-
shifted.update(t)
106-
applyTimeNs.add(System.nanoTime() - startNs)
107-
}
114+
if (offloadsDisabledLocal().isDefined) {
115+
response
116+
117+
} else {
118+
val shifted = Promise.interrupts[Rep](response)
119+
response.respond { t =>
120+
pool {
121+
val startNs = System.nanoTime()
122+
shifted.update(t)
123+
applyTimeNs.add(System.nanoTime() - startNs)
124+
}
108125

109-
val tracing = Trace()
110-
if (tracing.isActivelyTracing) {
111-
tracing.recordBinary(ClientAnnotationKey, pool.poolSize)
126+
val tracing = Trace()
127+
if (tracing.isActivelyTracing) {
128+
tracing.recordBinary(ClientAnnotationKey, pool.poolSize)
129+
}
112130
}
113-
}
114131

115-
shifted
132+
shifted
133+
}
116134
}
117135
}
118136

0 commit comments

Comments
 (0)