OpenSSL导致丢包?奇怪的CPU使用率
我正在编写网络应用程序,从 UDP 套接字读取数据包,然后使用 OpenSSL 解密它们。
主要功能如下所示:
receive(){
while(1){
read(udp_sock);
decrypt_packet();
}
}
程序过去工作正常,直到我添加加密。现在,内核缓冲区和我的应用程序之间丢失了很多数据包(netstat -su - RcvbufErrors:77123并且不断增长;)。数据包相当大(60K),我尝试在 1Gbps 以太网上使用它(因此超过 100Mbps 后问题就开始了)
听起来很正常 - 解密花费太多时间,数据包来得太快。问题是 - 发送方和接收方的 CPU 使用率永远不会超过 30%。
在decrypt_packet()中注释掉这条语句后问题就消失了: AES_ctr128_加密();
我的问题是 - OpenSSL 是否可能使用某些不计入 CPU 使用率的指令集(我使用 htop 和 Gnome 系统监视器)?如果不是,还有什么会导致这样的数据包丢失,CPU 能力仍然可用于处理吗?
I'm writing network application reading packets from UDP sockets and then decrypting them using OpenSSL.
The main function looks like this:
receive(){
while(1){
read(udp_sock);
decrypt_packet();
}
}
Program used to work fine until I added encryption. Now there's a lot of packets lost between kernel buffer and my application (netstat -su - RcvbufErrors: 77123 and growing ;). Packets are rather big (60K) and I try to use it on 1Gbps ethernet (thus problem begins after exceeding 100Mbps)
Sounds normal - decryption taking too much time and packets are coming too fast. The problem is - CPU usage never exceeds 30% both on the sender and the receiver.
Problem disappears after commenting out this statement in decrypt_packet():
AES_ctr128_encrypt();
My question is - is it possible, that OpenSSL is using some set of instruction which are not count in to CPU usage (I use htop and Gnome system monitor)? If not what else can cause such packet loss is CPU power is still available for processing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的系统有多少个 CPU 核心?你的代码是单线程的吗?它可能会最大化单个核心,因此仅使用 25% 的可用 CPU。
How many CPU cores does your system have? Is your code single threaded? It could be maxing out a single core and thus using only 25% of the available CPU.
使用探查器我能够解决这个问题。 OpenSSL 使用特殊的指令集,这些指令在 CPU 的特殊部分执行。显示的 CPU 使用率很低,但实际上它被占用进行加密,因此我的应用程序无法足够快地读取系统缓冲区。
我将解密移至其他线程,解决了该问题。现在,处理所有加密的线程显示为始终使用 0% CPU。
Using profiler I was able to solve the problem. OpenSSL is using special set of instructions, which are executed in special part of CPU. Shown CPU usage was low, but in fact it was occupied doing encryption, so my application couldn't read system buffer fast enough.
I moved decryption to other thread which solved the problem. And now the thread handling all encryption is shown as using 0% CPU all the time.