-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap PrintWriter with BufferedWriter (#540)
* Wrap PrintWriter with BufferedWriter * Microbenchmark for BufferedWriter wrapper Signed-off-by: Takanori Takase <scm@after-sunrise.com> Co-authored-by: Takanori Takase <scm@after-sunrise.com>
- Loading branch information
1 parent
c3dc1f2
commit ac5136b
Showing
3 changed files
with
56 additions
and
5 deletions.
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
52 changes: 52 additions & 0 deletions
52
simpleclient_servlet/src/test/java/io/prometheus/client/exporter/ExampleBenchmark.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,52 @@ | ||
package io.prometheus.client.exporter; | ||
|
||
import io.prometheus.client.Gauge; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.servlet.ServletContextHandler; | ||
import org.eclipse.jetty.servlet.ServletHolder; | ||
|
||
import java.io.InputStream; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.UUID; | ||
|
||
public class ExampleBenchmark { | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
Gauge gauge = Gauge.build().name("labels").help("foo").labelNames("bar").register(); | ||
for (int i = 0; i < 10000; i++) { | ||
gauge.labels(UUID.randomUUID().toString()).set(Math.random()); | ||
} | ||
|
||
ServletContextHandler context = new ServletContextHandler(); | ||
context.setContextPath("/"); | ||
context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics"); | ||
|
||
Server server = new Server(0); | ||
server.setHandler(context); | ||
server.start(); | ||
Thread.sleep(1000); | ||
|
||
byte[] bytes = new byte[8192]; | ||
URL url = new URL("http", "localhost", server.getConnectors()[0].getLocalPort(), "/metrics"); | ||
|
||
long start = System.nanoTime(); | ||
for (int i = 0; i < 100; i++) { | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
InputStream in = connection.getInputStream(); | ||
try { | ||
while (in.read(bytes) != -1) in.available(); | ||
} finally { | ||
in.close(); | ||
} | ||
connection.disconnect(); | ||
} | ||
System.out.println(String.format("%,3d ns", System.nanoTime() - start)); | ||
|
||
server.stop(); | ||
server.join(); | ||
|
||
} | ||
|
||
} |
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