Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nats - Aerospike - Nginx - Websocket High Memory #1297

Closed
byazrail opened this issue Mar 3, 2020 · 25 comments
Closed

Nats - Aerospike - Nginx - Websocket High Memory #1297

byazrail opened this issue Mar 3, 2020 · 25 comments

Comments

@byazrail
Copy link

byazrail commented Mar 3, 2020

Hi,

Own uses;
Nats v2.1.4
Aerospike v4.8.0.5
Nginx
ws-tcp-relay : https://github.com/isobit/ws-tcp-relay

Custom;
Auth.go : https://gist.github.com/byazrail/b44c786ac1604d5699527554724fedc5
Nats Conf, Nginx, Systemd Services Conf : https://gist.github.com/byazrail/3ebe4b2c5a05eb8e7566066bf21a2a2e

It's problem;
The system works very well, but RAM is constantly increasing.
I have to reset nats-server after a while.
Do you have any suggestions on this subject?

@byazrail
Copy link
Author

byazrail commented Mar 3, 2020

I use;
CentOS Linux release 7.7.1908 (Core)
4 x Intel(R) Xeon(R) Gold 6140 CPU @ 2.30GHz
32 GB ram,
Swap 8 GB.

Estimated active users;
300 ~ 700

After a certain time, users drop.
When there are 700 users, 32GB RAM is filled in 24 hours, and Swap section is filled in 24 hours.
Active users are 200, the RAM is still in the same usage.

Average Subscribers 2500.
Average Publish payloads per/subscribers 100KB ~ 1.2MB.

@ripienaar
Copy link
Contributor

what version go aerospike package?

Suggest you use the go memory profiler to figure it out

@byazrail
Copy link
Author

byazrail commented Mar 3, 2020

Aerospike client : https://github.com/aerospike/aerospike-client-go

Suggest you use the go memory profiler to figure it out
How am I going to do this?

@kozlovic
Copy link
Member

kozlovic commented Mar 3, 2020

Start the server with -profile 6060 (or any port that you like). When you start to observe unexplained memory growth, run the following command:

go tool pprof "http://localhost:6060/debug/pprof/heap"

replace localhost and 6060 by the hostname where the server is running and the port you have selected in -profile.
From the (pprof) prompt you can issue some commands such as "top", etc..

@byazrail
Copy link
Author

byazrail commented Mar 3, 2020

Thank you I will test and return again.

@kozlovic
Copy link
Member

kozlovic commented Mar 3, 2020

Actually there were some reports of memory leak on the aerospike client you are using, so look at this issue to see how to use the mem profiler, or if you are affected by that issue: aerospike/aerospike-client-go#230

@ripienaar
Copy link
Contributor

Aerospike client : https://github.com/aerospike/aerospike-client-go

yes, I got the URL from the code, I am asking what version of it you are using in your go mod or how you compile it.

@byazrail
Copy link
Author

byazrail commented Mar 3, 2020

yes, I got the URL from the code, I am asking what version of it you are using in your go mod or how you compile it.

I'm new in Golang.
I do go build in direct source package and get the execute file.
go get github.com/aerospike/aerospike-client-go
I shot it this way.
Go Version: go version go1.13.6 linux / amd64
I'm not entirely sure how to find out the current Aerospike version.

@kozlovic
Copy link
Member

kozlovic commented Mar 3, 2020

Since your modified version of the NATS Server includes the aerospike client, when building, Go should have updated the go.mod/sum. Could you paste the content of the go.mod file in this github issue? Thanks!

@byazrail
Copy link
Author

byazrail commented Mar 3, 2020

Since your modified version of the NATS Server includes the aerospike client, when building, Go should have updated the go.mod/sum. Could you paste the content of the go.mod file in this github issue? Thanks!

[root@dev nats-server-2.1.4]# cat go.mod
module github.com/nats-io/nats-server/v2

require (
github.com/aerospike/aerospike-client-go v2.7.2+incompatible
github.com/elliotchance/phpserialize v1.2.0 // indirect
github.com/go-redis/redis/v7 v7.0.0-beta.6
github.com/kovetskiy/go-php-serialize v0.0.0-20141101074437-71ef41a548d8 // indirect
github.com/nats-io/jwt v0.3.2
github.com/nats-io/nats.go v1.9.1
github.com/nats-io/nkeys v0.1.3
github.com/nats-io/nuid v1.0.1
github.com/techleeone/gophp v0.1.0
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb // indirect
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
golang.org/x/sys v0.0.0-20191010194322-b09406accb47
)

go 1.13

@byazrail
Copy link
Author

byazrail commented Mar 3, 2020

