Skip to content

Commit

Permalink
twitter-server: Move admin http server to netty4
Browse files Browse the repository at this point in the history
Problem / Solution

We want to slowly move to Netty4 and the admin server is a good
candidate to port over. Note, a non-jdk zlib codec isn't provided
transitively in Netty4. If you override the zlib codec via the flag
`-Dio.netty.noJdkZlib{Encoder,Decoder}=true`, you must furnish the
`com.jcraft.jzlib` dependency.

RB_ID=868328
  • Loading branch information
Ruben Oanta authored and jenkins committed Sep 7, 2016
1 parent 2b69347 commit bb18649
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ object TwitterServer extends Build {
name := "twitter-server",
libraryDependencies ++= Seq(
finagle("core"),
finagle("http"),
finagle("netty4-http"),
finagle("toggle"),
finagle("zipkin-core"),
util("app"),
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ scala_library(name='scala',
'3rdparty/jvm/com/fasterxml/jackson/core:jackson-databind',
'3rdparty/jvm/com/fasterxml/jackson/module:jackson-module-scala',
'3rdparty/jvm/org/scala-lang/modules:scala-xml',
'finagle/finagle-core',
'finagle/finagle-netty4-http',
'finagle/finagle-toggle',
'finagle/finagle-zipkin',
'finagle/finagle-zipkin-core',
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/com/twitter/server/AdminHttpServer.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.twitter.server

import com.twitter.app.App
import com.twitter.finagle.{Http, ListeningServer, NullServer, Service, param}
import com.twitter.finagle.client.ClientRegistry
import com.twitter.finagle.filter.ServerAdmissionControl
import com.twitter.finagle.http.{HttpMuxer, Request, Response}
import com.twitter.finagle.netty4.http.exp.Netty4Impl
import com.twitter.finagle.server.ServerRegistry
import com.twitter.finagle.stats.NullStatsReceiver
import com.twitter.finagle.tracing.NullTracer
import com.twitter.finagle.{Http, ListeningServer, NullServer, Service, param}
import com.twitter.server.util.HttpUtils
import com.twitter.server.view.{IndexView, NotFoundView}
import com.twitter.util.registry.Library
Expand Down Expand Up @@ -187,6 +188,7 @@ trait AdminHttpServer { self: App =>
}
log.info(s"Serving admin http on ${adminPort()}")
adminHttpServer = Http.server
.configured(Netty4Impl)
.configured(param.Stats(NullStatsReceiver))
.configured(param.Tracer(NullTracer))
.configured(param.Monitor(loggingMonitor))
Expand Down
24 changes: 7 additions & 17 deletions src/main/scala/com/twitter/server/ShadowAdminServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@ package com.twitter.server
import com.twitter.app.App
import com.twitter.concurrent.NamedPoolThreadFactory
import com.twitter.finagle.http.{HttpMuxer, HttpMuxHandler}
import com.twitter.finagle.netty3.Netty3Listener
import com.twitter.finagle.netty4
import com.twitter.finagle.netty4.http.exp.Netty4Impl
import com.twitter.finagle.stats.NullStatsReceiver
import com.twitter.finagle.tracing.NullTracer
import com.twitter.finagle.util.LoadService
import com.twitter.finagle.{Http, ListeningServer, NullServer, param}
import io.netty.channel.nio.NioEventLoopGroup
import java.net.InetSocketAddress
import java.util.concurrent.Executors
import java.util.logging.Logger
import org.jboss.netty.channel.ServerChannelFactory
import org.jboss.netty.channel.socket.nio.{NioWorkerPool, NioServerSocketChannelFactory}

private object ShadowAdminServer {
val Executor = Executors.newCachedThreadPool(
new NamedPoolThreadFactory("twitter-server/netty3", true /*daemon*/))
}

/**
* An admin http server which serves requests outside the default
Expand All @@ -31,14 +25,11 @@ private object ShadowAdminServer {
* are an accurate proxy of server health.
*/
trait ShadowAdminServer { self: App with AdminHttpServer =>
import ShadowAdminServer._

@volatile protected var shadowHttpServer: ListeningServer = NullServer
val shadowAdminPort = flag("shadow.admin.port", new InetSocketAddress(defaultHttpPort+1),
"Shadow admin http server port")

def shadowWorkerPool: NioWorkerPool = new NioWorkerPool(Executor, 1)

premain {
val log = Logger.getLogger(getClass.getName)
log.info(s"Serving BlackBox http server on port ${shadowAdminPort().getPort}")
Expand All @@ -54,15 +45,14 @@ trait ShadowAdminServer { self: App with AdminHttpServer =>
case (muxer, h) => muxer.withHandler(h.pattern, h)
}

val channelFactory: ServerChannelFactory =
new NioServerSocketChannelFactory(Executor, shadowWorkerPool) {
override def releaseExternalResources() = () // no-op
}
val shadowEventLoop = new NioEventLoopGroup(1 /*nThreads*/ ,
new NamedPoolThreadFactory("twitter-server/netty", makeDaemons = true))

shadowHttpServer = Http.server
.configured(param.Stats(NullStatsReceiver))
.configured(Netty4Impl)
.configured(param.Tracer(NullTracer))
.configured(Netty3Listener.ChannelFactory(channelFactory))
.configured(netty4.param.WorkerPool(shadowEventLoop))
.serve(shadowAdminPort(), muxer)
closeOnExit(shadowHttpServer)
}
Expand Down

0 comments on commit bb18649

Please sign in to comment.