ubuntu 14.04 socket.recv 性能下降 23%
23% performance degradation on ubuntu 14.04 with socket.recv
我正在 运行ning python 2.7.8 并观察到 ubuntu 14.04 与 10.04 相比,使用简单的 socket.recv API 性能下降了 23% .我可以分享我的代码、准确的性能数据等,供任何人查看。
这是我的服务器:
#!/usr/bin/python # This is server.py file
import socket # Import socket module
import sys
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port
f = open ("file", "r")
fdata = f.read(100000000)
s.listen(5) # Now wait for client connection.
while True:
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
if sys.argv[1] == '1':
c.send('Thank you for connecting')
elif sys.argv[1] == '2':
c.send(fdata)
c.close()
这是我的客户:
#!/usr/bin/python # This is client.py file
import socket # Import socket module
import sys
import time
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.connect((host, port))
i = 0
start = time.time()
while i < int(sys.argv[1]):
s.recv(100000000)
i = i + 1
end = time.time()
print "Time taken is %s" % (end - start)
s.close
当我 运行 1000 万次接收时,在 ubuntu 14.04 上需要 375 秒,而在 ubuntu 10.04 上只需要 305 秒。
假设您使用相同的硬件,您在 10.04 和 14.04 之间仍然有很多变化,即不同的内核、不同的库、不同的 python、可能不同的系统调整等。所以不要指望任何人指出您的高水平基准测试速度放缓的原因。
只是想说明此类性能问题可能潜伏在何处:更改调度程序或同一系统上的进程 运行 可能会导致 CPU 的负载不同。如果 CPU 变得太热,它将被迫以 运行 的速度冷却,这可能会导致很大的性能差异。另一方面,如果 CPU 太空闲,它将进入各种省电模式,从这些模式中唤醒需要一些时间,这也会影响性能。其他严重影响性能的东西是 CPU 缓存,即如果相关的 python 代码完全适合 10.04 中的处理器缓存并且现在有点太大,您可能会出现严重的性能差异。
我正在 运行ning python 2.7.8 并观察到 ubuntu 14.04 与 10.04 相比,使用简单的 socket.recv API 性能下降了 23% .我可以分享我的代码、准确的性能数据等,供任何人查看。
这是我的服务器:
#!/usr/bin/python # This is server.py file
import socket # Import socket module
import sys
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port
f = open ("file", "r")
fdata = f.read(100000000)
s.listen(5) # Now wait for client connection.
while True:
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
if sys.argv[1] == '1':
c.send('Thank you for connecting')
elif sys.argv[1] == '2':
c.send(fdata)
c.close()
这是我的客户:
#!/usr/bin/python # This is client.py file
import socket # Import socket module
import sys
import time
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.connect((host, port))
i = 0
start = time.time()
while i < int(sys.argv[1]):
s.recv(100000000)
i = i + 1
end = time.time()
print "Time taken is %s" % (end - start)
s.close
当我 运行 1000 万次接收时,在 ubuntu 14.04 上需要 375 秒,而在 ubuntu 10.04 上只需要 305 秒。
假设您使用相同的硬件,您在 10.04 和 14.04 之间仍然有很多变化,即不同的内核、不同的库、不同的 python、可能不同的系统调整等。所以不要指望任何人指出您的高水平基准测试速度放缓的原因。
只是想说明此类性能问题可能潜伏在何处:更改调度程序或同一系统上的进程 运行 可能会导致 CPU 的负载不同。如果 CPU 变得太热,它将被迫以 运行 的速度冷却,这可能会导致很大的性能差异。另一方面,如果 CPU 太空闲,它将进入各种省电模式,从这些模式中唤醒需要一些时间,这也会影响性能。其他严重影响性能的东西是 CPU 缓存,即如果相关的 python 代码完全适合 10.04 中的处理器缓存并且现在有点太大,您可能会出现严重的性能差异。