Skip to content

Conversation

JHue58
Copy link

@JHue58 JHue58 commented Feb 19, 2024

When used with sharequeue, the nodes of LinkBuffer are set to nil after Append, which prevents reuse and causes GC pressure.

@JHue58 JHue58 requested review from a team as code owners February 19, 2024 13:04
@CLAassistant
Copy link

CLAassistant commented Feb 19, 2024

CLA assistant check
All committers have signed the CLA.

@joway
Copy link
Member

joway commented Feb 20, 2024

the nodes of LinkBuffer are set to nil after Append, which prevents reuse and causes GC pressure.

@Nana-Miko Hi, can you show me your code and how it cause GC pressure?

@JHue58
Copy link
Author

JHue58 commented Feb 20, 2024

the nodes of LinkBuffer are set to nil after Append, which prevents reuse and causes GC pressure.

@Nana-Miko Hi, can you show me your code and how it cause GC pressure?

sure!

queue := mux.NewShardQueue(mux.ShardSize, conn)

	// Simulating pressure environment using for loops
	for {
		var getter mux.WriterGetter = func() (buf Writer, isNil bool) {
			// I can't use sync.Pool to get buf
			// In this func,'var buf = &LinkBuffer{}' will continuously allocate memory
			buf = NewLinkBuffer(128)

			buf.Malloc(128)
			buf.Flush()
			return buf, false
		}
		queue.Add(getter)
	}

In this example, is there any way to reuse LinkBuffer using sync.Pool?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants