-
Notifications
You must be signed in to change notification settings - Fork 714
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speeds up jersey and double-checks double-slashes
- Loading branch information
Adrian Cole
committed
Feb 21, 2018
1 parent
db3d46e
commit a3e18b8
Showing
5 changed files
with
290 additions
and
13 deletions.
There are no files selected for viewing
139 changes: 139 additions & 0 deletions
139
instrumentation/benchmarks/src/main/java/brave/jersey/server/FakeExtendedUriInfo.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,139 @@ | ||
package brave.jersey.server; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
import java.util.regex.MatchResult; | ||
import javax.ws.rs.core.MultivaluedMap; | ||
import javax.ws.rs.core.PathSegment; | ||
import javax.ws.rs.core.UriBuilder; | ||
import org.glassfish.jersey.server.ExtendedUriInfo; | ||
import org.glassfish.jersey.server.model.Resource; | ||
import org.glassfish.jersey.server.model.ResourceMethod; | ||
import org.glassfish.jersey.server.model.RuntimeResource; | ||
import org.glassfish.jersey.uri.UriTemplate; | ||
|
||
class FakeExtendedUriInfo implements ExtendedUriInfo { | ||
final URI baseURI; | ||
final List<UriTemplate> matchedTemplates; | ||
|
||
FakeExtendedUriInfo(URI baseURI, List<UriTemplate> matchedTemplates) { | ||
this.baseURI = baseURI; | ||
this.matchedTemplates = matchedTemplates; | ||
} | ||
|
||
@Override public Throwable getMappedThrowable() { | ||
return null; | ||
} | ||
|
||
@Override public List<MatchResult> getMatchedResults() { | ||
return null; | ||
} | ||
|
||
@Override public List<UriTemplate> getMatchedTemplates() { | ||
return matchedTemplates; | ||
} | ||
|
||
@Override public List<PathSegment> getPathSegments(String name) { | ||
return null; | ||
} | ||
|
||
@Override public List<PathSegment> getPathSegments(String name, boolean decode) { | ||
return null; | ||
} | ||
|
||
@Override public List<RuntimeResource> getMatchedRuntimeResources() { | ||
return null; | ||
} | ||
|
||
@Override public ResourceMethod getMatchedResourceMethod() { | ||
return null; | ||
} | ||
|
||
@Override public Resource getMatchedModelResource() { | ||
return null; | ||
} | ||
|
||
@Override public List<ResourceMethod> getMatchedResourceLocators() { | ||
return null; | ||
} | ||
|
||
@Override public List<Resource> getLocatorSubResources() { | ||
return null; | ||
} | ||
|
||
@Override public String getPath() { | ||
return null; | ||
} | ||
|
||
@Override public String getPath(boolean decode) { | ||
return null; | ||
} | ||
|
||
@Override public List<PathSegment> getPathSegments() { | ||
return null; | ||
} | ||
|
||
@Override public List<PathSegment> getPathSegments(boolean decode) { | ||
return null; | ||
} | ||
|
||
@Override public URI getRequestUri() { | ||
return null; | ||
} | ||
|
||
@Override public UriBuilder getRequestUriBuilder() { | ||
return null; | ||
} | ||
|
||
@Override public URI getAbsolutePath() { | ||
return null; | ||
} | ||
|
||
@Override public UriBuilder getAbsolutePathBuilder() { | ||
return null; | ||
} | ||
|
||
@Override public URI getBaseUri() { | ||
return baseURI; | ||
} | ||
|
||
@Override public UriBuilder getBaseUriBuilder() { | ||
return null; | ||
} | ||
|
||
@Override public MultivaluedMap<String, String> getPathParameters() { | ||
return null; | ||
} | ||
|
||
@Override public MultivaluedMap<String, String> getPathParameters(boolean decode) { | ||
return null; | ||
} | ||
|
||
@Override public MultivaluedMap<String, String> getQueryParameters() { | ||
return null; | ||
} | ||
|
||
@Override public MultivaluedMap<String, String> getQueryParameters(boolean decode) { | ||
return null; | ||
} | ||
|
||
@Override public List<String> getMatchedURIs() { | ||
return null; | ||
} | ||
|
||
@Override public List<String> getMatchedURIs(boolean decode) { | ||
return null; | ||
} | ||
|
||
@Override public List<Object> getMatchedResources() { | ||
return null; | ||
} | ||
|
||
@Override public URI resolve(URI uri) { | ||
return null; | ||
} | ||
|
||
@Override public URI relativize(URI uri) { | ||
return null; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...s/src/main/java/brave/jersey/server/TracingApplicationEventListenerAdapterBenchmarks.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,77 @@ | ||
/** | ||
* Copyright 2015-2016 The OpenZipkin 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 brave.jersey.server; | ||
|
||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.concurrent.TimeUnit; | ||
import org.glassfish.jersey.internal.MapPropertiesDelegate; | ||
import org.glassfish.jersey.server.ContainerRequest; | ||
import org.glassfish.jersey.server.ContainerResponse; | ||
import org.glassfish.jersey.server.ExtendedUriInfo; | ||
import org.glassfish.jersey.uri.PathTemplate; | ||
import org.jboss.resteasy.core.ServerResponse; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
@Measurement(iterations = 5, time = 1) | ||
@Warmup(iterations = 10, time = 1) | ||
@Fork(3) | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
@State(Scope.Thread) | ||
public class TracingApplicationEventListenerAdapterBenchmarks { | ||
FakeExtendedUriInfo uriInfo = new FakeExtendedUriInfo(URI.create("/"), | ||
Arrays.asList( | ||
new PathTemplate("/"), | ||
new PathTemplate("/items/{itemId}"), | ||
new PathTemplate("/"), | ||
new PathTemplate("/nested") | ||
) | ||
); | ||
ContainerResponse response = new ContainerResponse( | ||
new ContainerRequest( | ||
URI.create("/"), null, null, null, new MapPropertiesDelegate() | ||
) { | ||
@Override public ExtendedUriInfo getUriInfo() { | ||
return uriInfo; | ||
} | ||
}, new ServerResponse()); | ||
|
||
TracingApplicationEventListener.Adapter adapter = new TracingApplicationEventListener.Adapter(); | ||
|
||
@Benchmark public String parseRoute() { | ||
return adapter.route(response); | ||
} | ||
|
||
// Convenience main entry-point | ||
public static void main(String[] args) throws RunnerException { | ||
Options opt = new OptionsBuilder() | ||
.include(".*" + TracingApplicationEventListenerAdapterBenchmarks.class.getSimpleName()) | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
} |
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
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
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