-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New benchmark target for Netty. #501
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
91 changes: 91 additions & 0 deletions
91
benchmarks/src/main/java/com/squareup/okhttp/benchmarks/ApacheHttpClient.java
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,91 @@ | ||
/* | ||
* Copyright (C) 2014 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.squareup.okhttp.benchmarks; | ||
|
||
import com.squareup.okhttp.internal.SslContextBuilder; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.zip.GZIPInputStream; | ||
import javax.net.ssl.SSLContext; | ||
import org.apache.http.Header; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.conn.ClientConnectionManager; | ||
import org.apache.http.conn.scheme.Scheme; | ||
import org.apache.http.conn.ssl.SSLSocketFactory; | ||
import org.apache.http.impl.client.DefaultHttpClient; | ||
import org.apache.http.impl.conn.PoolingClientConnectionManager; | ||
|
||
/** Benchmark Apache HTTP client. */ | ||
class ApacheHttpClient extends SynchronousHttpClient { | ||
private static final boolean VERBOSE = false; | ||
|
||
private HttpClient client; | ||
|
||
@Override public void prepare(Benchmark benchmark) { | ||
super.prepare(benchmark); | ||
ClientConnectionManager connectionManager = new PoolingClientConnectionManager(); | ||
if (benchmark.tls) { | ||
SSLContext sslContext = SslContextBuilder.localhost(); | ||
connectionManager.getSchemeRegistry().register( | ||
new Scheme("https", 443, new SSLSocketFactory(sslContext))); | ||
} | ||
client = new DefaultHttpClient(connectionManager); | ||
} | ||
|
||
@Override public Runnable request(URL url) { | ||
return new ApacheHttpClientRequest(url); | ||
} | ||
|
||
class ApacheHttpClientRequest implements Runnable { | ||
private final URL url; | ||
|
||
public ApacheHttpClientRequest(URL url) { | ||
this.url = url; | ||
} | ||
|
||
public void run() { | ||
byte[] buffer = new byte[1024]; | ||
long start = System.nanoTime(); | ||
try { | ||
HttpResponse response = client.execute(new HttpGet(url.toString())); | ||
InputStream in = response.getEntity().getContent(); | ||
Header contentEncoding = response.getFirstHeader("Content-Encoding"); | ||
if (contentEncoding != null && contentEncoding.getValue().equals("gzip")) { | ||
in = new GZIPInputStream(in); | ||
} | ||
|
||
// Consume the response body. | ||
int total = 0; | ||
for (int count; (count = in.read(buffer)) != -1; ) { | ||
total += count; | ||
} | ||
in.close(); | ||
long finish = System.nanoTime(); | ||
|
||
if (VERBOSE) { | ||
System.out.println(String.format("Transferred % 8d bytes in %4d ms", | ||
total, TimeUnit.NANOSECONDS.toMillis(finish - start))); | ||
} | ||
} catch (IOException e) { | ||
System.out.println("Failed: " + e); | ||
} | ||
} | ||
} | ||
} |
64 changes: 0 additions & 64 deletions
64
benchmarks/src/main/java/com/squareup/okhttp/benchmarks/ApacheHttpClientRequest.java
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
25 changes: 25 additions & 0 deletions
25
benchmarks/src/main/java/com/squareup/okhttp/benchmarks/HttpClient.java
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,25 @@ | ||
/* | ||
* Copyright (C) 2014 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.squareup.okhttp.benchmarks; | ||
|
||
import java.net.URL; | ||
|
||
/** An HTTP client to benchmark. */ | ||
interface HttpClient { | ||
void prepare(Benchmark benchmark); | ||
void enqueue(URL url) throws Exception; | ||
boolean acceptingJobs(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yek. (not saying there's a better way)