-
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.
introduce an EndToEnd stress test that measures throughput between a
finagle client and server.
- Loading branch information
Showing
3 changed files
with
99 additions
and
20 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
finagle-stress/src/main/scala/com/twitter/finagle/stress/EndToEndStress.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,73 @@ | ||
package com.twitter.finagle.stress | ||
|
||
import java.net.InetSocketAddress | ||
|
||
import org.jboss.netty.buffer.ChannelBuffers | ||
import org.jboss.netty.handler.codec.http.{ | ||
HttpRequest, HttpResponse, DefaultHttpResponse, | ||
DefaultHttpRequest, HttpVersion, HttpResponseStatus, | ||
HttpMethod, HttpHeaders} | ||
|
||
import com.twitter.conversions.time._ | ||
import com.twitter.util.{Future, RandomSocket, Return, Throw, Time} | ||
import com.twitter.ostrich | ||
|
||
import com.twitter.finagle.builder.{ClientBuilder, ServerBuilder} | ||
import com.twitter.finagle.builder.Http | ||
import com.twitter.finagle.util.Timer | ||
import com.twitter.finagle.Service | ||
|
||
object EndToEndStress { | ||
private[this] object HttpService | ||
extends Service[HttpRequest, HttpResponse] | ||
{ | ||
def apply(request: HttpRequest) = Future { | ||
val response = new DefaultHttpResponse( | ||
request.getProtocolVersion, HttpResponseStatus.OK) | ||
response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, 1) | ||
response.setContent(ChannelBuffers.wrappedBuffer(".".getBytes)) | ||
response | ||
} | ||
} | ||
|
||
def dispatchLoop(service: Service[HttpRequest, HttpResponse]) { | ||
val request = new DefaultHttpRequest( | ||
HttpVersion.HTTP_1_1, HttpMethod.GET, "/") | ||
|
||
val beginTime = Time.now | ||
|
||
service(request) ensure { | ||
dispatchLoop(service) | ||
} respond { | ||
case Return(_) => | ||
ostrich.Stats.addTiming("request", beginTime.untilNow.inMilliseconds.toInt) | ||
case Throw(_) => | ||
ostrich.Stats.incr("failure") | ||
} | ||
} | ||
|
||
private[this] def run(concurrency: Int, addr: InetSocketAddress) { | ||
val service = ClientBuilder() | ||
.hosts(Seq(addr)) | ||
.codec(Http) | ||
.build() | ||
|
||
0 until concurrency foreach { _ => dispatchLoop(service) } | ||
} | ||
|
||
def main(args: Array[String]) { | ||
val serverAddr = RandomSocket() | ||
val server = ServerBuilder() | ||
.bindTo(serverAddr) | ||
.codec(Http) | ||
.build(HttpService) | ||
|
||
val beginTime = Time.now | ||
Timer.default.schedule(10.seconds) { | ||
println("@@ %ds".format(beginTime.untilNow.inSeconds)) | ||
Stats.prettyPrint(ostrich.Stats) | ||
} | ||
|
||
run(10, serverAddr) | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
finagle-stress/src/main/scala/com/twitter/finagle/stress/Stats.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,20 @@ | ||
package com.twitter.finagle.stress | ||
|
||
import com.twitter.ostrich.StatsProvider | ||
|
||
object Stats { | ||
def prettyPrint(stats: StatsProvider) { | ||
stats.getCounterStats foreach { case (name, count) => | ||
println("# %-30s %d".format(name, count)) | ||
} | ||
|
||
stats.getTimingStats foreach { case (name, stat) => | ||
val statMap = stat.toMap | ||
val keys = statMap.keys.toList.sorted | ||
|
||
keys foreach { key => | ||
println("# %-30s %s".format("timing_%s".format(key), statMap(key))) | ||
} | ||
} | ||
} | ||
} |