question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a simple `StreamMessageAndWriter` for a dedicated event loop

See original GitHub issue

A DefaultStreamMessage is a thread-safe StreamMessageAndWriter for multiple producder. Some technics are used for concurrency such as:

In some cases, we can write and read elements in a single event loop. For example, the HttpObjects for DecodedHttpRequest and DecodedHttpResponse are always written in an event loop with channelRead event. https://github.com/line/armeria/blob/002e24970fb71cbf7bb27697f95367499a19588c/core/src/main/java/com/linecorp/armeria/client/Http1ResponseDecoder.java#L185 https://github.com/line/armeria/blob/6f93315ba003f167788d5f4f1c6d7464387444bc/core/src/main/java/com/linecorp/armeria/server/Http1RequestDecoder.java#L248

Furthermore, we don’t directly expose the DecodedHttpRequest and DecodedHttpResponse for gRPC services and clients. It also is subscribed by the event loop which is used for writing. https://github.com/line/armeria/blob/207c5e038f59802dca769936a50e219a5fe308ea/grpc/src/main/java/com/linecorp/armeria/server/grpc/ArmeriaServerCall.java#L645-L649 It would be efficient to add a non-thread-safe version of StreamMessageAndWriter and use it for handling encoding and decoding HTTP layer for gRPC service and client.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
ikhooncommented, May 28, 2021

we can’t prevent subscribers from calling subscribe(), request() and close() on DecodedHttp[Request|Response].

That is true for HTTP protocol and REST. A HttpRequest and Response is directly exposed to users with HttpService and WebClient. Users can subscribe to the Publisher with their own Subscriber. Some thread safety is required for the Publisher.

However, We don’t expose our HttpRequest to users for gRPC services.

  • ArmeriaServerCall subscribes to HttpRequest with ctx.eventLoop() for decoding gRPC frames
  • The decoded gRPC messages passed to a gRPC stub. Finally users will get a unary message or a stream messages through gRPC’s StreamObserver

Though a service is RPC, a HttpRequest is exposed to users by decorators. But users can not subscribe to the Publisher directly because Armeria’s StreamMessage should be subscribed only once. I think the stream duplicator could take care of the safety for decorators.

One thing I think we can do is modify to not use MpscChunkedArrayQueue since write signals will only be performed from armeria event loops.

Agreed. We don’t need to use MpscChunkedArrayQueue for decoded request and response.

1reaction
ikhooncommented, May 29, 2021

The current code currently doesn’t know whether a request is grpc (and whether to create a thread-unsafe DecodedHttpRequest) in Http[1|2]RequestDecoder. Maybe we can looks at a header value like content-type for this though…

I guess this means if the user calls subscribe/abort, the grpc request fails to reach the designated grpc service.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chapter 7. EventLoop and threading model - Netty in Action
In this chapter we'll examine Netty's threading model in detail. It's powerful but easy to use and, as usual with Netty, aims to...
Read more >
Node JS Architecture - Single Threaded Event Loop
Node JS Platform uses “Single Threaded Event Loop” architecture to handle multiple concurrent clients. Then how it really handles concurrent ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found