Skip to content

Commit 26d0dc9

Browse files
committed
Update again
1 parent f685e02 commit 26d0dc9

16 files changed

+273
-230
lines changed

armeria_client_detail.md renamed to armeria_internal.md

+32-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- `Subscriber.onComplete()` or `Subscriber.onError(throwable)` is called depending on the situation.
1616
- Reactive Streams implementations in Armeria
1717
- `Publisher` (`StreamMessage`)
18-
- `HttpRequest` and `HttpResponse` implement it
18+
- `HttpRequest` and `HttpResponse` extends it
1919
- `DefaultStreamMessage`
2020
- Queue based
2121
- `AbstractStreamMessageDuplicator`
@@ -27,12 +27,13 @@
2727
- `FilteredStreamMessage`
2828
- What if we want to add some header in the decorator?
2929
- `DeferredStreamMessage`
30-
- Let's implement my own subscriber.
30+
- Deferred?
31+
- Let's implement our own subscriber.
3132
- `Subscriber`
3233
- `HttpMessageAggregator`
33-
- `HttpClient.execute(...)` returns an `HttpResponse` which is one of `StreamMessage`s
34+
- `HttpClient.execute(...)` returns an `HttpResponse`.
3435
- You can aggregate the `HttpResponse` using `HttpResponse.aggregate()`.
35-
- Then, it will return a `CompletableFuture<AggregatedHttpMessage>`.
36+
- Then, it will return a `CompletableFuture<AggregatedHttpResponse>`.
3637
- In `HttpResponse.aggregate()`, `HttpMessageAggregator` which is a `Subscriber`, subscribes
3738
the `StreamMessage` and it collects all the response.
3839
- `HttpRequestSubscriber`
@@ -45,21 +46,28 @@
4546
it consumes all the elements.
4647
- `Http1ResponseDecoder` implements `ChannelInboundHandler`.
4748
- `HttpResponseSubscriber` is used by the server side.
48-
49+
- Let's build a simple decorating service.
50+
- The difference between `HttpRequest` and `HttpResponse`
51+
4952
### Event Loop
5053

5154
- Who does the all jobs above?
52-
- What is Event loop?
55+
- What is the event loop?
5356
- A general term which waits for and dispatches events or messages in a program.
5457
- We use `EventLoop` in Netty.
5558
- Handles all the I/O operations for a `Channel` once registered.
5659
- One `EventLoop` instance usually handles more than one `Channel` but this may depend on implementation details and internals.
5760
- `EventLoop` extends Java's `ScheduledExecutorService`.
5861
- Events and Tasks are executed in order received.
5962
- Let's see what it really does with [`EpollEventLoop`](https://github.com/netty/netty/blob/05e5ab1ecb98963604d686c1f59b2196cf73e244/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollEventLoop.java#L257)
63+
- From the point of view of the `EventLoop`s
6064
- How many `EventLoop`s ?
6165
- No official formula
6266
- Nthreads = Ncpu * Ucpu * (1 + W/C)
67+
- Let's build a simple reactive server.
68+
69+
### Request flow
70+
6371
- Sending an `HttpRequest`
6472
- `HttpClient` -> `UserClient` -> HTTP decorators -> `HttpClientDelegate` -> `HttpSessionHandler`
6573
- Creates a `ClientRequestContext` in `UserClient`
@@ -71,13 +79,27 @@
7179
- So the thread who calls `HttpClient.execute()` and write to the `Channel` can be different.
7280
- Receiving an `HttpResponse`
7381
- The thread who writes to the response is the `EventLoop` you used when sending the `Request`.
82+
- Thrift client
83+
- `HelloSerivce.Iface()` or `AsyncIface()` -> `THttpClientInvocationHandler` -> `DefaultTHttpClient(UserClient)` ->
84+
RPC decorators -> `THttpClientDelegate` -> HTTP decorators -> `HttpClientDelegate`
85+
86+
### `RequestContext`
87+
88+
- Thread-local storage
89+
- `makeContextAware`
7490

