UDP性能 [英] UDP performance

查看:111
本文介绍了UDP性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下问题感到困惑。我有一个大的多线程

服务器接受一个UDP端口上的通信(根据它所假设的

速度选择)。


我一直在分析代码,发现UDP通信是我最大的性能消耗!在运行Linux的Athlon64 3000+(Fedora Core 5 x64)上,客户端和

服务器在同一台计算机上的通信仍然需要300毫秒或有时更多

每个数据包。


我一定做错了什么,非常感谢我的反馈

我的代码如下:


我打开服务器端口


self.s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

self.s.setsockopt(socket.SOL_SOCKET ,socket.SO_REUSEADDR,1)

self.s.bind((myaddress,myport))


然后我用
打开一个客户端端口

self.s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

self.s.connect((host,port))


客户端发送数据


self.s.sendall(数据)


和服务器


self.s.sendto(data,link.remoteaddress)


均收到


buf, address = socket.recvfrom(8192)


发送方和接收方都在不同的线程中(threading.Thread)。


有谁知道这里出了什么问题,套接字通信,

线程安排?


Paul Sijben

I am stumped by the following problem. I have a large multi-threaded
server accepting communications on one UDP port (chosen for its supposed
speed).

I have been profiling the code and found that the UDP communication is
my biggest drain on performance! Communication where the client and the
server are on the same machine still takes 300ms or sometimes much more
per packet on an Athlon64 3000+ running Linux (Fedora Core 5 x64).

I must be doing something wrong and would really appreciate feedback on
my code below:

I open the server port with

self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.s.bind((myaddress, myport))

I then open a client port with

self.s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.s.connect((host, port))

the client sends data with

self.s.sendall(data)

and the server with

self.s.sendto(data,link.remoteaddress)

both receive with

buf, address = socket.recvfrom(8192)

The sender and receiver are in separate threads (threading.Thread).

Does anyone know what is going wrong here, the socket communication, the
thread scheduling?

Paul Sijben

推荐答案



Paul Sijben写道:

Paul Sijben wrote:
我对以下问题感到困惑。我有一个大的多线程服务器接受一个UDP端口上的通信(选择其所谓的速度)。

我一直在分析代码并发现UDP通信是我性能最大的消耗!在运行Linux的Athlon64 3000+(Fedora Core 5 x64)上,客户端和服务器位于同一台计算机上的通信仍需要300毫秒或有时甚至更多。


[snip]

buf,address = socket.recvfrom(8192)
I am stumped by the following problem. I have a large multi-threaded
server accepting communications on one UDP port (chosen for its supposed
speed).

I have been profiling the code and found that the UDP communication is
my biggest drain on performance! Communication where the client and the
server are on the same machine still takes 300ms or sometimes much more
per packet on an Athlon64 3000+ running Linux (Fedora Core 5 x64).
[snip]
buf, address = socket.recvfrom(8192)




I 我不是这里的专家,但我应该保持AFAIK UDP数据包大小

低于512字节,否则会造成碎片,因此所有的b / b $ b慢速的东西,比如acknoledgements,超时等...



I''m not an expert here, but I AFAIK UDP packet size should be kept
below 512 bytes otherwise it can cause fragmentation and hence all the
slow stuff like acknoledgements, timeouts, etc...


Serge Orlov写道:
Serge Orlov wrote:
Paul Sijben写道:
Paul Sijben wrote:
I我被以下问题难住了。我有一个大的多线程服务器接受一个UDP端口上的通信(选择其所谓的速度)。

我一直在分析代码并发现UDP通信是我性能最大的消耗!在运行Linux的Athlon64 3000+(Fedora Core 5 x64)上,客户端和服务器位于同一台计算机上的通信仍然需要300毫秒或更多的时间。
I am stumped by the following problem. I have a large multi-threaded
server accepting communications on one UDP port (chosen for its supposed
speed).

I have been profiling the code and found that the UDP communication is
my biggest drain on performance! Communication where the client and the
server are on the same machine still takes 300ms or sometimes much more
per packet on an Athlon64 3000+ running Linux (Fedora Core 5 x64).


[snip]



[snip]

buf,address = socket.recvfrom(8192)
buf, address = socket.recvfrom(8192)



我不是这里的专家,但我的AFAIK UDP数据包大小应该保持在512字节以下,否则会导致碎片,因此所有的速度都很慢,比如acknoledgements,timeout等等......



I''m not an expert here, but I AFAIK UDP packet size should be kept
below 512 bytes otherwise it can cause fragmentation and hence all the
slow stuff like acknoledgements, timeouts, etc...



一般来说是好点,但在实践中它们就是这种情况。但是这对于loopback接口上的问题来说还不是什么问题。


good point in general but in practice they are in this case. but this is
less of a problem on the loopback interface anyway.




Paul Sijben写道:

Paul Sijben wrote:
Serge Orlov写道:
Serge Orlov wrote:
Paul Sijben写道:
Paul Sijben wrote:
我对以下问题感到困惑。我有一个大的多线程服务器接受一个UDP端口上的通信(选择其所谓的速度)。

我一直在分析代码并发现UDP通信是我性能最大的消耗!在运行Linux的Athlon64 3000+(Fedora Core 5 x64)上,客户端和服务器位于同一台计算机上的通信仍然需要300毫秒或更多的时间。
I am stumped by the following problem. I have a large multi-threaded
server accepting communications on one UDP port (chosen for its supposed
speed).

I have been profiling the code and found that the UDP communication is
my biggest drain on performance! Communication where the client and the
server are on the same machine still takes 300ms or sometimes much more
per packet on an Athlon64 3000+ running Linux (Fedora Core 5 x64).


[snip]



[snip]

buf,address = socket.recvfrom(8192)
buf, address = socket.recvfrom(8192)



我不是这里的专家,但我的AFAIK UDP数据包大小应该保持在512字节以下,否则会导致碎片,因此所有的缓慢的东西,比如acknoledgements,timeout等...



I''m not an expert here, but I AFAIK UDP packet size should be kept
below 512 bytes otherwise it can cause fragmentation and hence all the
slow stuff like acknoledgements, timeouts, etc...


好一般而言,但实际上他们就是这种情况。但这对于loopback接口来说还不是什么问题。


good point in general but in practice they are in this case. but this is
less of a problem on the loopback interface anyway.




即使在环回上,MTU是否仍然可以控制它?你的MTU

在环回上是什么?



Isn''t it still controlled by MTU even on the loopback? What is your MTU
on the loopback?


这篇关于UDP性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