Since your modified version of the NATS Server includes the aerospike client, when building, Go should have updated the go.mod/sum. Could you paste the content of the go.mod file in this github issue? Thanks!

[root@dev nats-server-2.1.4]# cat go.sum
github.com/aerospike/aerospike-client-go v2.7.2+incompatible h1:bWbRf8trg1FhKF7u43KLGNfOH60RlvIgQjpaS107DZ8=
github.com/aerospike/aerospike-client-go v2.7.2+incompatible/go.mod h1:zj8LBEnWBDOVEIJt8LvaRvDG5ARAoa5dBeHaB472NRc=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/elliotchance/phpserialize v1.2.0 h1:bf6HpWHBSp9UM0MqGQGsA0LR2lJZUcEljjhYi4Xb0fw=
github.com/elliotchance/phpserialize v1.2.0/go.mod h1:gt7XX9+ETUcLXbtTKEuyrqW3lcLUAeS/AnGZ2e49TZs=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-redis/redis/v7 v7.0.0-beta.6 h1:ApjPvZNUF+/oVHwrTBQsVOwex5v/WapUUR4bOL2kMFA=
github.com/go-redis/redis/v7 v7.0.0-beta.6/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/kovetskiy/go-php-serialize v0.0.0-20141101074437-71ef41a548d8 h1:5SuynDl9zQBugAPyvRjca4mClezQH954P4fBxdUB7GA=
github.com/kovetskiy/go-php-serialize v0.0.0-20141101074437-71ef41a548d8/go.mod h1:vbjtdVbbitDdc7FZj0ojJf+O/fEqf6Io1OmvIf9sWVg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI=
github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ=
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k=
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/techleeone/gophp v0.1.0 h1:egZLeqwIBm9lnZ3ZkRLIf1nKHFFr/89aH9lvMCClE9o=
github.com/techleeone/gophp v0.1.0/go.mod h1:vFf38I92ZchWPK9yrH/qPs/SL7M4beCwkxfWcvupEBU=
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb h1:ZkM6LRnq40pR1Ox0hTHlnpkcOTuFIDQpZ1IN8rKKhX0=
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qqCB4teTffacDWr7CI+0=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

@kozlovic
Copy link
Member

kozlovic commented Mar 3, 2020

Thanks, seem to be version 2.7.2, which is not quite the latest, but 2.7.3 has only 1 change that I don't think would be related.
If you could proceed with the memory profiling (again, check the aerospike issue I linked to get details on how to gather it) and update this issue with the output. Thanks!

@byazrail
Copy link
Author

byazrail commented Mar 3, 2020

Thanks, seem to be version 2.7.2, which is not quite the latest, but 2.7.3 has only 1 change that I don't think would be related.
If you could proceed with the memory profiling (again, check the aerospike issue I linked to get details on how to gather it) and update this issue with the output. Thanks!

Profiler; restart after nats-server.
Showing nodes accounting for 123.59MB, 96.86% of 127.60MB total
Dropped 19 nodes (cum <= 0.64MB)
Showing top 10 nodes out of 45
flat flat% sum% cum cum%
103.66MB 81.24% 81.24% 103.66MB 81.24% github.com/aerospike/aerospike-client-go.(*Partitions).clone
5.67MB 4.45% 85.68% 5.67MB 4.45% github.com/aerospike/aerospike-client-go.newPartitions
4MB 3.14% 88.82% 4MB 3.14% github.com/aerospike/aerospike-client-go.newSingleConnectionHeap
2.64MB 2.07% 90.89% 2.64MB 2.07% github.com/nats-io/nats-server/v2/server.(*client).queueOutbound
2.10MB 1.64% 92.53% 2.10MB 1.64% github.com/aerospike/aerospike-client-go.newConnection
2.01MB 1.58% 94.11% 2.01MB 1.58% math/rand.NewSource
1.01MB 0.79% 94.90% 1.01MB 0.79% github.com/nats-io/nats-server/v2/server.(*Server).createClient
1MB 0.78% 95.68% 1MB 0.78% sync.(*Map).Store
1MB 0.78% 96.47% 1MB 0.78% github.com/nats-io/nats-server/v2/server.(*Sublist).Insert
0.50MB 0.39% 96.86% 7.63MB 5.98% github.com/nats-io/nats-server/v2/server.(*client).readLoop

@byazrail
Copy link
Author

byazrail commented Mar 3, 2020

