kezhenxu94 commented on code in PR #250: URL: https://github.com/apache/skywalking-python/pull/250#discussion_r1020675932
########## docs/en/profiling/profiling.md: ########## @@ -0,0 +1,83 @@ +# how does threading-profiler (the default mode) work Review Comment: ```suggestion # How does threading-profiler (the default mode) work ``` ########## docs/en/profiling/profiling.md: ########## @@ -0,0 +1,83 @@ +# how does threading-profiler (the default mode) work + +These [skywalking-profiling](https://skywalking.apache.org/blog/2020-04-13-apache-skywalking-profiling/#profiling-in-production) [skywalking-python-profiling](https://skywalking.apache.org/blog/2021-09-12-skywalking-python-profiling/) documents described how the threading-profiler works + +And this figure demonstrated how the profiler works as well: + + +```mermaid +sequenceDiagram + API->>+working thread: get: /api/v1/user/ + rect rgb(0,200,0) + API->>+profiling thread: start profiling + profiling thread->>working thread: snapshot + profiling thread->>working thread: snapshot + profiling thread->>working thread: snapshot + profiling thread->>-working thread: snapshot + end + working thread-->>-API: response +``` + + +It works well with threading mode because the whole process will be executed in **the same** thread, so the profiling thread can fetch the complete profiling info of the process of the API request. + +# why doesn't threading-profiler work in greenlet mode Review Comment: ```suggestion # Why doesn't threading-profiler work in greenlet mode ``` ########## docs/en/profiling/profiling.md: ########## @@ -0,0 +1,83 @@ +# how does threading-profiler (the default mode) work + +These [skywalking-profiling](https://skywalking.apache.org/blog/2020-04-13-apache-skywalking-profiling/#profiling-in-production) [skywalking-python-profiling](https://skywalking.apache.org/blog/2021-09-12-skywalking-python-profiling/) documents described how the threading-profiler works Review Comment: ```suggestion These blogs [skywalking-profiling](https://skywalking.apache.org/blog/2020-04-13-apache-skywalking-profiling/#profiling-in-production) and [skywalking-python-profiling](https://skywalking.apache.org/blog/2021-09-12-skywalking-python-profiling/) described how the threading-profiler works ``` ########## docs/en/profiling/profiling.md: ########## @@ -0,0 +1,83 @@ +# how does threading-profiler (the default mode) work + +These [skywalking-profiling](https://skywalking.apache.org/blog/2020-04-13-apache-skywalking-profiling/#profiling-in-production) [skywalking-python-profiling](https://skywalking.apache.org/blog/2021-09-12-skywalking-python-profiling/) documents described how the threading-profiler works + +And this figure demonstrated how the profiler works as well: + + +```mermaid +sequenceDiagram + API->>+working thread: get: /api/v1/user/ + rect rgb(0,200,0) + API->>+profiling thread: start profiling + profiling thread->>working thread: snapshot + profiling thread->>working thread: snapshot + profiling thread->>working thread: snapshot + profiling thread->>-working thread: snapshot + end + working thread-->>-API: response +``` + + +It works well with threading mode because the whole process will be executed in **the same** thread, so the profiling thread can fetch the complete profiling info of the process of the API request. + +# why doesn't threading-profiler work in greenlet mode +When the python program runs with gevent + greenlet, the process would be like this: + + + +```mermaid +sequenceDiagram + API->>+working thread 1: get: /api/v1/user/ + rect rgb(0,200,0) + greenlet.HUB-->>+working thread 1: swap in the profiled greenlet + API->>+profiling thread: start profiling + profiling thread->>working thread 1: snapshot + working thread 1-->>-greenlet.HUB : swap out the profiled greenlet + end + greenlet.HUB-->>+working thread 1: swap in the other greenlet + profiling thread->>working thread 1: snapshot + greenlet.HUB-->>+working thread 2: swap in the profiled greenlet + profiling thread->>working thread 1: snapshot + profiling thread->>working thread 1: snapshot + working thread 2-->-greenlet.HUB : swap out the profiled greenlet + profiling thread->>working thread 1: snapshot + profiling thread->>-working thread 1: snapshot + working thread 1-->>-greenlet.HUB : swap out the other greenlet + working thread 1-->>-API: response +``` + + +In this circumstance, the snapshot of the working thread includes multi contexts of different greenlets, which will make skywalking confusing to build the trace stack. Review Comment: ```suggestion In this circumstance, the snapshot of the working thread includes multi contexts of different greenlets, which will make skywalking confused to build the trace stack. ``` ########## docs/en/profiling/profiling.md: ########## @@ -0,0 +1,83 @@ +# how does threading-profiler (the default mode) work + +These [skywalking-profiling](https://skywalking.apache.org/blog/2020-04-13-apache-skywalking-profiling/#profiling-in-production) [skywalking-python-profiling](https://skywalking.apache.org/blog/2021-09-12-skywalking-python-profiling/) documents described how the threading-profiler works + +And this figure demonstrated how the profiler works as well: + + +```mermaid +sequenceDiagram + API->>+working thread: get: /api/v1/user/ + rect rgb(0,200,0) + API->>+profiling thread: start profiling + profiling thread->>working thread: snapshot + profiling thread->>working thread: snapshot + profiling thread->>working thread: snapshot + profiling thread->>-working thread: snapshot + end + working thread-->>-API: response +``` + + +It works well with threading mode because the whole process will be executed in **the same** thread, so the profiling thread can fetch the complete profiling info of the process of the API request. + +# why doesn't threading-profiler work in greenlet mode +When the python program runs with gevent + greenlet, the process would be like this: + + + +```mermaid +sequenceDiagram + API->>+working thread 1: get: /api/v1/user/ + rect rgb(0,200,0) + greenlet.HUB-->>+working thread 1: swap in the profiled greenlet + API->>+profiling thread: start profiling + profiling thread->>working thread 1: snapshot + working thread 1-->>-greenlet.HUB : swap out the profiled greenlet + end + greenlet.HUB-->>+working thread 1: swap in the other greenlet + profiling thread->>working thread 1: snapshot + greenlet.HUB-->>+working thread 2: swap in the profiled greenlet + profiling thread->>working thread 1: snapshot + profiling thread->>working thread 1: snapshot + working thread 2-->-greenlet.HUB : swap out the profiled greenlet + profiling thread->>working thread 1: snapshot + profiling thread->>-working thread 1: snapshot + working thread 1-->>-greenlet.HUB : swap out the other greenlet + working thread 1-->>-API: response +``` + + +In this circumstance, the snapshot of the working thread includes multi contexts of different greenlets, which will make skywalking confusing to build the trace stack. + + +Fortunately, greenlet has an API for profiling, the doc is [here](https://greenlet.readthedocs.io/en/latest/tracing.html). We can implement a greenlet profiler to solute this issue. + + +# how the greenlet profiler works Review Comment: ```suggestion # How the greenlet profiler works ``` ########## docs/en/profiling/profiling.md: ########## @@ -0,0 +1,83 @@ +# how does threading-profiler (the default mode) work + +These [skywalking-profiling](https://skywalking.apache.org/blog/2020-04-13-apache-skywalking-profiling/#profiling-in-production) [skywalking-python-profiling](https://skywalking.apache.org/blog/2021-09-12-skywalking-python-profiling/) documents described how the threading-profiler works + +And this figure demonstrated how the profiler works as well: + + +```mermaid +sequenceDiagram + API->>+working thread: get: /api/v1/user/ + rect rgb(0,200,0) + API->>+profiling thread: start profiling + profiling thread->>working thread: snapshot + profiling thread->>working thread: snapshot + profiling thread->>working thread: snapshot + profiling thread->>-working thread: snapshot + end + working thread-->>-API: response +``` + + +It works well with threading mode because the whole process will be executed in **the same** thread, so the profiling thread can fetch the complete profiling info of the process of the API request. + +# why doesn't threading-profiler work in greenlet mode +When the python program runs with gevent + greenlet, the process would be like this: + + + +```mermaid +sequenceDiagram + API->>+working thread 1: get: /api/v1/user/ + rect rgb(0,200,0) + greenlet.HUB-->>+working thread 1: swap in the profiled greenlet + API->>+profiling thread: start profiling + profiling thread->>working thread 1: snapshot + working thread 1-->>-greenlet.HUB : swap out the profiled greenlet + end + greenlet.HUB-->>+working thread 1: swap in the other greenlet + profiling thread->>working thread 1: snapshot + greenlet.HUB-->>+working thread 2: swap in the profiled greenlet + profiling thread->>working thread 1: snapshot + profiling thread->>working thread 1: snapshot + working thread 2-->-greenlet.HUB : swap out the profiled greenlet + profiling thread->>working thread 1: snapshot + profiling thread->>-working thread 1: snapshot + working thread 1-->>-greenlet.HUB : swap out the other greenlet + working thread 1-->>-API: response +``` + + +In this circumstance, the snapshot of the working thread includes multi contexts of different greenlets, which will make skywalking confusing to build the trace stack. + + +Fortunately, greenlet has an API for profiling, the doc is [here](https://greenlet.readthedocs.io/en/latest/tracing.html). We can implement a greenlet profiler to solute this issue. Review Comment: ```suggestion Fortunately, greenlet has an API for profiling, the doc is [here](https://greenlet.readthedocs.io/en/latest/tracing.html). We can implement a greenlet profiler to solve this issue. ``` ########## docs/en/profiling/profiling.md: ########## @@ -0,0 +1,83 @@ +# how does threading-profiler (the default mode) work + +These [skywalking-profiling](https://skywalking.apache.org/blog/2020-04-13-apache-skywalking-profiling/#profiling-in-production) [skywalking-python-profiling](https://skywalking.apache.org/blog/2021-09-12-skywalking-python-profiling/) documents described how the threading-profiler works + +And this figure demonstrated how the profiler works as well: Review Comment: ```suggestion And this figure demonstrates how the profiler works as well: ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