7591
### Connection pooling
7692

93+
- How many connections we have?
94+
- HTTP/1.1
95+
- What's the [pipelining](https://en.wikipedia.org/wiki/HTTP_pipelining)?
96+
- [In Armeria](https://github.com/line/armeria/blob/armeria-0.88.0/core/src/main/java/com/linecorp/armeria/client/HttpClientDelegate.java#L224)
97+
- HTTP/2
98+
- Why is it possible just to have one connection?
99+
- What Content-length header is for?
100+
- [Frame format](https://tools.ietf.org/html/rfc7540#section-4.1)
101+
77102
- Creates a [`PoolKey`](https://github.com/line/armeria/blob/d90aea4704982df06251c1132bbc4da33301725d/core/src/main/java/com/linecorp/armeria/client/HttpClientDelegate.java#L104) with host, ip, port and session protocol.
78103
- Gets a [`KeyedChannelPool`](https://github.com/line/armeria/blob/d90aea4704982df06251c1132bbc4da33301725d/core/src/main/java/com/linecorp/armeria/client/HttpClientFactory.java#L289) using the `EventLoop`.
79-
- Gets a healthy `Channel` from the pool using the key.
80-
81-
### Thrift client
82104

83-
- `HelloSerivce.Iface()` or `AsyncIface()` -> `THttpClientInvocationHandler` -> `DefaultTHttpClient(UserClient)` -> RPC decorators -> `THttpClientDelegate` -> HTTP decorators -> `HttpClientDelegate`
105+
### Let's build a proxy server

build.gradle

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
plugins {
2+
id "io.spring.dependency-management" version "1.0.8.RELEASE"
3+
}
4+
5+
apply plugin: 'java'
6+
apply plugin: 'idea'
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
dependencyManagement {
13+
imports {
14+
mavenBom 'com.linecorp.armeria:armeria-bom:0.88.0'
15+
}
16+
}
17+
18+
dependencies {
19+
compile 'com.linecorp.armeria:armeria'
20+
21+
testCompile 'com.linecorp.armeria:armeria-testing-junit'
22+
testCompile 'org.assertj:assertj-core:3.12.2'
23+
testCompile 'org.awaitility:awaitility:4.0.0-rc1'
24+
}
25+
26+
tasks.withType(JavaCompile) {
27+
sourceCompatibility = '1.8'
28+
targetCompatibility = '1.8'
29+
options.encoding = 'UTF-8'
30+
options.debug = true
31+
options.compilerArgs += '-parameters'
32+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Jul 27 11:26:30 KST 2018
1+
#Thu Jul 25 12:34:08 KST 2019
2+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
23
distributionBase=GRADLE_USER_HOME
34
distributionPath=wrapper/dists
4-
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6+
zipStoreBase=GRADLE_USER_HOME

samples/gradlew renamed to gradlew

File renamed without changes.
File renamed without changes.

samples/build.gradle

-40
This file was deleted.

samples/settings.gradle

-2
This file was deleted.

samples/src/test/java/MyTest.java

-85
This file was deleted.

samples/src/test/java/WithEventLoop.java

-90
This file was deleted.

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'misc'

src/main/java/DecoratingService.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import com.linecorp.armeria.client.HttpClient;
2+
import com.linecorp.armeria.common.AggregatedHttpResponse;
3+
import com.linecorp.armeria.common.HttpResponse;
4+
5+
public class DecoratingService {
6+
7+
public static void main(String[] args) {
8+
// build server
9+
10+
sendRequest();
11+
}
12+
13+
private static void sendRequest() {
14+
final HttpClient client = HttpClient.of("http://127.0.0.1:8080");
15+
final HttpResponse httpResponse = client.get("/test");
16+
final AggregatedHttpResponse res = httpResponse.aggregate().join();
17+
System.err.println(res.headers());
18+
}
19+
}

0 commit comments

Comments
 (0)