Comments (6)
Please provide some example code.
from gnet.
🤖 Non-English text detected, translating...
There is another question, should NumEventLoop be the same as the value set by runtime.GOMAXPROCS to achieve optimal performance? We set runtime.GOMAXPROCS to 8, use memtier_benchmark stress test get, value128B,
Start NumEventLoop setting 64, p99.9Latency reaches 130ms, adjust NumEventLoop to 8, p99.9Latency drops to 3.5ms
from gnet.
线上打日志发现了,一次请求mget命令返回值可能在100KB大小,调用gnet.Conn Write方法需要几百毫秒的耗时,这个同步写怎么这么耗时呢,我看注释AsyncWrite方法不能在OnTraffic的EventHandler里调用,那这个问题有什么好的方法解决吗
func (s *Server) OnTraffic(conn gnet.Conn) (action gnet.Action) {
connBuf, _ := conn.Next(-1)
cmds, err := ReadCommands(connBuf)
if err != nil {
return gnet.Close
}
for _, cmd := range cmds {
respData := HandleRequest(cmd.Args)
conn.Write(respData) // 这里耗时会达到几百毫秒
}
return gnet.None
}
from gnet.
🤖 Non-English text detected, translating...
I found out through online logging that the return value of a request for the mget command may be 100KB, and it takes hundreds of milliseconds to call the gnet.Conn Write method. Why is this synchronous writing so time-consuming? I saw the comment that the AsyncWrite method cannot be used in OnTraffic. Called in EventHandler, is there any good way to solve this problem?
from gnet.
首先,AsyncWrite()
可以在 OnTraffic()
里调用,只不过这个方法通常是给 event loop 之外的 goroutine 使用的;其次,gnet.Conn.Write()
只是直接调用系统调用 write(2)
,而且 socket 都是非阻塞的,如果当前还有未发送完的数据则直接写入本地 buffer 然后返回,连系统调用都没有,所以写 100KB 的数据的延迟是几百毫秒肯定是有问题的,我建议你排查一下你的系统网络,或者就是你的代码有问题,是不是别的地方大量占用 CPU 导致 event loop 没有机会运行,跑一下性能测试看看 CPU 的分布状况;最后,如果是需要一次性写出多个 buffers,可以考虑使用 gnet.Conn.Writev()
减少系统调用,具体可看文档。
from gnet.
🤖 Non-English text detected, translating...
First of all, AsyncWrite()
can be called in OnTraffic()
, but this method is usually used by goroutines outside the event loop; secondly, gnet.Conn.Write()
just directly calls the system call write(2)
, and sockets are non-blocking. If there is currently unsent data, it will be written directly to the local buffer and then returned. There is not even a system call, so the delay of writing 100KB data is definitely a few hundred milliseconds. If there is a problem, I suggest you check your system network, or there is a problem with your code. Is it that other places are occupying a lot of CPU, causing the event loop to have no chance to run? Run a performance test to see the distribution of the CPU; finally, If you need to write multiple buffers at once, you can consider using gnet.Conn.Writev()
to reduce system calls. Please see the documentation for details.
from gnet.
Related Issues (20)
- [Question]: Is the netpoll v1 version defaulting to horizontal triggering, and the V2 version defaulting to edge triggering? HOT 15
- [Bug]: fatal error: concurrent map read and map write HOT 1
- Inconsistent behaviors with SO_REUSEPORT on Linux and *BSD HOT 7
- Don't use SO_REUSEPORT on Unix domain sockets HOT 1
- Don't disable SO_REUSEPORT on DragonFlyBSD HOT 1
- [Question]: gnet client works not as expected even tho i did it according to the api ref HOT 1
- [Bug]: GNET client not working as expected HOT 4
- [Bug]: example gnet for echo tcp uses too much memory HOT 7
- [Bug]: Read returns io.ErrShortBuffer on closed connection HOT 7
- Special treatment for the first package HOT 8
- [Question]: How to shut down the started tcp server and turn off port listening? HOT 2
- [Question]: When using io.CopyBuffer(), do you need to call Flush to send the data? HOT 2
- [Bug]: Discard() panic HOT 17
- [Feature]: `io_uring` support HOT 6
- [Question]: there's gnet https server now, how to use gnet https client? HOT 1
- UDP FD handle is not released HOT 1
- [Question]: redhub upgraded to use gnet/v2 issues, seemed "stalled" HOT 1
- [Feature]: tls support HOT 5
- [Bug]: gnet.Conn.Peek crashes slice bounds out of range HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gnet.