Sunkwan-Kwon opened a new issue #5626: Memory leak of pulsar-function-go 
library regarding time.NewTimer()
URL: https://github.com/apache/pulsar/issues/5626
 
 
   **Describe the bug**
   There is a memory leak in the pulsar-function-go library.
   I reported an issue regarding the package(#5589), but this report is another 
one.
   
   It is related to KillAfterIdleMs configuration value. If I set the value to 
0, time.NewTimer() function has occupied more memory indefinitely. Refer to 
`pprof ` result of that below.
   ```
   # go tool pprof -top http://localhost:6060/debug/pprof/heap
   Fetching profile over HTTP from http://localhost:6060/debug/pprof/heap
   Saved profile in 
/root/pprof/pprof.simple-worker.alloc_objects.alloc_space.inuse_objects.inuse_space.713.pb.gz
   File: simple-worker
   Build ID: 2a730ff40dbea9318c3ce868f33ecc2e69304de8
   Type: inuse_space
   Time: Nov 12, 2019 at 12:27pm (KST)
   Showing nodes accounting for 31.29MB, 100% of 31.29MB total
         flat  flat%   sum%        cum   cum%
         30MB 95.88% 95.88%    31.29MB   100%  time.NewTimer
       1.29MB  4.12%   100%     1.29MB  4.12%  time.startTimer
            0     0%   100%    31.29MB   100%  
github.com/apache/pulsar/pulsar-function-go/pf.(*goInstance).startFunction
            0     0%   100%    31.29MB   100%  
github.com/apache/pulsar/pulsar-function-go/pf.Start
            0     0%   100%    31.29MB   100%  main.main
            0     0%   100%    31.29MB   100%  runtime.main
            0     0%   100%    31.29MB   100%  time.After
   ```
   If I set `KillAfterIdleMs` value higher than 0, the memory leak didn't 
appear.
   
   In order to fix this issue, I investigated the source code and I could find 
the code that caused the problem. Fortunately, It seems has been fixed now. So 
I will send a pull request for that.
   
   **To Reproduce**
   Steps to reproduce the behavior:
   1. Prepare a pulsar cluster with standalone mode.
   2. Prepare a simple pulsar function worker. Refer to the codes below.
   ```
   $ cat simple-worker.go 
   package main
   
   import (
           "context"
           "fmt"
           "net/http"
           _ "net/http/pprof"
   
           "github.com/apache/pulsar/pulsar-function-go/pf"
   )
   
   func main() {
           // go routine for pprof
           go func() {
                   fmt.Println("%+v", http.ListenAndServe("localhost:6060", 
nil))
           }()
   
           pf.Start(testFunction)
   }
   
   func testFunction(ctx context.Context) {
           fmt.Printf("Hello\n")
   }
   ```
   3. Prepare a conf.yaml file for the function worker.
   ```
   ---
   pulsarServiceURL: "pulsar://sunkwan-devpc:6650"
   instanceID: 0
   funcID: "ed5f48f4-8e76-4d30-8b88-6eea1ff3cbf3"
   funcVersion: "12f361a0-67e5-4404-8177-8c328a33e3db"
   maxBufTuples: 1024
   port: 0
   clusterName: "standalone"
   killAfterIdleMs: 0
   tenant: "public"
   nameSpace: "default"
   name: "func-concat"
   className: ''
   #logTopic: 'persistent://public/default/func-concat-logs'
   logTopic: ''
   processingGuarantees: 0
   secretsMap: ''
   runtime: 0
   autoAck: true
   parallelism: 3
   subscriptionType: 0
   timeoutMs: 0
   subscriptionName: ''
   cleanupSubscription: true
   sourceSpecsTopic: "persistent://public/default/func-concat"
   sourceSchemaType: ''
   receiverQueueSize: 1
   #sinkSpecsTopic: "persistent://public/default/func-concat-output"
   #sinkSpecsTopic: ""
   #sinkSchemaType: ''
   #cpu: 1
   #ram: 1073741824
   #disk: 10737418240
   #maxMessageRetries: 0
   #deadLetterTopic: ''
   #regexPatternSubscription: false
   ```
   4. Execute the simple pulsar function worker by command line below.
   ```
   ./simple-worker --instance-conf-path ./conf.yaml
   ```
   5. Send messages to the input topic consecutively.
   6. Check the memory usage and heap status using pprof.
   ```
   # go tool pprof -top http://localhost:6060/debug/pprof/heap
   Fetching profile over HTTP from http://localhost:6060/debug/pprof/heap
   Saved profile in 
/root/pprof/pprof.simple-worker.alloc_objects.alloc_space.inuse_objects.inuse_space.713.pb.gz
   File: simple-worker
   Build ID: 2a730ff40dbea9318c3ce868f33ecc2e69304de8
   Type: inuse_space
   Time: Nov 12, 2019 at 12:27pm (KST)
   Showing nodes accounting for 31.29MB, 100% of 31.29MB total
         flat  flat%   sum%        cum   cum%
         30MB 95.88% 95.88%    31.29MB   100%  time.NewTimer
       1.29MB  4.12%   100%     1.29MB  4.12%  time.startTimer
            0     0%   100%    31.29MB   100%  
github.com/apache/pulsar/pulsar-function-go/pf.(*goInstance).startFunction
            0     0%   100%    31.29MB   100%  
github.com/apache/pulsar/pulsar-function-go/pf.Start
            0     0%   100%    31.29MB   100%  main.main
            0     0%   100%    31.29MB   100%  runtime.main
            0     0%   100%    31.29MB   100%  time.After
   ```
   
   **Expected behavior**
   - Memory usage of pulsar worker process shouldn't be grown indefinitely.
   
   **Screenshots**
   N/A
   
   **Desktop (please complete the following information):**
    - OS: Ubuntu 18.04
   
   **Additional context**
   N/A
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to