Tree Out;
(pprof) tree
Showing nodes accounting for 125.09MB, 98.04% of 127.60MB total
Dropped 19 nodes (cum <= 0.64MB)
----------------------------------------------------------+-------------
flat flat% sum% cum cum% calls calls% + context
----------------------------------------------------------+-------------
103.66MB 100% | github.com/aerospike/aerospike-client-go.partitionMap.clone
103.66MB 81.24% 81.24% 103.66MB 81.24% | github.com/aerospike/aerospike-client-go.(*Partitions).clone
----------------------------------------------------------+-------------
5.67MB 100% | github.com/aerospike/aerospike-client-go.(*partitionParser).parseReplicasAll
5.67MB 4.45% 85.68% 5.67MB 4.45% | github.com/aerospike/aerospike-client-go.newPartitions
----------------------------------------------------------+-------------
4MB 100% | github.com/aerospike/aerospike-client-go.newConnectionHeap
4MB 3.14% 88.82% 4MB 3.14% | github.com/aerospike/aerospike-client-go.newSingleConnectionHeap
----------------------------------------------------------+-------------
2.11MB 79.88% | github.com/nats-io/nats-server/v2/server.(*client).deliverMsg
2.64MB 2.07% 90.89% 2.64MB 2.07% | github.com/nats-io/nats-server/v2/server.(*client).queueOutbound
----------------------------------------------------------+-------------
2.10MB 100% | github.com/aerospike/aerospike-client-go.NewConnection
2.10MB 1.64% 92.53% 2.10MB 1.64% | github.com/aerospike/aerospike-client-go.newConnection
----------------------------------------------------------+-------------
2.01MB 100% | github.com/nats-io/nats-server/v2/server.(*client).processMsgResults
2.01MB 1.58% 94.11% 2.01MB 1.58% | math/rand.NewSource
----------------------------------------------------------+-------------
1.01MB 100% | github.com/nats-io/nats-server/v2/server.(*Server).AcceptLoop.func2
1.01MB 0.79% 94.90% 1.01MB 0.79% | github.com/nats-io/nats-server/v2/server.(*Server).createClient
----------------------------------------------------------+-------------
1MB 100% | github.com/nats-io/nats-server/v2/server.(*Sublist).Match
1MB 0.78% 95.68% 1MB 0.78% | sync.(*Map).Store
----------------------------------------------------------+-------------
1MB 100% | github.com/nats-io/nats-server/v2/server.(*client).setPermissions
1MB 0.78% 96.47% 1MB 0.78% | github.com/nats-io/nats-server/v2/server.(*Sublist).Insert
----------------------------------------------------------+-------------
7.63MB 100% | github.com/nats-io/nats-server/v2/server.(*Server).createClient.func2
0.50MB 0.39% 96.86% 7.63MB 5.98% | github.com/nats-io/nats-server/v2/server.(*client).readLoop
7.12MB 93.39% | github.com/nats-io/nats-server/v2/server.(*client).parse
----------------------------------------------------------+-------------
1MB 100% | github.com/aerospike/aerospike-client-go.(*Cluster).tend
0.50MB 0.39% 97.25% 1MB 0.78% | github.com/aerospike/aerospike-client-go.(*Cluster).aggregateNodestats
----------------------------------------------------------+-------------
104.16MB 100% | github.com/aerospike/aerospike-client-go.(*Cluster).tend.func3
0.50MB 0.39% 97.65% 104.16MB 81.63% | github.com/aerospike/aerospike-client-go.partitionMap.clone
103.66MB 99.52% | github.com/aerospike/aerospike-client-go.(*Partitions).clone
----------------------------------------------------------+-------------
4.50MB 100% | github.com/aerospike/aerospike-client-go.newNode
0.50MB 0.39% 98.04% 4.50MB 3.53% | github.com/aerospike/aerospike-client-go.newConnectionHeap
4MB 88.89% | github.com/aerospike/aerospike-client-go.newSingleConnectionHeap
----------------------------------------------------------+-------------
3.50MB 77.78% | github.com/aerospike/aerospike-client-go.nodesToAddT.addNodeIfNotExists
1MB 22.22% | github.com/aerospike/aerospike-client-go.(*Cluster).tend.func4
0 0% 98.04% 4.50MB 3.53% | github.com/aerospike/aerospike-client-go.(*Cluster).createNode
4.50MB 100% | github.com/aerospike/aerospike-client-go.newNode
----------------------------------------------------------+-------------
0 0% 98.04% 3.50MB 2.74% | github.com/aerospike/aerospike-client-go.(*Cluster).seedNodes.func2
3.50MB 100% | github.com/aerospike/aerospike-client-go.(*nodeValidator).seedNodes
----------------------------------------------------------+-------------
2MB 100% | github.com/aerospike/aerospike-client-go.(*Cluster).waitTillStabilized.func1
0 0% 98.04% 2MB 1.57% | github.com/aerospike/aerospike-client-go.(*Cluster).tend
1MB 49.90% | github.com/aerospike/aerospike-client-go.(*Cluster).aggregateNodestats
----------------------------------------------------------+-------------
104.16MB 100% | github.com/aerospike/aerospike-client-go.(*Cluster).tend.func4
0 0% 98.04% 104.16MB 81.63% | github.com/aerospike/aerospike-client-go.(*Cluster).tend.func3
104.16MB 100% | github.com/aerospike/aerospike-client-go.partitionMap.clone
----------------------------------------------------------+-------------
0 0% 98.04% 105.69MB 82.83% | github.com/aerospike/aerospike-client-go.(*Cluster).tend.func4
104.16MB 98.55% | github.com/aerospike/aerospike-client-go.(*Cluster).tend.func3
1MB 0.95% | github.com/aerospike/aerospike-client-go.(*Cluster).createNode
0.53MB 0.5% | github.com/aerospike/aerospike-client-go.NewConnection
----------------------------------------------------------+-------------
0 0% 98.04% 5.67MB 4.45% | github.com/aerospike/aerospike-client-go.(*Cluster).tend.func5
5.67MB 100% | github.com/aerospike/aerospike-client-go.(*Node).refreshPartitions
----------------------------------------------------------+-------------
0 0% 98.04% 2MB 1.57% | github.com/aerospike/aerospike-client-go.(*Cluster).waitTillStabilized.func1
2MB 100% | github.com/aerospike/aerospike-client-go.(*Cluster).tend
----------------------------------------------------------+-------------
0 0% 98.04% 1.56MB 1.23% | github.com/aerospike/aerospike-client-go.(*Node).makeConnectionForPool
1.56MB 100% | github.com/aerospike/aerospike-client-go.(*Node).newConnection
----------------------------------------------------------+-------------
1.56MB 100% | github.com/aerospike/aerospike-client-go.(*Node).makeConnectionForPool
0 0% 98.04% 1.56MB 1.23% | github.com/aerospike/aerospike-client-go.(*Node).newConnection
1.56MB 100% | github.com/aerospike/aerospike-client-go.NewConnection
----------------------------------------------------------+-------------
5.67MB 100% | github.com/aerospike/aerospike-client-go.(*Cluster).tend.func5
0 0% 98.04% 5.67MB 4.45% | github.com/aerospike/aerospike-client-go.(*Node).refreshPartitions
5.67MB 100% | github.com/aerospike/aerospike-client-go.newPartitionParser
----------------------------------------------------------+-------------
3.50MB 100% | github.com/aerospike/aerospike-client-go.(*Cluster).seedNodes.func2
0 0% 98.04% 3.50MB 2.74% | github.com/aerospike/aerospike-client-go.(*nodeValidator).seedNodes
3.50MB 100% | github.com/aerospike/aerospike-client-go.nodesToAddT.addNodeIfNotExists
----------------------------------------------------------+-------------
5.67MB 100% | github.com/aerospike/aerospike-client-go.newPartitionParser
0 0% 98.04% 5.67MB 4.45% | github.com/aerospike/aerospike-client-go.(*partitionParser).parseReplicasAll
5.67MB 100% | github.com/aerospike/aerospike-client-go.newPartitions
----------------------------------------------------------+-------------
1.56MB 74.62% | github.com/aerospike/aerospike-client-go.(*Node).newConnection
0.53MB 25.38% | github.com/aerospike/aerospike-client-go.(*Cluster).tend.func4
0 0% 98.04% 2.10MB 1.64% | github.com/aerospike/aerospike-client-go.NewConnection
2.10MB 100% | github.com/aerospike/aerospike-client-go.newConnection
----------------------------------------------------------+-------------
4.50MB 100% | github.com/aerospike/aerospike-client-go.(*Cluster).createNode
0 0% 98.04% 4.50MB 3.53% | github.com/aerospike/aerospike-client-go.newNode
4.50MB 100% | github.com/aerospike/aerospike-client-go.newConnectionHeap
----------------------------------------------------------+-------------
5.67MB 100% | github.com/aerospike/aerospike-client-go.(*Node).refreshPartitions
0 0% 98.04% 5.67MB 4.45% | github.com/aerospike/aerospike-client-go.newPartitionParser
5.67MB 100% | github.com/aerospike/aerospike-client-go.(*partitionParser).parseReplicasAll
----------------------------------------------------------+-------------
3.50MB 100% | github.com/aerospike/aerospike-client-go.(*nodeValidator).seedNodes
0 0% 98.04% 3.50MB 2.74% | github.com/aerospike/aerospike-client-go.nodesToAddT.addNodeIfNotExists
3.50MB 100% | github.com/aerospike/aerospike-client-go.(*Cluster).createNode
----------------------------------------------------------+-------------
0 0% 98.04% 1.01MB 0.79% | github.com/nats-io/nats-server/v2/server.(*Server).AcceptLoop.func2
1.01MB 100% | github.com/nats-io/nats-server/v2/server.(*Server).createClient
----------------------------------------------------------+-------------
2MB 100% | github.com/nats-io/nats-server/v2/server.(*client).processConnect
0 0% 98.04% 2MB 1.57% | github.com/nats-io/nats-server/v2/server.(*Server).checkAuthentication
2MB 100% | github.com/nats-io/nats-server/v2/server.(*Server).isClientAuthorized
----------------------------------------------------------+-------------
0 0% 98.04% 7.63MB 5.98% | github.com/nats-io/nats-server/v2/server.(*Server).createClient.func2
7.63MB 100% | github.com/nats-io/nats-server/v2/server.(*client).readLoop
----------------------------------------------------------+-------------
2MB 100% | github.com/nats-io/nats-server/v2/server.(*Server).checkAuthentication
0 0% 98.04% 2MB 1.57% | github.com/nats-io/nats-server/v2/server.(*Server).isClientAuthorized
2MB 100% | github.com/nats-io/nats-server/v2/server.(*Server).processClientOrLeafAuthentication
----------------------------------------------------------+-------------
2MB 100% | github.com/nats-io/nats-server/v2/server.(*Server).isClientAuthorized
0 0% 98.04% 2MB 1.57% | github.com/nats-io/nats-server/v2/server.(*Server).processClientOrLeafAuthentication
1MB 50.00% | github.com/nats-io/nats-server/v2/server.comparePasswords
1MB 50.00% | github.com/nats-io/nats-server/v2/server.(*client).RegisterUser
----------------------------------------------------------+-------------
0.50MB 50.00% | github.com/nats-io/nats-server/v2/server.(*client).parse
0.50MB 50.00% | github.com/nats-io/nats-server/v2/server.(*client).processInboundClientMsg
0 0% 98.04% 1MB 0.78% | github.com/nats-io/nats-server/v2/server.(*Sublist).Match
1MB 100% | sync.(*Map).Store
----------------------------------------------------------+-------------
1MB 100% | github.com/nats-io/nats-server/v2/server.(*Server).processClientOrLeafAuthentication
0 0% 98.04% 1MB 0.78% | github.com/nats-io/nats-server/v2/server.(*client).RegisterUser
1MB 100% | github.com/nats-io/nats-server/v2/server.(*client).setPermissions
----------------------------------------------------------+-------------
2.11MB 100% | github.com/nats-io/nats-server/v2/server.(*client).processMsgResults
0 0% 98.04% 2.11MB 1.65% | github.com/nats-io/nats-server/v2/server.(*client).deliverMsg
2.11MB 100% | github.com/nats-io/nats-server/v2/server.(*client).queueOutbound
----------------------------------------------------------+-------------
7.12MB 100% | github.com/nats-io/nats-server/v2/server.(*client).readLoop
0 0% 98.04% 7.12MB 5.58% | github.com/nats-io/nats-server/v2/server.(*client).parse
4.62MB 64.89% | github.com/nats-io/nats-server/v2/server.(*client).processInboundMsg
2MB 28.09% | github.com/nats-io/nats-server/v2/server.(*client).processConnect
0.50MB 7.02% | github.com/nats-io/nats-server/v2/server.(*Sublist).Match
----------------------------------------------------------+-------------
2MB 100% | github.com/nats-io/nats-server/v2/server.(*client).parse
0 0% 98.04% 2MB 1.57% | github.com/nats-io/nats-server/v2/server.(*client).processConnect
2MB 100% | github.com/nats-io/nats-server/v2/server.(*Server).checkAuthentication
----------------------------------------------------------+-------------
4.62MB 100% | github.com/nats-io/nats-server/v2/server.(*client).processInboundMsg
0 0% 98.04% 4.62MB 3.62% | github.com/nats-io/nats-server/v2/server.(*client).processInboundClientMsg
4.12MB 89.18% | github.com/nats-io/nats-server/v2/server.(*client).processMsgResults
0.50MB 10.82% | github.com/nats-io/nats-server/v2/server.(*Sublist).Match
----------------------------------------------------------+-------------
4.62MB 100% | github.com/nats-io/nats-server/v2/server.(*client).parse
0 0% 98.04% 4.62MB 3.62% | github.com/nats-io/nats-server/v2/server.(*client).processInboundMsg
4.62MB 100% | github.com/nats-io/nats-server/v2/server.(*client).processInboundClientMsg
----------------------------------------------------------+-------------
4.12MB 100% | github.com/nats-io/nats-server/v2/server.(*client).processInboundClientMsg
0 0% 98.04% 4.12MB 3.23% | github.com/nats-io/nats-server/v2/server.(*client).processMsgResults
2.11MB 51.23% | github.com/nats-io/nats-server/v2/server.(*client).deliverMsg
2.01MB 48.77% | math/rand.NewSource
----------------------------------------------------------+-------------
1MB 100% | github.com/nats-io/nats-server/v2/server.(*client).RegisterUser
0 0% 98.04% 1MB 0.78% | github.com/nats-io/nats-server/v2/server.(*client).setPermissions
1MB 100% | github.com/nats-io/nats-server/v2/server.(*Sublist).Insert
----------------------------------------------------------+-------------
1MB 100% | github.com/nats-io/nats-server/v2/server.comparePasswords
0 0% 98.04% 1MB 0.78% | github.com/nats-io/nats-server/v2/server.aerospikeGet
----------------------------------------------------------+-------------
1MB 100% | github.com/nats-io/nats-server/v2/server.(*Server).processClientOrLeafAuthentication
0 0% 98.04% 1MB 0.78% | github.com/nats-io/nats-server/v2/server.comparePasswords
1MB 100% | github.com/nats-io/nats-server/v2/server.aerospikeGet
----------------------------------------------------------+-------------

