--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/CALbocOmUBsVEkkZXdf-1wmjsgZyvRCCX_JnXTroO21PBxzocbA%40mail.gmail.com.
Hi,
few days ago, we (me, Michal, Martin and Matej) discussed request context activation/propagation in the context of gRPC, but realized this has (or may have) broader impact. Hence we wanted to discuss this publicly.
What happens now in gRPC (but seemingly also in SSE, and maybe elsewhere too?) is that the request context is activated at the beginning of service call processing. The request context state is then captured, and activated again on each asynchronous callback pertaining to the same gRPC service call. Only when the gRPC call finishes is the request context destroyed.
This means that, for example, gRPC calls that use a database will each have their own Hibernate session, and that Hibernate session will be available for the entire duration of the gRPC call (because sessions are request-scoped, including Hibernate Reactive).
This sounds nice, but the thing with gRPC calls is that they can be streaming. Such stream may last for hours or days – and for sure you don’t want a session open for so long.
We could think of a few options how to tackle this:
- Keep doing what we’re doing. Works nice, until it doesn’t.
- Stop doing what we’re doing. Request context wouldn’t be propagated to the individual callbacks of a gRPC service call. Prevents sessions from living too long, at the cost of each part of the service call having a different session and hence a different transaction (which may lead to perceived data inconsistencies).
- Configurable behavior. It could be opt-in or opt-out, but either way, user would declare if the stream is long-running or not, which would then control how request context is activated/propagated.
Any thoughts? Other options?
Thanks,
LT
--
On Tue, 22 Jun 2021 at 00:06, Ladislav Thon <lad...@gmail.com> wrote:Hi,
few days ago, we (me, Michal, Martin and Matej) discussed request context activation/propagation in the context of gRPC, but realized this has (or may have) broader impact. Hence we wanted to discuss this publicly.
What happens now in gRPC (but seemingly also in SSE, and maybe elsewhere too?) is that the request context is activated at the beginning of service call processing. The request context state is then captured, and activated again on each asynchronous callback pertaining to the same gRPC service call. Only when the gRPC call finishes is the request context destroyed.
This means that, for example, gRPC calls that use a database will each have their own Hibernate session, and that Hibernate session will be available for the entire duration of the gRPC call (because sessions are request-scoped, including Hibernate Reactive).Note that for blocking hibernate sessions are only request scoped if you are not using transactions, otherwise they are transaction scoped. The request scoped session will only be used if you attempt to use hibernate outside a transaction.
@Sanne Grinovero does a EntityManager that is not bound to a transaction tie up any database resources? I would assume it would just get a new connection per operation?
Stuart--
This sounds nice, but the thing with gRPC calls is that they can be streaming. Such stream may last for hours or days – and for sure you don’t want a session open for so long.
We could think of a few options how to tackle this:
- Keep doing what we’re doing. Works nice, until it doesn’t.
- Stop doing what we’re doing. Request context wouldn’t be propagated to the individual callbacks of a gRPC service call. Prevents sessions from living too long, at the cost of each part of the service call having a different session and hence a different transaction (which may lead to perceived data inconsistencies).
- Configurable behavior. It could be opt-in or opt-out, but either way, user would declare if the stream is long-running or not, which would then control how request context is activated/propagated.
Any thoughts? Other options?
Thanks,
LT
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/CALbocOmUBsVEkkZXdf-1wmjsgZyvRCCX_JnXTroO21PBxzocbA%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/CALbocOmUBsVEkkZXdf-1wmjsgZyvRCCX_JnXTroO21PBxzocbA%40mail.gmail.com.
I have no concrete examples -- but quick googling shows that gRPC is used that way, and it's intended to be used that way (among others, of course). What seems to be one of the typical use cases is long-running notification subscriptions.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/CALbocOmFD6aZpC3aTepP1e3tgLkfQq-Ph45NYeZmf8V%2B9O%3DHsg%40mail.gmail.com.
A gRPC channel uses a single HTTP/2 connection, and concurrent calls are multiplexed on that connection. When the number of active calls reaches the connection stream limit, additional calls are queued in the client.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/CALbocOmFD6aZpC3aTepP1e3tgLkfQq-Ph45NYeZmf8V%2B9O%3DHsg%40mail.gmail.com.
On Thu, 24 Jun 2021 at 10:26, Ladislav Thon <lad...@gmail.com> wrote:I have no concrete examples -- but quick googling shows that gRPC is used that way, and it's intended to be used that way (among others, of course). What seems to be one of the typical use cases is long-running notification subscriptions.When it comes to bridging an API to a database, I think it's our user's responsibility to decide how they want to break it up in small transactional units of work: they most likely don't want transactions running for days, which implies having to think about eventual consistency and compensating transactions; how this gets modelled often requires business-specific ad-hoc logic so we can't automate it all transparently, especially conflict resolutions and error handling.What we can do is to help our users to define the boundaries of the smaller atomic transactions they need, and provide the APIs they will need to use within those boundaries.
instead of marking it as longrunning request is it more the other way around
that grpc should consider each streaming interaction a request ?
not sure if that is doable but if not that then some other boundary mechanism; probably manually
as Sanne mentions is the way forward ?
/max
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/CALbocOn6CptwQ7uTqa6JZqZyOw-MZtXVknHx-9VYZNw80W74oQ%40mail.gmail.com.
/max
https://xam.dk/about
Well, yeah, we could think of a way to mark this specially, via an
annotation, and offer an API to do it too.
Even if we go via the API route only, we'll need an annotation to disable
the request context at the very least, or to make sure it's not propagated
and is terminates before the end of the Multi (or gRPC equivalent).I do wonder how many people use this, though, because in the case of SSE,
we barely ever have bug reports, so I assume they're just not used that
much outside of demos.
I still remember many Hibernate cases where customers been running in production
and it worked great for them for long period of times but then on some weird days they lost data or
couldn't scale properly.
root cause: having put sessions into http session or even in a static block in code.
Everything is awesome until it isn't :)
Not saying we have the same exact situation here but I'm sure if there is an API there are
someone using it somehow in ways we don't think they should - and they don't even realise it.
/max
are request-scoped
https://github.com/quarkusio/quarkus/blob/main/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/RequestScopedSessionHolder.java ,
including Hibernate Reactive
https://github.com/quarkusio/quarkus/blob/main/extensions/hibernate-reactive/runtime/src/main/java/io/quarkus/hibernate/reactive/runtime/ReactiveSessionProducer.java
).
This sounds nice, but the thing with gRPC calls is that they can be
streaming. Such stream may last for hours or days – and for sure you don’t
want a session open for so long.
We could think of a few options how to tackle this:
- Keep doing what we’re doing. Works nice, until it doesn’t.
- Stop doing what we’re doing. Request context wouldn’t be propagated
to the individual callbacks of a gRPC service call. Prevents sessions from
living too long, at the cost of each part of the service call having a
different session and hence a different transaction (which may lead to
perceived data inconsistencies).
- Configurable behavior. It could be opt-in or opt-out, but either
way, user would declare if the stream is long-running or not, which would
then control how request context is activated/propagated.Any thoughts? Other options?
Thanks,
LT
--
You received this message because you are subscribed to the Google
Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/quarkus-dev/CALbocOmUBsVEkkZXdf-1wmjsgZyvRCCX_JnXTroO21PBxzocbA%40mail.gmail.com
--
You received this message because you are subscribed to the Google
Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/quarkus-dev/CALbocOmFD6aZpC3aTepP1e3tgLkfQq-Ph45NYeZmf8V%2B9O%3DHsg%40mail.gmail.com
You received this message because you are subscribed to the Google Groups
"Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/quarkus-dev/CALbocOn6CptwQ7uTqa6JZqZyOw-MZtXVknHx-9VYZNw80W74oQ%40mail.gmail.com
https://groups.google.com/d/msgid/quarkus-dev/CALbocOn6CptwQ7uTqa6JZqZyOw-MZtXVknHx-9VYZNw80W74oQ%40mail.gmail.com?utm_medium=email&utm_source=footer
./max
https://xam.dk/about--
Stéphane Épardaud
/max
https://xam.dk/about