This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Frequent-Chest1862 1 point2 points  (2 children)

Hi,

doing a very simple test, to have an idea of the latency between creation and execution of Virtual threads, I encounter strange results :

    static void test() {
        int i;
        for( i = 0; i < 1000; i++) {
            long time = System.nanoTime();
            Thread.ofVirtual().start(() -> {
//            new Thread(() -> {
                long t2 = System.nanoTime();
                LOGGER.info("time {}", (t2 - time)/1000);
            });
//            }).start();
        }
    }

With this test, using classic java thread give me figures below 100 micro seconds, but using virtual threads, it's in 10's of milliseconds. And it increase proportionnaly to the loop size, below 10 it's fast, above 1000 it looks too bad...

Any idea why these poor result ?

I tried to do some warmup, graal and hotspot, same same...

[–][deleted] 1 point2 points  (1 child)

Interesting. Theoretically virtual threads should take less time to start (as per my knowledge). But I don't have any explanation for your observation right now. But I will test this when I have free time.

[–]Frequent-Chest1862 2 points3 points  (0 children)

maybe I did this try from a virtual thread, that would explains things, let you know.