简体   繁体   English

扭曲吞吐量限制减少

[英]Twisted Throughput Limit Decreases

I am developing a program which allows for simulations of networks on a single machine. 我正在开发一个允许在一台机器上模拟网络的程序。 For this I am using Twisted for asynchronous I/O, as having a thread for each 'connection' might be a bit much. 为此,我使用Twisted进行异步I / O,因为每个'连接'都有一个线程可能有点多。 (I have also implemented a similar program in Java using their NIO). (我还使用他们的NIO在Java中实现了类似的程序)。 However as I scale the emulated network size up the throughput on Twisted decreases. 但是,随着我对模拟网络规模的扩展,Twisted上的吞吐量会降低。 When comparing this to the Java implementation, for the same network size, the Java throughput continues to grow. 将其与Java实现进行比较时,对于相同的网络大小,Java吞吐量会继续增长。 (The growth rate slows down, but it's still an increase). (增长率放缓,但仍然是增长)。 Eg (Python 100 nodes = 58MB Total throughput, 300 nodes = 45MB, Java 100 nodes = 24 MB, 300 nodes = 56MB). 例如(Python 100节点= 58MB总吞吐量,300个节点= 45MB,Java 100节点= 24 MB,300个节点= 56MB)。

I am wondering if anyone has any suggestion on why this might be happening? 我想知道是否有人有任何关于为什么会发生这种情况的建议?

The only reason that I can think of is that the Java one has each 'peer' running in its own thread (which contains its own selector that monitors that peers connections). 我能想到的唯一原因是Java的每个'peer'都在自己的线程中运行(它包含自己的监视对等连接的选择器)。 In the python version everything is registered with the reactor (and subsequently the one selector). 在python版本中,所有内容都在reactor(以及随后的一个选择器)中注册。 As the python one scales up the one selector is not able to respond as fast. 随着python的扩展,一个选择器无法快速响应。 However this is just a guess, if anyone has any more concreate information it would be appriciated. 然而,这只是一个猜测,如果任何人有任何更多的具体信息,它将被appriciated。

EDIT: I ran some testing as suggested by Jean-Paul Calderone, the results are posted at imgur . 编辑:我按照Jean-Paul Calderone的建议进行了一些测试,结果发布在imgur For those who might be wondering the following Avg throughput was reported for the tests. 对于那些可能想知道测试报告以下Avg吞吐量的人。 (The profiling was done with cProfile, tests were run for 60 seconds) (分析是用cProfile完成的,测试运行了60秒)

Epoll Reactor: 100 Peers: 20.34 MB, 200 Peers: 18.84 MB, 300 Peers: 17.4 MB Epoll Reactor:100对等:20.34 MB,200对等:18.84 MB,300对等:17.4 MB

Select Reactor: 100 Peers: 18.86 MB, 200 Peers: 19.08 MB, 300 Peers: 16.732 MB 选择Reactor:100对等:18.86 MB,200对等:19.08 MB,300对等:16.732 MB

A couple things that seemed to go up and down with the reported throughput was the calls made to main.py:48(send), but this corrolation is not really a surprise as this is where the data is being sent. 对报告的吞吐量似乎上下的一些事情是对main.py:48(send)的调用,但这种腐蚀并不是一个惊喜,因为这是数据发送的地方。

For both of the reactor the time spent in the send function on the socket(s) increased as throughput decreased, as well as the number of calls to the send function decreased as throughput decreased. 对于两个反应器,套接字上的发送功能所花费的时间随着吞吐量的减少而增加,并且随着吞吐量的减少,对发送功能的调用次数也减少。 (That is: more time was spent sending on the socket, with less calls to send on a socket.) Eg 2.5 sec for epoll {method 'send' of '_socket.socket' objects} on 100 peers for 413600 calls, to 5.5 sec for epoll on 300 peers, for 354300 calls. (也就是说:在套接字上花费的时间更多,在套接字上发送的呼叫次数更少。)例如,对于413600个呼叫,100个对等体上的epoll {方法'发送''_socket.socket'对象}为2.5秒,为5.5对于300个同行的epoll,为354300个电话。

So as to try to answer the original question, does this data seem to point to the selector being a limiting factor? 为了尝试回答原始问题,这些数据是否似乎指向选择器是一个限制因素? The time spent in the Selector seems to decrease as the number of peers increases ( if the selector was slowing everything down wouldn't one expect the time spent inside to rise?) Is there anything else that might be slowing the amount of data being sent? 在Selector中花费的时间似乎随着对等体数量的增加而减少(如果选择器减慢了一切,那么人们不会期望内部花费的时间会增加吗?)还有什么可能会减慢发送的数据量? (The sending of the data is just one function for each peer that is registered with reactor.calllater again and again. That is the main.py:49 (send)) (数据的发送只是一次又一次向reactor.calllater注册的每个对等体的一个函数。那就是main.py:49(发送))

Try profiling the application at different levels of concurrency and see which things get slower as you add more connections. 尝试在不同的并发级别上分析应用程序,并在添加更多连接时查看哪些内容变慢。

select is a likely candidate; select是一个可能的候选人; if you find that it is using noticably more and more time as you add connections, try using the poll or epoll reactor . 如果您发现在添加连接时使用的时间越来越多,请尝试使用pollepoll reactor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM