Skip to content
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

2.x: Upgrade to Gradle 4.3.1, add TakeUntilPerf #6029

Merged
merged 1 commit into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
dependencies {
classpath "ru.vyarus:gradle-animalsniffer-plugin:1.2.0"
classpath "gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.13.1"
classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.4"
classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.5"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.5.2"
}
Expand Down Expand Up @@ -201,6 +201,7 @@ jmh {
jmhVersion = jmhLibVersion
humanOutputFile = null
includeTests = false
jvmArgs = ["-Djmh.ignoreLock=true"]
jvmArgsAppend = ["-Djmh.separateClasspathJAR=true"]

if (project.hasProperty("jmh")) {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-bin.zip
95 changes: 95 additions & 0 deletions src/jmh/java/io/reactivex/TakeUntilPerf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* Copyright (c) 2016-present, RxJava Contributors.
*
* 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 io.reactivex;

import java.util.concurrent.*;

import org.openjdk.jmh.annotations.*;

import io.reactivex.functions.*;
import io.reactivex.internal.functions.Functions;
import io.reactivex.schedulers.Schedulers;

@BenchmarkMode(Mode.Throughput)
@Warmup(iterations = 5)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@OutputTimeUnit(TimeUnit.SECONDS)
@Fork(value = 1)
@State(Scope.Thread)
@AuxCounters
public class TakeUntilPerf implements Consumer<Integer> {

public volatile int items;

static final int count = 10000;

Flowable<Integer> flowable;

Observable<Integer> observable;

@Override
public void accept(Integer t) throws Exception {
items++;
}

@Setup
public void setup() {

flowable = Flowable.range(1, 1000 * 1000).takeUntil(Flowable.fromCallable(new Callable<Object>() {
@Override
public Object call() throws Exception {
int c = count;
while (items < c) { }
return 1;
}
}).subscribeOn(Schedulers.single()));

observable = Observable.range(1, 1000 * 1000).takeUntil(Observable.fromCallable(new Callable<Object>() {
@Override
public Object call() throws Exception {
int c = count;
while (items < c) { }
return 1;
}
}).subscribeOn(Schedulers.single()));
}

@Benchmark
public void flowable() {
final CountDownLatch cdl = new CountDownLatch(1);

flowable.subscribe(this, Functions.emptyConsumer(), new Action() {
@Override
public void run() throws Exception {
cdl.countDown();
}
});

while (cdl.getCount() != 0) { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akarnokd I wonder if this loop affects benchmark in positive or negative way, it consumes single core to max

Should cdl.await() be used instead? it parks the thread

I see this pattern in few other benchmarks but idk if it's intentional

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// It shouldn't affect the comparison though since loop is present in both Flowable and Observable benchmarks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem await is that on my machines they can't wake up that fast and the throughput usually caps out around 200k ops/s, even if the underlying work finished much faster.

For sorter sequences, typically in the range of 1000-10000 items, a spin-wait will result in a much higher throughput number as the end-of-work is detected more eagerly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhh damn, I think you've mentioned that problem before

What if JMH would be event/callback based so we could benchmark async code like RxJava in a reactive manner?

ie:

@Benchmark
public void flowable(BenchmarkObserver benchmarkObserver) {
    flowable.subscribe(this, Functions.emptyConsumer(), new Action() {
        @Override
        public void run() throws Exception {
            benchmarkObserver.onComplete();
        }
    });
}

}

@Benchmark
public void observable() {
final CountDownLatch cdl = new CountDownLatch(1);

observable.subscribe(this, Functions.emptyConsumer(), new Action() {
@Override
public void run() throws Exception {
cdl.countDown();
}
});

while (cdl.getCount() != 0) { }
}
}