@byazrail
Copy link
Author

byazrail commented Mar 3, 2020

18mins after top command;
[root@nats ~]# go tool pprof "http://localhost:6060/debug/pprof/heap"
Fetching profile over HTTP from http://localhost:6060/debug/pprof/heap
Saved profile in /root/pprof/pprof.nats-server.alloc_objects.alloc_space.inuse_objects.inuse_space.003.pb.gz
File: nats-server
Type: inuse_space
Time: Mar 3, 2020 at 7:57pm (+03)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
Showing nodes accounting for 629.28MB, 96.76% of 650.34MB total
Dropped 30 nodes (cum <= 3.25MB)
Showing top 10 nodes out of 53
flat flat% sum% cum cum%
522.46MB 80.34% 80.34% 522.46MB 80.34% github.com/aerospike/aerospike-client-go.(*Partitions).clone
36.62MB 5.63% 85.97% 36.62MB 5.63% github.com/aerospike/aerospike-client-go.newPartitions
25.51MB 3.92% 89.89% 25.51MB 3.92% github.com/aerospike/aerospike-client-go.newSingleConnectionHeap
21.15MB 3.25% 93.14% 21.15MB 3.25% github.com/nats-io/nats-server/v2/server.(*client).queueOutbound
5.50MB 0.85% 93.99% 5.50MB 0.85% github.com/aerospike/aerospike-client-go.(*Cluster).addNodes.func1
4.53MB 0.7% 94.69% 4.53MB 0.7% github.com/nats-io/nats-server/v2/server.(*Server).createClient
4.50MB 0.69% 95.38% 4.50MB 0.69% github.com/nats-io/nats-server/v2/server.(*Server).saveClosedClient
4MB 0.62% 95.99% 6MB 0.92% github.com/aerospike/aerospike-client-go.NewCluster
2.50MB 0.38% 96.38% 29.51MB 4.54% github.com/aerospike/aerospike-client-go.newNode
2.50MB 0.38% 96.76% 524.96MB 80.72% github.com/aerospike/aerospike-client-go.partitionMap.clone

