简体   繁体   English

控制台输出消耗多少CPU? (每秒约140行)

[英]Console output consuming much CPU? (about 140 lines per second)

I am doing my bachelor's thesis where I wrote a program that is distributed over many servers and exchaning messages via IPv6 multicast and unicast. 我正在写本科学位论文,当时我编写了一个程序,该程序分布在许多服务器上,并通过IPv6多播和单播来交换消息。 The network usage is relatively high but I think it is not too high when I have 15 servers in my test where there are 2 requests every second that are going like that: 网络使用率相对较高,但我认为当测试中有15台服务器时,每秒会有2个请求,这并不是很高:

Server 1 requests information from server 3-15 via multicast. 服务器1通过多播向服务器3-15请求信息。 every of 3-15 must respond. 3-15岁的每个人都必须做出回应。 if one response is missing after 0.5 sec, the multicast is resent, but only the missing servers must respond (so in most cases this is only one server) Server 2 does exactly the same. 如果在0.5秒后缺少一个响应,则重新发送多播,但是只有丢失的服务器必须响应(因此,在大多数情况下,这只是一台服务器),服务器2完全相同。 If there are missing results after 5 retries the missing servers are marked as dead and the change is synced with the other server (1/2) 如果5次重试后仍缺少结果,则将丢失的服务器标记为无效服务器,并将更改与其他服务器同步(1/2)

So there are 2 multicasts every second and 26 unicasts every second. 因此,每秒有2个多播,每秒有26个单播。 I think this should not be too much? 我认为应该不应该太多吗?

Server 1 and 2 are running python web servers which I use to do the request every second on each server (via a web client) 服务器1和2正在运行python Web服务器,我用来在每个服务器上每秒(通过Web客户端)发出请求

The whole szenario is running in a mininet environment which is running in a virtual box ubuntu that has 2 cores (max 2.8ghz) and 1GB RAM. 整个szenario在mininet环境中运行,该环境在具有2个核心(最大2.8ghz)和1GB RAM的虚拟盒子ubuntu中运行。 While running the test, i see via htop that the CPUs are at 100% while the RAM is at 50%. 在运行测试时,我通过htop看到CPU占100%,而RAM占50%。 So the CPU is the bottleneck here. 因此,CPU是这里的瓶颈。

I noticed that after 2-5 minutes (1 minute = 60 * (2+26) messages = 1680 messages) there are too many missing results causing too many sending repetitions while new requests are already coming in, so that the "management server" thinks the client servers (3-15) are down and deregisters them. 我注意到2-5分钟(1分钟= 60 *(2 + 26)消息= 1680消息)之后,丢失了太多结果,导致新请求进入时发送重复次数过多,因此“管理服务器”认为客户端服务器(3-15)已关闭并注销了它们。 After syncing this with the other management server, all client servers are marked as dead on both management servers which is not true... 与其他管理服务器同步后,所有客户端服务器在两个管理服务器上都标记为已失效,这是不正确的...

I am wondering if the problem could be my debug outputs? 我想知道问题是否出在我的调试输出上? I am printing 3-5 messages for every message that is sent and received. 我为发送和接收的每条消息打印3-5条消息。 So that are about (let's guess it are 5 messages per sent/recvd msg) (26 + 2)*5 = 140 lines that are printed on the console. 这样就差不多了(让我们猜每个发送/接收的消息是5条消息)(26 + 2)* 5 =在控制台上打印的140行。

I use python 2.6 for the servers. 我将python 2.6用于服务器。

So the question here is: Can the console output slow down the whole system that simple requests take more than 0.5 seconds to complete 5 times in a row? 因此,这里的问题是:控制台输出会降低整个系统的速度吗,因为简单请求连续5次要花费0.5秒以上的时间? The request processing is simple in my test. 在我的测试中,请求处理很简单。 No complex calculations or something like that. 没有复杂的计算或类似的东西。 basically it is something like "return request_param in ["bla", "blaaaa", ...] (small list of 5 items)" 基本上,它类似于“在[“ bla”,“ blaaaa”,...]中返回return_param(5个项目的清单)

If yes, how can I disable the output completely without having to comment out every print statement? 如果是,如何完全禁用输出而不必注释掉每个打印语句? Or is there even the possibility to output only lines that contain "Error" or "Warning"? 或者甚至有可能只输出包含“错误”或“警告”的行? (not via grep, because when grep becomes active all the prints already have finished... I mean directly in python) (不是通过grep,因为当grep变为活动状态时,所有打印都已经完成了……我的意思是直接在python中)

What else could cause my application to be that slow? 还有什么可能导致我的申请这么慢? I know this is a very generic question, but maybe someone already has some experience with mininet and network applications... 我知道这是一个非常笼统的问题,但也许有人已经对mininet和网络应用程序有了一些经验...

I finally found the real problem. 我终于找到了真正的问题。 It was not because of the prints (removing them improved performance a bit, but not significantly) but because of a thread that was using a shared lock. 这不是因为打印(删除它们会稍微改善性能,但不是很明显),而是因为线程使用了共享锁。 This lock was shared over multiple CPU cores causing the whole thing being very slow. 此锁在多个CPU内核上共享,导致整个过程非常缓慢。

It even got slower the more cores I added to the executing VM which was very strange... 我添加到执行虚拟机中的内核越多,速度就越慢,这很奇怪。

Now the new bottleneck seems to be the APScheduler... I always get messages like "event missed" because there is too much load on the scheduler. 现在,新的瓶颈似乎是APScheduler ...我总是收到诸如“事件丢失”之类的消息,因为调度程序上的负载过多。 So that's the next thing to speed up... :) 所以这是下一步要加快的速度... :)

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

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