Skip to content

Commit

Permalink
Merged branch '2.0.x' into '3.0.x'.
Browse files Browse the repository at this point in the history
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Jul 12, 2023
2 parents aee4c6c + 6c626b1 commit 76c31e2
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

A [ReactiveStreams](http://www.reactive-streams.org/) wrapper around
[Jetty](https://eclipse.org/jetty)'s
[HttpClient](http://www.eclipse.org/jetty/documentation/current/http-client.html).
[HttpClient](https://www.eclipse.org/jetty/documentation/jetty-11/programming-guide/index.html#pg-client-http).

## Versions

Expand Down
46 changes: 29 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty-version>11.0.14</jetty-version>
<rxjava-version>3.1.6</rxjava-version>
<spring-version>5.3.25</spring-version>
<slf4j-version>2.0.6</slf4j-version>
<spring-version>5.3.28</spring-version>
<slf4j-version>2.0.7</slf4j-version>
<log4j2-version>2.20.0</log4j2-version>
<reactivestreams-version>1.0.4</reactivestreams-version>
</properties>
Expand Down Expand Up @@ -182,11 +182,11 @@
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.5.0</version>
<version>3.6.0</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -199,23 +199,23 @@
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.5.0</version>
<version>3.6.0</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.0</version>
</plugin>
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
Expand All @@ -233,7 +233,7 @@
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M7</version>
<version>3.0.1</version>
<configuration>
<goals>deploy</goals>
<preparationGoals>clean install</preparationGoals>
Expand All @@ -244,34 +244,34 @@
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M9</version>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.8</version>
<version>5.1.9</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<version>0.8.10</version>
</plugin>
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>4.1</version>
<version>4.2</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down Expand Up @@ -352,6 +352,18 @@
<version>${jetty-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hdrhistogram</groupId>
<artifactId>HdrHistogram</artifactId>
<version>2.1.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-perf-helper</artifactId>
<version>1.0.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
Expand All @@ -367,7 +379,7 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.7.1</version>
<version>7.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void prepare(Handler handler) throws Exception {
QueuedThreadPool serverThreads = new QueuedThreadPool();
serverThreads.setName("server");
server = new Server(serverThreads);
connector = new ServerConnector(server, createServerConnectionFactory(protocol));
connector = new ServerConnector(server, 1, 1, createServerConnectionFactory(protocol));
server.addConnector(connector);
server.setHandler(handler);
server.start();
Expand Down
111 changes: 111 additions & 0 deletions src/test/java/org/eclipse/jetty/reactive/client/MetricsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2017-2022 the original author or authors.
*
* 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 org.eclipse.jetty.reactive.client;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;

import org.HdrHistogram.ConcurrentHistogram;
import org.HdrHistogram.Histogram;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.toolchain.perf.HistogramSnapshot;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import org.testng.Assert;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;

public class MetricsTest extends AbstractTest {
@Factory(dataProvider = "protocols", dataProviderClass = AbstractTest.class)
public MetricsTest(String protocol) {
super(protocol);
}

@Test
public void testMetrics() throws Exception {
prepare(new EmptyHandler());

// Data structure to hold response status codes.
Map<Integer, AtomicInteger> responses = new ConcurrentHashMap<>();

// Data structure to hold response times.
Histogram responseTimes = new ConcurrentHistogram(
TimeUnit.MICROSECONDS.toNanos(1),
TimeUnit.MINUTES.toNanos(1),
3
);

int count = 100;
CountDownLatch latch = new CountDownLatch(count);
IntStream.range(0, count)
.parallel()
.forEach(i -> {
Request request = httpClient().newRequest(uri() + "/" + i);

// Collect information about response status codes.
request.onResponseSuccess(rsp ->
{
int key = rsp.getStatus() / 100;
responses.computeIfAbsent(key, k -> new AtomicInteger()).incrementAndGet();
});

// Collect information about response times.
request.onRequestBegin(req -> req.attribute("nanoTime", System.nanoTime()))
.onComplete(result -> {
Long nanoTime = (Long)result.getRequest().getAttributes().get("nanoTime");
if (nanoTime != null) {
long responseTime = System.nanoTime() - nanoTime;
responseTimes.recordValue(responseTime);
}
});

ReactiveRequest.newBuilder(request)
.build()
.response()
.subscribe(new Subscriber<>() {
@Override
public void onSubscribe(Subscription subscription) {
subscription.request(1);
}

@Override
public void onNext(ReactiveResponse reactiveResponse) {
}

@Override
public void onError(Throwable throwable) {
}

@Override
public void onComplete() {
latch.countDown();
}
});
});

// Wait for all the responses to arrive.
Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));

System.err.println("responses = " + responses);

HistogramSnapshot snapshot = new HistogramSnapshot(responseTimes, 32, "Response Times", "us", TimeUnit.NANOSECONDS::toMicros);
System.err.println(snapshot);
}
}

0 comments on commit 76c31e2

Please sign in to comment.