-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created abstract FilterBenchmark class (#3247)
* Created abstract FilterBenchmark class Signed-off-by: Calum Murray <cmurray@redhat.com> * Added copyright header Signed-off-by: Calum Murray <cmurray@redhat.com> * Refactoring a bit Signed-off-by: Calum Murray <cmurray@redhat.com> * Implemented exact filter benchmark Signed-off-by: Calum Murray <cmurray@redhat.com> * Added state annotation to base class Signed-off-by: Calum Murray <cmurray@redhat.com> * Added copyright header Signed-off-by: Calum Murray <cmurray@redhat.com> --------- Signed-off-by: Calum Murray <cmurray@redhat.com>
- Loading branch information
Showing
2 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
...n/java/dev/knative/eventing/kafka/broker/dispatcher/impl/filter/ExactFilterBenchmark.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,89 @@ | ||
/* | ||
* Copyright © 2018 Knative Authors (knative-dev@googlegroups.com) | ||
* | ||
* 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 dev.knative.eventing.kafka.broker.dispatcher.impl.filter; | ||
|
||
import dev.knative.eventing.kafka.broker.dispatcher.Filter; | ||
import dev.knative.eventing.kafka.broker.dispatcher.impl.filter.subscriptionsapi.ExactFilter; | ||
import io.cloudevents.CloudEvent; | ||
import io.cloudevents.core.builder.CloudEventBuilder; | ||
import io.cloudevents.core.v1.CloudEventV1; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
public class ExactFilterBenchmark { | ||
|
||
public static CloudEvent event() { | ||
return CloudEventBuilder.v1() | ||
.withId("abc") | ||
.withSource(URI.create("http://localhost")) | ||
.withType("test") | ||
.withDataSchema(URI.create("/api/schema")) | ||
.withDataContentType("testContentType") | ||
.withSubject("testSubject") | ||
.build(); | ||
} | ||
|
||
public static class ExactFilterBenchmarkExactMatchID extends FilterBenchmark { | ||
|
||
@Override | ||
protected Filter createFilter() { | ||
return new ExactFilter(Map.of(CloudEventV1.ID, "abc")); | ||
} | ||
|
||
@Override | ||
protected CloudEvent createEvent() { | ||
return event(); | ||
} | ||
} | ||
|
||
public static class ExactFilterBenchmarkAllAttributes extends FilterBenchmark { | ||
|
||
@Override | ||
protected Filter createFilter() { | ||
return new ExactFilter(Map.of( | ||
CloudEventV1.ID, "abc", | ||
CloudEventV1.SOURCE, "http://localhost", | ||
CloudEventV1.TYPE, "test", | ||
CloudEventV1.DATASCHEMA,"/api/schema", | ||
CloudEventV1.DATACONTENTTYPE, "testContentType", | ||
CloudEventV1.SUBJECT, "testSubject" | ||
)); | ||
} | ||
|
||
@Override | ||
protected CloudEvent createEvent() { | ||
return event(); | ||
} | ||
} | ||
|
||
public static class ExactFilterBenchmarkNoMatch extends FilterBenchmark { | ||
|
||
@Override | ||
protected Filter createFilter() { | ||
return new ExactFilter(Map.of( | ||
CloudEventV1.ID, "qwertyuiopasdfghjklzxcvbnm", | ||
CloudEventV1.SOURCE, "qwertyuiopasdfghjklzxcvbnm" | ||
)); | ||
} | ||
|
||
@Override | ||
protected CloudEvent createEvent() { | ||
return event(); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...c/main/java/dev/knative/eventing/kafka/broker/dispatcher/impl/filter/FilterBenchmark.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,57 @@ | ||
/* | ||
* Copyright © 2018 Knative Authors (knative-dev@googlegroups.com) | ||
* | ||
* 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 dev.knative.eventing.kafka.broker.dispatcher.impl.filter; | ||
|
||
import dev.knative.eventing.kafka.broker.dispatcher.Filter; | ||
import io.cloudevents.CloudEvent; | ||
import org.openjdk.jmh.annotations.*; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@BenchmarkMode(Mode.All) | ||
@Fork(1) | ||
@State(Scope.Thread) | ||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
public abstract class FilterBenchmark { | ||
Filter filter; | ||
CloudEvent cloudEvent; | ||
|
||
@Setup | ||
public void setupFilter() { | ||
this.filter = createFilter(); | ||
} | ||
|
||
@Setup | ||
public void setupCloudEvent() { | ||
this.cloudEvent = createEvent(); | ||
} | ||
|
||
protected abstract Filter createFilter(); | ||
|
||
protected abstract CloudEvent createEvent(); | ||
|
||
@Benchmark | ||
public void benchmarkFilterCreation(Blackhole bh) { | ||
bh.consume(this.createFilter()); | ||
} | ||
|
||
@Benchmark | ||
public void benchmarkFilterEvaluation(Blackhole bh) { | ||
bh.consume(this.filter.test(this.cloudEvent)); | ||
} | ||
} |