@ripienaar
Copy link
Contributor

so seems clear there's a leak in the client library for aerospike or something needs a clean up.

I'd suggest perhaps reusing the aerospike client between calls? and asking that project about the leak or best use pattern

@kozlovic
Copy link
Member

kozlovic commented Mar 3, 2020

At this point, you need to get this report to aerospike repo. They will know better what is causing the clone of these partitions and help you finding out if you are using their API properly and releasing all resources (I see that you call defer client.Close() - which by the way should be done after checking for error, not before), etc..

@byazrail
Copy link
Author

byazrail commented Mar 3, 2020

(I see that you call defer client.Close() - which by the way should be done after checking for error, not before), etc..

defer client.Close() how this usage should be?

@byazrail
Copy link
Author

byazrail commented Mar 3, 2020

`func aerospikeGet(key string) bool {
hosts := []*aero.Host {
aero.NewHost("10.135.65.66", 3000),
aero.NewHost("10.135.200.130", 3000),
}
client, err := aero.NewClientWithPolicyAndHost(nil, hosts...)

if err != nil {
	defer client.Close()
	return false
}

getKey, err := aero.NewKey("leonsbet", "cache", "socket:token:" + key)
// fmt.Println(getKey)
// fmt.Println(err)

if (err != nil) {
	defer client.Close()
	return false
}

policy := aero.NewPolicy()
exists, err := client.Exists(policy, getKey)

// fmt.Println(exists)
// fmt.Println(err)

if (err != nil) {
	defer client.Close()
	return false
} else if exists != false {
	defer client.Close()
	return true
} else {
	return false
}

}`

