Skip to content

Commit 7015b2c

Browse files
committed
update doc
1 parent 68476eb commit 7015b2c

File tree

5 files changed

+127
-4
lines changed

5 files changed

+127
-4
lines changed
44.9 KB
Loading
33.1 KB
Loading

testapps/libevent_http_server/pp_ev_http.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
// Copyright 2020 NAVER Corp
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
// use this file except in compliance with the License. You may obtain a copy
6+
// of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
// License for the specific language governing permissions and limitations under
14+
// the License.
15+
////////////////////////////////////////////////////////////////////////////////
16+
117
#include "pp_ev_http.h"
218
#include "event2/http.h"
319
#include <malloc.h>
@@ -158,8 +174,6 @@ static int pp_evhttp_make_request(struct evhttp_connection *evcon,
158174
req->cb = pp_sub_request_done;
159175
req->cb_arg = ctx;
160176

161-
// todo add pinpoint-header
162-
163177
struct evkeyvalq *output_headers;
164178
output_headers = evhttp_request_get_output_headers(req);
165179

@@ -318,3 +332,5 @@ void pp_free_http_client(pp_http_client_t *client) {
318332
free(client);
319333
}
320334
}
335+
336+
//@author eeliu

testapps/libevent_http_server/pp_ev_http.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
#pragma once
2-
2+
////////////////////////////////////////////////////////////////////////////////
3+
// Copyright 2020 NAVER Corp
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
6+
// use this file except in compliance with the License. You may obtain a copy
7+
// of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
// License for the specific language governing permissions and limitations under
15+
// the License.
16+
////////////////////////////////////////////////////////////////////////////////
317
#include <event2/buffer.h>
418
#include <event2/bufferevent.h>
519
#include <event2/event.h>
@@ -97,3 +111,5 @@ void pinpoint_set_agent_helper(const char *app_name, const char *app_id,
97111
pinpoint_end_trace(node); \
98112
} \
99113
}
114+
115+
//@author eeliu

testapps/libevent_http_server/readme.md

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## Command
44

55
```
6-
$ mkdir build && cd build && make -j
6+
$ mkdir build && cd build && cmake .. && make -j
7+
$ # curl http://localhost:8080/http-client
78
```
89

910
### Thanks
@@ -21,3 +22,93 @@ $ mkdir build && cd build && make -j
2122
2223
![call stack ](call_stack.png)
2324

25+
## Introduction for pinpoint on asynchronous framework
26+
27+
> what's problem in asynchronous framework (event driver)?
28+
29+
In synchronous, we gets trace by it's called order, that is the logical order when handling request, but in asynchronous framework, trace are driven by event, it's the event order. So, we must find a way to recover the logical order.
30+
31+
### Synchronous call flow
32+
33+
![alt text](image.png)
34+
35+
### Asynchronous call flow
36+
37+
> Red line: user A logical flow \
38+
Blue line: user B logical flow
39+
40+
![alt text](image-1.png)
41+
42+
Here is the question, how to separate A and B from mixed call chains ?
43+
44+
>Inspired by nginx
45+
46+
Pass `ctx` to everywhere
47+
48+
```c
49+
#define CTX_MATIC_NUM 0x1357325l
50+
typedef struct {
51+
int magic_num_;
52+
NodeID current_id_; // current trace ID
53+
void *ori_arg_;
54+
void (*on_complete_cb_origin_)(struct evhttp_request *, void *);
55+
void *on_complete_cb_arg_origin_;
56+
57+
void (*http_client_request_cb_)(struct evhttp_request *, void *);
58+
void *http_client_request_done_cb_arg_;
59+
...
60+
} pp_request_context_t;
61+
```
62+
63+
If you want to trace `foo` function,
64+
65+
1. add `ctx` into parameter list
66+
67+
|Old | Now|
68+
|----|----|
69+
|void foo(int a, ...)| void foo(void* ctx, int a,...)|
70+
71+
2. wrapper `foo` function
72+
73+
```c
74+
void foo(void *ctx,int a, ...);
75+
76+
void pp_foo(void *ctx,int a, ...){
77+
...
78+
NodeID trace_id = pinpoint_start_trace(ctx_.current_id_);
79+
foo(ctx,a);
80+
// end current trace and update current_id_
81+
ctx_.current_id_ = pinpoint_end_trace(trace_id);
82+
}
83+
...
84+
call_pp_foo();
85+
...
86+
```
87+
88+
3. what if needs to register a callback function?
89+
90+
Before
91+
```
92+
// some like
93+
async_http_request(.. request_done_call_cb,request_done_call_cb_arg...);
94+
95+
```
96+
Now
97+
```
98+
cxt->origin_request_done_call_cb = request_done_call_cb;
99+
ctx->origin_request_done_call_cb_arg = request_done_call_cb_arg
100+
int pp_request_done_call_cb(arg){
101+
cxt->origin_request_done_call_cb(ctx->origin_request_done_call_cb_arg);
102+
};
103+
104+
async_http_request(ctx,.. pp_request_done_call_cb,ctx,...);
105+
106+
```
107+
108+
While, there are many unknown cases in below list. If you have any question, [create an issue 🙋‍♂️ ](https://github.com/pinpoint-apm/pinpoint-c-agent/issues/new).
109+
110+
111+
112+
113+
114+

0 commit comments

Comments
 (0)