Virtual threads

2023-12-19 Thread ski n
Since Camel 4.3.0 released 18th December, the framework has primarily
support for virtual threads:

https://camel.apache.org/manual/threading-model.html#_virtual_threads

In the documentation, it's already said that this doesn't work in all
cases. Previously, it was also mentioned by Claus that it can take a long
time (years) before most important libraries implemented support for it
(Currently Spring is one of the few examples that already supports virtual
threads).

I would love to explore this new functionality, but still have many
questions. For example, I don't know what the best settings for threading
are when virtual threads are enabled. I thought that pooling was a solution
that was used with platform threads, but with virtual threads a pool may
not be needed anymore. And if we use a thread pool, can we set the pools to
-1 (infinite) or a million?

Are there already cases in Camel where enabling virtual threads speed up
processing (for example, with a lot of blocking I/O)? Are there benchmarks
available that compare use cases with and without virtual threads enabled?

This is not an area I'm very knowledgeable of, but would love to see a blog
entry that covers this interesting new topic.

Raymond


Re: Camel & Virtual threads

2023-09-02 Thread bukaj_s
thx, but I still prefer this explanation https://youtu.be/zluKcazgkV4

On Fri, 1 Sept 2023, 11:34 ski n,  wrote:

> Kotlin Coroutines and Java Virtual Threads are conceptually very similar.
> In details and implementation they are different, of course. A good
> presentation on comparing coroutines and virtual threads by Urs Peter:
>
> https://www.youtube.com/watch?v=bOLChQ3fFQo
>
> I was just referencing Kotlin Coroutines btw, for Camel only virtual
> threads are relevant.
>
> On Fri, Sep 1, 2023 at 11:01 AM bukaj_s  wrote:
>
> > sry I meant executor.
> >
> > On Fri, 1 Sept 2023, 10:57 bukaj_s,  wrote:
> >
> > > You are confusing coroutines and virtual threads.
> > > Afaik you can try to use virtual thread pool, question is how much
> > > synchronization is camel using under the hood.
> > >
> > > On Fri, 1 Sept 2023, 10:34 ski n,  wrote:
> > >
> > >> OK, thanks. It will take some (couple of years) before most libraries
> > are
> > >> catching up.
> > >>
> > >> At least, Spring Boot will already support Java 21 with virtual
> threads
> > in
> > >> their next release (
> > >> https://spring.io/blog/2023/08/24/spring-boot-3-2-0-m2-available-now
> ).
> > I
> > >> don't know exactly how they do it, but they ship Spring as a multi
> > release
> > >> Jar for this purpose. When running Spring on Java 21 you can enable
> it (
> > >>
> > >>
> >
> https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2.0-M1-Release-Notes#support-for-virtual-threads
> > >> ).
> > >>
> > >> I was thinking more or less in the same lines for Camel. For most of
> the
> > >> cases the underlying libraries needs to be updated, but for some stuff
> > >> like
> > >> Seda or Stream caching this may already work from within the libraries
> > own
> > >> code.
> > >>
> > >> Raymond
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >> On Fri, Sep 1, 2023 at 9:36 AM Claus Ibsen 
> > wrote:
> > >>
> > >> > Hi
> > >> >
> > >> > No plan for virtual threads - this relies on 3rd party libraries and
> > >> many
> > >> > other frameworks starting to adopt them as well, which means Java 21
> > as
> > >> > minimum base version.
> > >> > Support for Java 21 is to run on JDK21. JDK17 will be primary
> > supported,
> > >> > and 21 secondary, that is the plan for this year.
> > >> >
> > >> >
> > >> > On Fri, Sep 1, 2023 at 9:34 AM ski n 
> > wrote:
> > >> >
> > >> > > In integration there is a lot of Async I/O (calling disk,
> databases,
> > >> > api's
> > >> > > and other external systems). Though Camel is very fast, it's
> mostly
> > >> these
> > >> > > async I/O calls that take time and eat a lot of platform threads.
> > >> > >
> > >> > > For example:
> > >> > >
> > >> > > from("direct:start")
> > >> > >   .log("some log") //this takes less than 1 ms
> > >> > >   .setHeader(Exchange.HTTP_URI, constant("http://someapi;))
> //this
> > >> takes
> > >> > > less than 1 ms
> > >> > >   .to("http://someapi;) //this takes 3 seconds
> > >> > >   .setHeader("Result","Done") //this takes less than 1 ms
> > >> > >   .to("sql://insertindatabase")  //this takes less than 1 seconds
> > >> > >   ;
> > >> > >
> > >> > > One solution to this is using virtual threads. They are already
> part
> > >> of
> > >> > > Kotlin (coroutines), but now coming to Java as well in Java 21
> > >> (release
> > >> > > 19th September).
> > >> > >
> > >> > > In the Camel 4 blog "What's new" it states that:
> > >> > >
> > >> > > "We plan to support Java 21 on next LTS released by the end of
> this
> > >> > year."
> > >> > >
> > >> > > Camel next LTS release (4.2) is expected around December.
> > >> > >
> > >> > > I was wondering what the plans here are with supporting virtual
> > >> threads?
> > >> > > Will they part of 4.2 or planned for later?
> > >> > >
> > >> > > Raymond
> > >> > >
> > >> >
> > >> >
> > >> > --
> > >> > Claus Ibsen
> > >> > -
> > >> > @davsclaus
> > >> > Camel in Action 2: https://www.manning.com/ibsen2
> > >> >
> > >>
> > >
> >
>


Re: Camel & Virtual threads

2023-09-01 Thread ski n
Kotlin Coroutines and Java Virtual Threads are conceptually very similar.
In details and implementation they are different, of course. A good
presentation on comparing coroutines and virtual threads by Urs Peter:

https://www.youtube.com/watch?v=bOLChQ3fFQo

I was just referencing Kotlin Coroutines btw, for Camel only virtual
threads are relevant.

On Fri, Sep 1, 2023 at 11:01 AM bukaj_s  wrote:

> sry I meant executor.
>
> On Fri, 1 Sept 2023, 10:57 bukaj_s,  wrote:
>
> > You are confusing coroutines and virtual threads.
> > Afaik you can try to use virtual thread pool, question is how much
> > synchronization is camel using under the hood.
> >
> > On Fri, 1 Sept 2023, 10:34 ski n,  wrote:
> >
> >> OK, thanks. It will take some (couple of years) before most libraries
> are
> >> catching up.
> >>
> >> At least, Spring Boot will already support Java 21 with virtual threads
> in
> >> their next release (
> >> https://spring.io/blog/2023/08/24/spring-boot-3-2-0-m2-available-now).
> I
> >> don't know exactly how they do it, but they ship Spring as a multi
> release
> >> Jar for this purpose. When running Spring on Java 21 you can enable it (
> >>
> >>
> https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2.0-M1-Release-Notes#support-for-virtual-threads
> >> ).
> >>
> >> I was thinking more or less in the same lines for Camel. For most of the
> >> cases the underlying libraries needs to be updated, but for some stuff
> >> like
> >> Seda or Stream caching this may already work from within the libraries
> own
> >> code.
> >>
> >> Raymond
> >>
> >>
> >>
> >>
> >>
> >>
> >> On Fri, Sep 1, 2023 at 9:36 AM Claus Ibsen 
> wrote:
> >>
> >> > Hi
> >> >
> >> > No plan for virtual threads - this relies on 3rd party libraries and
> >> many
> >> > other frameworks starting to adopt them as well, which means Java 21
> as
> >> > minimum base version.
> >> > Support for Java 21 is to run on JDK21. JDK17 will be primary
> supported,
> >> > and 21 secondary, that is the plan for this year.
> >> >
> >> >
> >> > On Fri, Sep 1, 2023 at 9:34 AM ski n 
> wrote:
> >> >
> >> > > In integration there is a lot of Async I/O (calling disk, databases,
> >> > api's
> >> > > and other external systems). Though Camel is very fast, it's mostly
> >> these
> >> > > async I/O calls that take time and eat a lot of platform threads.
> >> > >
> >> > > For example:
> >> > >
> >> > > from("direct:start")
> >> > >   .log("some log") //this takes less than 1 ms
> >> > >   .setHeader(Exchange.HTTP_URI, constant("http://someapi;)) //this
> >> takes
> >> > > less than 1 ms
> >> > >   .to("http://someapi;) //this takes 3 seconds
> >> > >   .setHeader("Result","Done") //this takes less than 1 ms
> >> > >   .to("sql://insertindatabase")  //this takes less than 1 seconds
> >> > >   ;
> >> > >
> >> > > One solution to this is using virtual threads. They are already part
> >> of
> >> > > Kotlin (coroutines), but now coming to Java as well in Java 21
> >> (release
> >> > > 19th September).
> >> > >
> >> > > In the Camel 4 blog "What's new" it states that:
> >> > >
> >> > > "We plan to support Java 21 on next LTS released by the end of this
> >> > year."
> >> > >
> >> > > Camel next LTS release (4.2) is expected around December.
> >> > >
> >> > > I was wondering what the plans here are with supporting virtual
> >> threads?
> >> > > Will they part of 4.2 or planned for later?
> >> > >
> >> > > Raymond
> >> > >
> >> >
> >> >
> >> > --
> >> > Claus Ibsen
> >> > -
> >> > @davsclaus
> >> > Camel in Action 2: https://www.manning.com/ibsen2
> >> >
> >>
> >
>


Re: Camel & Virtual threads

2023-09-01 Thread bukaj_s
sry I meant executor.

On Fri, 1 Sept 2023, 10:57 bukaj_s,  wrote:

> You are confusing coroutines and virtual threads.
> Afaik you can try to use virtual thread pool, question is how much
> synchronization is camel using under the hood.
>
> On Fri, 1 Sept 2023, 10:34 ski n,  wrote:
>
>> OK, thanks. It will take some (couple of years) before most libraries are
>> catching up.
>>
>> At least, Spring Boot will already support Java 21 with virtual threads in
>> their next release (
>> https://spring.io/blog/2023/08/24/spring-boot-3-2-0-m2-available-now). I
>> don't know exactly how they do it, but they ship Spring as a multi release
>> Jar for this purpose. When running Spring on Java 21 you can enable it (
>>
>> https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2.0-M1-Release-Notes#support-for-virtual-threads
>> ).
>>
>> I was thinking more or less in the same lines for Camel. For most of the
>> cases the underlying libraries needs to be updated, but for some stuff
>> like
>> Seda or Stream caching this may already work from within the libraries own
>> code.
>>
>> Raymond
>>
>>
>>
>>
>>
>>
>> On Fri, Sep 1, 2023 at 9:36 AM Claus Ibsen  wrote:
>>
>> > Hi
>> >
>> > No plan for virtual threads - this relies on 3rd party libraries and
>> many
>> > other frameworks starting to adopt them as well, which means Java 21 as
>> > minimum base version.
>> > Support for Java 21 is to run on JDK21. JDK17 will be primary supported,
>> > and 21 secondary, that is the plan for this year.
>> >
>> >
>> > On Fri, Sep 1, 2023 at 9:34 AM ski n  wrote:
>> >
>> > > In integration there is a lot of Async I/O (calling disk, databases,
>> > api's
>> > > and other external systems). Though Camel is very fast, it's mostly
>> these
>> > > async I/O calls that take time and eat a lot of platform threads.
>> > >
>> > > For example:
>> > >
>> > > from("direct:start")
>> > >   .log("some log") //this takes less than 1 ms
>> > >   .setHeader(Exchange.HTTP_URI, constant("http://someapi;)) //this
>> takes
>> > > less than 1 ms
>> > >   .to("http://someapi;) //this takes 3 seconds
>> > >   .setHeader("Result","Done") //this takes less than 1 ms
>> > >   .to("sql://insertindatabase")  //this takes less than 1 seconds
>> > >   ;
>> > >
>> > > One solution to this is using virtual threads. They are already part
>> of
>> > > Kotlin (coroutines), but now coming to Java as well in Java 21
>> (release
>> > > 19th September).
>> > >
>> > > In the Camel 4 blog "What's new" it states that:
>> > >
>> > > "We plan to support Java 21 on next LTS released by the end of this
>> > year."
>> > >
>> > > Camel next LTS release (4.2) is expected around December.
>> > >
>> > > I was wondering what the plans here are with supporting virtual
>> threads?
>> > > Will they part of 4.2 or planned for later?
>> > >
>> > > Raymond
>> > >
>> >
>> >
>> > --
>> > Claus Ibsen
>> > -
>> > @davsclaus
>> > Camel in Action 2: https://www.manning.com/ibsen2
>> >
>>
>


Re: Camel & Virtual threads

2023-09-01 Thread bukaj_s
You are confusing coroutines and virtual threads.
Afaik you can try to use virtual thread pool, question is how much
synchronization is camel using under the hood.

On Fri, 1 Sept 2023, 10:34 ski n,  wrote:

> OK, thanks. It will take some (couple of years) before most libraries are
> catching up.
>
> At least, Spring Boot will already support Java 21 with virtual threads in
> their next release (
> https://spring.io/blog/2023/08/24/spring-boot-3-2-0-m2-available-now). I
> don't know exactly how they do it, but they ship Spring as a multi release
> Jar for this purpose. When running Spring on Java 21 you can enable it (
>
> https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2.0-M1-Release-Notes#support-for-virtual-threads
> ).
>
> I was thinking more or less in the same lines for Camel. For most of the
> cases the underlying libraries needs to be updated, but for some stuff like
> Seda or Stream caching this may already work from within the libraries own
> code.
>
> Raymond
>
>
>
>
>
>
> On Fri, Sep 1, 2023 at 9:36 AM Claus Ibsen  wrote:
>
> > Hi
> >
> > No plan for virtual threads - this relies on 3rd party libraries and many
> > other frameworks starting to adopt them as well, which means Java 21 as
> > minimum base version.
> > Support for Java 21 is to run on JDK21. JDK17 will be primary supported,
> > and 21 secondary, that is the plan for this year.
> >
> >
> > On Fri, Sep 1, 2023 at 9:34 AM ski n  wrote:
> >
> > > In integration there is a lot of Async I/O (calling disk, databases,
> > api's
> > > and other external systems). Though Camel is very fast, it's mostly
> these
> > > async I/O calls that take time and eat a lot of platform threads.
> > >
> > > For example:
> > >
> > > from("direct:start")
> > >   .log("some log") //this takes less than 1 ms
> > >   .setHeader(Exchange.HTTP_URI, constant("http://someapi;)) //this
> takes
> > > less than 1 ms
> > >   .to("http://someapi;) //this takes 3 seconds
> > >   .setHeader("Result","Done") //this takes less than 1 ms
> > >   .to("sql://insertindatabase")  //this takes less than 1 seconds
> > >   ;
> > >
> > > One solution to this is using virtual threads. They are already part of
> > > Kotlin (coroutines), but now coming to Java as well in Java 21 (release
> > > 19th September).
> > >
> > > In the Camel 4 blog "What's new" it states that:
> > >
> > > "We plan to support Java 21 on next LTS released by the end of this
> > year."
> > >
> > > Camel next LTS release (4.2) is expected around December.
> > >
> > > I was wondering what the plans here are with supporting virtual
> threads?
> > > Will they part of 4.2 or planned for later?
> > >
> > > Raymond
> > >
> >
> >
> > --
> > Claus Ibsen
> > -
> > @davsclaus
> > Camel in Action 2: https://www.manning.com/ibsen2
> >
>


Re: Camel & Virtual threads

2023-09-01 Thread ski n
OK, thanks. It will take some (couple of years) before most libraries are
catching up.

At least, Spring Boot will already support Java 21 with virtual threads in
their next release (
https://spring.io/blog/2023/08/24/spring-boot-3-2-0-m2-available-now). I
don't know exactly how they do it, but they ship Spring as a multi release
Jar for this purpose. When running Spring on Java 21 you can enable it (
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2.0-M1-Release-Notes#support-for-virtual-threads
).

I was thinking more or less in the same lines for Camel. For most of the
cases the underlying libraries needs to be updated, but for some stuff like
Seda or Stream caching this may already work from within the libraries own
code.

Raymond






On Fri, Sep 1, 2023 at 9:36 AM Claus Ibsen  wrote:

> Hi
>
> No plan for virtual threads - this relies on 3rd party libraries and many
> other frameworks starting to adopt them as well, which means Java 21 as
> minimum base version.
> Support for Java 21 is to run on JDK21. JDK17 will be primary supported,
> and 21 secondary, that is the plan for this year.
>
>
> On Fri, Sep 1, 2023 at 9:34 AM ski n  wrote:
>
> > In integration there is a lot of Async I/O (calling disk, databases,
> api's
> > and other external systems). Though Camel is very fast, it's mostly these
> > async I/O calls that take time and eat a lot of platform threads.
> >
> > For example:
> >
> > from("direct:start")
> >   .log("some log") //this takes less than 1 ms
> >   .setHeader(Exchange.HTTP_URI, constant("http://someapi;)) //this takes
> > less than 1 ms
> >   .to("http://someapi;) //this takes 3 seconds
> >   .setHeader("Result","Done") //this takes less than 1 ms
> >   .to("sql://insertindatabase")  //this takes less than 1 seconds
> >   ;
> >
> > One solution to this is using virtual threads. They are already part of
> > Kotlin (coroutines), but now coming to Java as well in Java 21 (release
> > 19th September).
> >
> > In the Camel 4 blog "What's new" it states that:
> >
> > "We plan to support Java 21 on next LTS released by the end of this
> year."
> >
> > Camel next LTS release (4.2) is expected around December.
> >
> > I was wondering what the plans here are with supporting virtual threads?
> > Will they part of 4.2 or planned for later?
> >
> > Raymond
> >
>
>
> --
> Claus Ibsen
> -
> @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>


Re: Camel & Virtual threads

2023-09-01 Thread Claus Ibsen
Hi

No plan for virtual threads - this relies on 3rd party libraries and many
other frameworks starting to adopt them as well, which means Java 21 as
minimum base version.
Support for Java 21 is to run on JDK21. JDK17 will be primary supported,
and 21 secondary, that is the plan for this year.


On Fri, Sep 1, 2023 at 9:34 AM ski n  wrote:

> In integration there is a lot of Async I/O (calling disk, databases, api's
> and other external systems). Though Camel is very fast, it's mostly these
> async I/O calls that take time and eat a lot of platform threads.
>
> For example:
>
> from("direct:start")
>   .log("some log") //this takes less than 1 ms
>   .setHeader(Exchange.HTTP_URI, constant("http://someapi;)) //this takes
> less than 1 ms
>   .to("http://someapi;) //this takes 3 seconds
>   .setHeader("Result","Done") //this takes less than 1 ms
>   .to("sql://insertindatabase")  //this takes less than 1 seconds
>   ;
>
> One solution to this is using virtual threads. They are already part of
> Kotlin (coroutines), but now coming to Java as well in Java 21 (release
> 19th September).
>
> In the Camel 4 blog "What's new" it states that:
>
> "We plan to support Java 21 on next LTS released by the end of this year."
>
> Camel next LTS release (4.2) is expected around December.
>
> I was wondering what the plans here are with supporting virtual threads?
> Will they part of 4.2 or planned for later?
>
> Raymond
>


-- 
Claus Ibsen
-
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2


Camel & Virtual threads

2023-09-01 Thread ski n
In integration there is a lot of Async I/O (calling disk, databases, api's
and other external systems). Though Camel is very fast, it's mostly these
async I/O calls that take time and eat a lot of platform threads.

For example:

from("direct:start")
  .log("some log") //this takes less than 1 ms
  .setHeader(Exchange.HTTP_URI, constant("http://someapi;)) //this takes
less than 1 ms
  .to("http://someapi;) //this takes 3 seconds
  .setHeader("Result","Done") //this takes less than 1 ms
  .to("sql://insertindatabase")  //this takes less than 1 seconds
  ;

One solution to this is using virtual threads. They are already part of
Kotlin (coroutines), but now coming to Java as well in Java 21 (release
19th September).

In the Camel 4 blog "What's new" it states that:

"We plan to support Java 21 on next LTS released by the end of this year."

Camel next LTS release (4.2) is expected around December.

I was wondering what the plans here are with supporting virtual threads?
Will they part of 4.2 or planned for later?

Raymond