same?

@kozlovic
Copy link
Member

kozlovic commented Mar 3, 2020

You have this right now:

client, err := aero.NewClientWithPolicyAndHost(nil, hosts...)
defer client.Close()
if err != nil {
	return false
}

Well, if aero.NewClientWithPolicyAndHost() returns an error, client will be nil, and you will get a SEGFAULT when trying to close the client, since client is nil. So you should have:

client, err := aero.NewClientWithPolicyAndHost(nil, hosts...)
if err != nil {
	return false
}
defer client.Close()

But I am not saying that this is why you have the memory growth, just stating that the defer was not placed correctly.

@kozlovic
Copy link
Member

kozlovic commented Mar 3, 2020

Just one defer after creating the client, but after checking for the error from aero.NewClientWithPolicyAndHost().

@byazrail
Copy link
Author

byazrail commented Mar 3, 2020

defer client.Close()

Okey, trying after profiler watching...

@byazrail
Copy link
Author

byazrail commented Mar 3, 2020

You have this right now:

client, err := aero.NewClientWithPolicyAndHost(nil, hosts...)
defer client.Close()
if err != nil {
	return false
}

Well, if aero.NewClientWithPolicyAndHost() returns an error, client will be nil, and you will get a SEGFAULT when trying to close the client, since client is nil. So you should have:

client, err := aero.NewClientWithPolicyAndHost(nil, hosts...)
if err != nil {
	return false
}
defer client.Close()

But I am not saying that this is why you have the memory growth, just stating that the defer was not placed correctly.

I use just now profiler watching.

@byazrail
Copy link
Author

byazrail commented Mar 3, 2020

Tested after result; - The problem appears in the Aerospike client, then.
(pprof) top 100
Showing nodes accounting for 437.83MB, 97.65% of 448.39MB total
Dropped 44 nodes (cum <= 2.24MB)
flat flat% sum% cum cum%
339.37MB 75.69% 75.69% 339.37MB 75.69% github.com/aerospike/aerospike-client-go.(*Partitions).clone
22.69MB 5.06% 80.75% 22.69MB 5.06% github.com/nats-io/nats-server/v2/server.(*client).queueOutbound
22.51MB 5.02% 85.77% 22.51MB 5.02% github.com/aerospike/aerospike-client-go.newSingleConnectionHeap
21.66MB 4.83% 90.60% 21.66MB 4.83% github.com/aerospike/aerospike-client-go.newPartitions
6.54MB 1.46% 92.06% 6.54MB 1.46% github.com/nats-io/nats-server/v2/server.(*Server).createClient
4.50MB 1.00% 93.06% 5MB 1.12% github.com/nats-io/nats-server/v2/server.(*Server).saveClosedClient
4.50MB 1.00% 94.07% 28.51MB 6.36% github.com/aerospike/aerospike-client-go.newNode
3MB 0.67% 94.74% 3MB 0.67% github.com/aerospike/aerospike-client-go.(*info).parseMultiResponse
3MB 0.67% 95.41% 3MB 0.67% github.com/aerospike/aerospike-client-go.(*Cluster).addNodes.func1
2.51MB 0.56% 95.97% 2.51MB 0.56% math/rand.NewSource
2.50MB 0.56% 96.52% 2.50MB 0.56% net.newFD
2MB 0.45% 96.97% 3.50MB 0.78% github.com/aerospike/aerospike-client-go.NewCluster
1.50MB 0.33% 97.30% 24.01MB 5.36% github.com/aerospike/aerospike-client-go.newConnectionHeap
1.03MB 0.23% 97.53% 3.53MB 0.79% github.com/aerospike/aerospike-client-go.newConnection
0.50MB 0.11% 97.65% 339.87MB 75.80% github.com/aerospike/aerospike-client-go.partitionMap.clone
0 0% 97.65% 3MB 0.67% github.com/aerospike/aerospike-client-go.(*Cluster).addNodes
0 0% 97.65% 28.51MB 6.36% github.com/aerospike/aerospike-client-go.(*Cluster).createNode
0 0% 97.65% 18.51MB 4.13% github.com/aerospike/aerospike-client-go.(*Cluster).seedNodes.func2
0 0% 97.65% 5MB 1.12% github.com/aerospike/aerospike-client-go.(*Cluster).tend
0 0% 97.65% 339.87MB 75.80% github.com/aerospike/aerospike-client-go.(*Cluster).tend.func3
0 0% 97.65% 353.88MB 78.92% github.com/aerospike/aerospike-client-go.(*Cluster).tend.func4
0 0% 97.65% 21.66MB 4.83% github.com/aerospike/aerospike-client-go.(*Cluster).tend.func5
0 0% 97.65% 5MB 1.12% github.com/aerospike/aerospike-client-go.(*Cluster).waitTillStabilized.func1
0 0% 97.65% 3.03MB 0.68% github.com/aerospike/aerospike-client-go.(*Node).makeConnectionForPool
0 0% 97.65% 3.03MB 0.68% github.com/aerospike/aerospike-client-go.(*Node).newConnection
0 0% 97.65% 21.66MB 4.83% github.com/aerospike/aerospike-client-go.(*Node).refreshPartitions
0 0% 97.65% 18.51MB 4.13% github.com/aerospike/aerospike-client-go.(*nodeValidator).seedNodes
0 0% 97.65% 3.50MB 0.78% github.com/aerospike/aerospike-client-go.(*nodeValidator).validateAlias
0 0% 97.65% 21.66MB 4.83% github.com/aerospike/aerospike-client-go.(*partitionParser).parseReplicasAll
0 0% 97.65% 3.50MB 0.78% github.com/aerospike/aerospike-client-go.NewClientWithPolicyAndHost
0 0% 97.65% 3.53MB 0.79% github.com/aerospike/aerospike-client-go.NewConnection
0 0% 97.65% 3MB 0.67% github.com/aerospike/aerospike-client-go.RequestInfo
0 0% 97.65% 21.66MB 4.83% github.com/aerospike/aerospike-client-go.newPartitionParser
0 0% 97.65% 16.01MB 3.57% github.com/aerospike/aerospike-client-go.nodesToAddT.addNodeIfNotExists
0 0% 97.65% 3MB 0.67% github.com/aerospike/aerospike-client-go/internal/atomic.(*SyncVal).Update
0 0% 97.65% 6.54MB 1.46% github.com/nats-io/nats-server/v2/server.(*Server).AcceptLoop.func2
0 0% 97.65% 6MB 1.34% github.com/nats-io/nats-server/v2/server.(*Server).checkAuthentication
0 0% 97.65% 32.76MB 7.31% github.com/nats-io/nats-server/v2/server.(*Server).createClient.func2
0 0% 97.65% 6MB 1.34% github.com/nats-io/nats-server/v2/server.(*Server).isClientAuthorized
0 0% 97.65% 6MB 1.34% github.com/nats-io/nats-server/v2/server.(*Server).processClientOrLeafAuthentication
0 0% 97.65% 22.69MB 5.06% github.com/nats-io/nats-server/v2/server.(*client).deliverMsg
0 0% 97.65% 32.76MB 7.31% github.com/nats-io/nats-server/v2/server.(*client).parse
0 0% 97.65% 6MB 1.34% github.com/nats-io/nats-server/v2/server.(*client).processConnect
0 0% 97.65% 26.26MB 5.86% github.com/nats-io/nats-server/v2/server.(*client).processInboundClientMsg
0 0% 97.65% 26.26MB 5.86% github.com/nats-io/nats-server/v2/server.(*client).processInboundMsg
0 0% 97.65% 25.21MB 5.62% github.com/nats-io/nats-server/v2/server.(*client).processMsgResults
0 0% 97.65% 32.76MB 7.31% github.com/nats-io/nats-server/v2/server.(*client).readLoop
0 0% 97.65% 4MB 0.89% github.com/nats-io/nats-server/v2/server.aerospikeGet
0 0% 97.65% 4MB 0.89% github.com/nats-io/nats-server/v2/server.comparePasswords
0 0% 97.65% 2.50MB 0.56% net.(*Dialer).Dial
0 0% 97.65% 2.50MB 0.56% net.(*Dialer).DialContext
0 0% 97.65% 2.50MB 0.56% net.(*sysDialer).dialSerial
0 0% 97.65% 2.50MB 0.56% net.(*sysDialer).dialSingle
0 0% 97.65% 2.50MB 0.56% net.(*sysDialer).dialTCP
0 0% 97.65% 2.50MB 0.56% net.(*sysDialer).doDialTCP
0 0% 97.65% 2.50MB 0.56% net.DialTimeout
0 0% 97.65% 2.50MB 0.56% net.internetSocket
0 0% 97.65% 2.50MB 0.56% net.socket

@kozlovic
Copy link
Member

kozlovic commented Mar 3, 2020

Yes. I am sure they will be able to point out why these partitions are cloned and why the resources are not released. Closing for now, but appreciate if you can update with the resolution. Thanks!

@kozlovic kozlovic closed this as completed Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants