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

求助!内存使用问题 #314

Closed
JHue58 opened this issue Feb 29, 2024 · 8 comments
Closed

求助!内存使用问题 #314

JHue58 opened this issue Feb 29, 2024 · 8 comments

Comments

@JHue58
Copy link

JHue58 commented Feb 29, 2024

在服务端消费过慢时,会导致服务端内存堆积导致服务炸掉。
目前netpoll有提供什么可行的限流方案嘛,求解答!谢谢

@joway
Copy link
Member

joway commented Mar 1, 2024

@Nana-Miko #298

已经实现了read限流,正在测试这个pr,你也可以直接用这个分支试试?

@JHue58
Copy link
Author

JHue58 commented Mar 1, 2024

@Nana-Miko #298

已经实现了read限流,正在测试这个pr,你也可以直接用这个分支试试?

好的谢谢

@JHue58 JHue58 closed this as completed Mar 1, 2024
@JHue58
Copy link
Author

JHue58 commented Mar 4, 2024

刚刚看了一下read-throttle这个分支,如果通过inputBuffer.Len()进行限流的话,感觉不是很妥当
比如onRequest那边需要进行数据分包,就像官网的例子

var conn netpoll.Connection
	// reading
	reader := conn.Reader()
	for {
		... unpacking & handling ...
		pkg, _ := reader.Slice(pkgsize)
		go func() {
			... handling pkg ...
                        <-time.After(50*time.Microsecond)
			pkg.Release()
		}
	}

由于Slice会进行recalLen,但实际上pkg并没有被消费完毕,就会导致限流无效

@JHue58 JHue58 reopened this Mar 4, 2024
@ppzqh
Copy link
Contributor

ppzqh commented Mar 5, 2024

对于netpoll而言,我理解slice操作属于是消费了buffer,返回了一个新的link buffer供用户来按需读取。

@ppzqh
Copy link
Contributor

ppzqh commented Mar 5, 2024

关于限流,是否有别的建议来解决这个问题?

@JHue58
Copy link
Author

JHue58 commented Mar 5, 2024

关于限流,是否有别的建议来解决这个问题?

我后来想了一下,像上面的代码那样来一个pkg就开一个协程去处理是错误的,换成channel+一个process协程就行

@joway
Copy link
Member

joway commented Mar 6, 2024

@Nana-Miko yes,无论什么实现方式,都需要你自己也主动控制下消费buffer的速度,进而才能控制对端速度。实现方式只是在「控制方法」这有差异,目前的实现方式是通过buffer本身的读取消费来控制

@JHue58
Copy link
Author

JHue58 commented Mar 6, 2024

@Nana-Miko yes,无论什么实现方式,都需要你自己也主动控制下消费buffer的速度,进而才能控制对端速度。实现方式只是在「控制方法」这有差异,目前的实现方式是通过buffer本身的读取消费来控制

嗯,确实是这样的,受教了!

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

No branches or pull requests

3 participants