Created
January 20, 2011 04:45
-
-
Save aviflax/787409 to your computer and use it in GitHub Desktop.
A server and client for very simple benchmarking of Restlet 1.1 and 2.0. The focus is on a fixed server using Restlet 2.0.4 with Jetty, being used by various client scenarios — Restlet 1.1 and 2.0, Apache HttpClient 3.1 and 4.0, the Restlet Net connector.
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
/*** SETTINGS ***/ | |
requestsToSend = args.length >= 1 ? args[0] as Integer : 1000 | |
concurrency = args.length >= 2 ? args[1] as Integer : 10 | |
port = args.length >= 3 ? args[2] as Integer : 3000 | |
/*** /SETTINGS ***/ | |
requestsPerThread = (requestsToSend / concurrency) as Integer | |
import java.util.concurrent.atomic.* | |
import org.restlet.* | |
import org.restlet.data.* | |
import org.restlet.representation.* | |
import org.restlet.resource.* | |
ref = new Reference("http://localhost:$port/") | |
def client = new Client(new Context(), Protocol.HTTP) | |
client.context.parameters.add 'maxConnectionsPerHost', (concurrency * 2) as String | |
client.context.parameters.add 'maxTotalConnections', (concurrency * 2) as String | |
// need to pre-start the client because was otherwise having concurrency issues | |
client.start() | |
form = new Form() | |
form.add 'foo', 'bar' | |
20.times { form.add 'foo.' + it, 'bar'.multiply(it * 2) } | |
formText = form.webRepresentation.text | |
requestCounter = new AtomicInteger(0) | |
threads = [] | |
concurrency.times { | |
threads << Thread.start { | |
requestsPerThread.times { | |
def request = new Request(Method.POST, ref, new StringRepresentation(formText, MediaType.APPLICATION_WWW_FORM)) | |
def response = client.handle(request) | |
requestCounter.incrementAndGet() | |
print "$requestCounter requests sent and handled\r" | |
} | |
} | |
} | |
threads.each { it.join() } | |
println "$requestCounter requests sent and handled" | |
System.exit(0) |
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
#!/usr/bin/env java -cp groovy-all-1.7.5.jar:restlet-2.0.4/restlet/*:restlet-2.0.4/jetty/* groovy.lang.GroovyShell | |
/*** SETTINGS ***/ | |
port = args.length >= 1 ? args[0] as Integer : 3000 | |
/*** /SETTINGS ***/ | |
import java.util.concurrent.atomic.* | |
import org.restlet.* | |
import org.restlet.data.* | |
import org.restlet.representation.* | |
import org.restlet.resource.* | |
class RequestHandler extends Restlet { | |
static requestCounter = new AtomicInteger(0) | |
void handle(Request request, Response response) { | |
response.status = Status.SUCCESS_ACCEPTED | |
print "${requestCounter.incrementAndGet()} requests handled\r" | |
} | |
} | |
new Server(Protocol.HTTP, port, new RequestHandler()).start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment