# Multiple client objects cause memory usage to keep growing

**URL:** <https://discuss.aerospike.com/t/multiple-client-objects-cause-memory-usage-to-keep-growing/7136>\
**Category:** Go Client\
**Created:** [February 14, 2020, 7:41pm UTC](https://discuss.aerospike.com/t/multiple-client-objects-cause-memory-usage-to-keep-growing/7136 "2020-02-14T19:41:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandeep\_Yarabarla](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/sandeep_yarabarla/32/1361_2.png) [@Sandeep\_Yarabarla](https://discuss.aerospike.com/u/Sandeep_Yarabarla)\
**Post date:** [February 14, 2020, 7:41pm UTC](https://discuss.aerospike.com/t/multiple-client-objects-cause-memory-usage-to-keep-growing/7136/1 "2020-02-14T19:41:31Z")

</div>

I have a simple healthcheck program that runs every 15s on aerospike instances. We primarily use this for service discovery and other internal stuff. The code is straightforward and looks like this:

func aspkHealth() error {

```
policy := aerospike.NewClientPolicy()

client, err := aerospike.NewClientWithPolicy(policy, "127.0.0.1", 3000)
defer func(client *aerospike.Client) {
	if client != nil {
		client.Close()
	}
}(client)

if err != nil {
	log.Error("error: %v", err)
	return err
}

return nil

```

}

Even though we close the client, the memory usage keeps growing. This is part of a long running process by the way. After doing a bit of memory profiling, I found this:

 ![Screen Shot 2020-02-14 at 11.26.58 AM](https://us1.discourse-cdn.com/flex019/uploads/aerospike/original/2X/1/13bf7bedebaa78ca9e685ea582dff412999ac25b.png)

I know it is recommended to create a single client and reuse it. I just want to know why this particular design pattern causes the memory usage to grow?

---

<div class="post-metadata">

**Author:** ![Khosrow\_Afroozeh](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Khosrow\_Afroozeh](https://discuss.aerospike.com/u/Khosrow_Afroozeh)\
**Post date:** [February 14, 2020, 9:57pm UTC](https://discuss.aerospike.com/t/multiple-client-objects-cause-memory-usage-to-keep-growing/7136/2 "2020-02-14T21:57:22Z")

</div>

The memory growing is a concern. I have to check why it is happening. Did you check via ps/top/htop how much resident memory is being used? Virtual Memory is not really allocated, so if all this is virtual, I wouldn’t be too worried.

Clients manage lots of connections and buffers in the back. Limiting the `ClientPolicy.ConnectionQueueSize` to 1 (or 2 if you use data API) will considerably help with the memory usage.

I’m very curious about the Resident memory consumption of the process. I’d appreciate if you could report back your observations.

---

<div class="post-metadata">

**Author:** ![Sandeep\_Yarabarla](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/sandeep_yarabarla/32/1361_2.png) [@Sandeep\_Yarabarla](https://discuss.aerospike.com/u/Sandeep_Yarabarla)\
**Post date:** [February 14, 2020, 11:28pm UTC](https://discuss.aerospike.com/t/multiple-client-objects-cause-memory-usage-to-keep-growing/7136/3 "2020-02-14T23:28:22Z")

</div>

Sure, the resident memory consumption keeps growing as well. The process with PID 21694 is the one that has the above health check function running on it.

![Screen Shot 2020-02-14 at 3.25.42 PM](https://us1.discourse-cdn.com/flex019/uploads/aerospike/original/2X/a/a7df625718651b39d0b0acd3261a4f46f1c293a4.png)

Also, the aerospike go client version used is v2.7.2 and aerospike server version is E-4.5.3.3

---

<div class="post-metadata">

**Author:** ![Khosrow\_Afroozeh](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Khosrow\_Afroozeh](https://discuss.aerospike.com/u/Khosrow_Afroozeh)\
**Post date:** [February 23, 2020, 3:24pm UTC](https://discuss.aerospike.com/t/multiple-client-objects-cause-memory-usage-to-keep-growing/7136/4 "2020-02-23T15:24:20Z")

</div>

Did setting the `ClientPolicy.ConnectionQueueSize` to 1 help?

---

<div class="post-metadata">

**Author:** ![Sandeep\_Yarabarla](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/sandeep_yarabarla/32/1361_2.png) [@Sandeep\_Yarabarla](https://discuss.aerospike.com/u/Sandeep_Yarabarla)\
**Post date:** [March 3, 2020, 12:52am UTC](https://discuss.aerospike.com/t/multiple-client-objects-cause-memory-usage-to-keep-growing/7136/5 "2020-03-03T00:52:23Z")

</div>

No setting ConnectionQueueSize to 1 did not help. I changed my code to avoid creating and closing multiple client instances for now.

---

<div class="post-metadata">

**Author:** ![Khosrow\_Afroozeh](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Khosrow\_Afroozeh](https://discuss.aerospike.com/u/Khosrow_Afroozeh)\
**Post date:** [March 4, 2020, 11:31am UTC](https://discuss.aerospike.com/t/multiple-client-objects-cause-memory-usage-to-keep-growing/7136/6 "2020-03-04T11:31:26Z")

</div>

Thank you for your persistence. I think the latest release should resolve the issue (v2.8.1).

Changing your code to avoid using multiple instances is the superior solution though.
