回复:Fiber try out feedback

Lei Yu lei.yul at alibaba-inc.com
Fri Jul 19 11:56:17 UTC 2019


Here is the test case

/*
 * @test
 * @library /lib/testlibrary
 * @summary Test fibers pass token to each others
 * @run main  PassTokenTest
 */
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import static jdk.testlibrary.Asserts.assertTrue;
public class PassTokenTest {
    static final int N = 1_000_000;
    Runner[] runners = new Runner[16];
    public static void main(String[] args) throws Exception {
        while (true) {
            new PassTokenTest().doTest(FiberScope.background()::schedule);
        }
    }
    private void doTest(Consumer<Runnable> run) throws Exception {
        for (int i = 0; i < runners.length; i++) {
            runners[i] = new Runner(i);
        }
        CountDownLatch finishLatch = new CountDownLatch(runners.length);
        for (Runner runner : runners) {
            run.accept(() -> {
                runner.run();
                finishLatch.countDown();
            });
        }
        assertTrue(finishLatch.await(60, TimeUnit.SECONDS));
    }
    final long start = System.currentTimeMillis();
    int counter = 0;
    final Lock lock = new ReentrantLock();
    final Condition cond = lock.newCondition();
    class Runner implements Runnable {
        private final int ord;
        public Runner(int ord) {
            this.ord = ord;
        }
        @Override
        public void run() {
            while (counter < N) {
                lock.lock();
                try {
                    while (counter % runners.length != ord) {
                        try {
                            cond.await();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    if (++counter % 10000 == 0) // pass the token
                        System.out.println(Thread.currentThread().getName() + "\t" + counter +
                                "\t elapsed=" + (System.currentTimeMillis() - start));
                    cond.signalAll();
                } finally {
                    lock.unlock();
                }
            }
        }
    }}

Lei Yu


------------------------------------------------------------------
发件人:Alan Bateman <Alan.Bateman at oracle.com>
发送时间:2019年7月19日(星期五) 19:05
收件人:郁磊(梁希) <lei.yul at alibaba-inc.com>; loom-dev <loom-dev at openjdk.java.net>
主 题:Re: Fiber try out feedback

On 19/07/2019 09:48, Lei Yu wrote:
> Hi,
>
> Here are some feedback on our try out of loom from Alibaba.
> We have written a test of the message passing between the Fibers to verify the performance under high concurrency.
> 1. An assertion error occurred while running the test(can be reproduced by the code in the attachment):
> java.lang.AssertionError
>         at java.base/java.lang.Continuation.resizeStack(Continuation.java:685)
>         at java.base/java.lang.Continuation.maybeShrink(Continuation.java:671)
>         at java.base/java.lang.Continuation.postYieldCleanup(Continuation.java:465)
>         at java.base/java.lang.Continuation.run(Continuation.java:341)
>         at java.base/java.lang.Fiber.runContinuation(Fiber.java:367)
>         at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1425)
>         ...
>
> I think the deeper reason is that the value of Continuation.sp has been changed between maybeShrink() and resizeStack().
>
> 2. Thaw/Freeze interpreter frame will be slowed down by compute_oop_map significantly.
> [image.png]
>
> If a Fiber is executing as a consumer of a BlockingQueue in loop, we can frequently observe the interpreter frame exists even though compilation occurs,
> thaw/freeze interpreter frame may become a performance bottleneck.
Thanks for the bug report/data. I think the attachments (test case and 
PNG) were dropped by the mail system. Can you re-send with the test case 
inlined or if you have someone with write access to cr.openjdk.java.net 
then maybe they could be published there?

-Alan


More information about the loom-dev mailing list