为什么滴水工具不会影响我的动态链接的 Golang 程序?

huangapple go评论99阅读模式
英文:

Why doesn't the trickle utility affect my dynamically-linked golang program?

问题

我有一个使用golang编写的程序,通过https将大量数据上传到OpenStack对象存储。它依赖于golang标准库"net/http"来完成工作。我想使用"trickle"来限制数据的上传速率,但是使用trickle运行我的代码似乎没有任何效果(就好像我根本没有使用trickle一样)。

为什么会发生这种情况?是trickle或golang存在某些限制,阻止它们一起工作吗?有没有什么我没有考虑到的问题?

这是我的设置:

我知道"trickle"只能用于动态链接的可执行文件(请参阅trickle文档的第一段),所以我使用"go build -compiler gccgo mycode.go"编译了我的代码,"ldd myexecutable"的输出是:

linux-vdso.so.1 =>  (0x00007ffee27b8000)
libgo.so.9 => /usr/lib/x86_64-linux-gnu/libgo.so.9 (0x00007f46062bf000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f46060a9000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4605cdf000)
/lib64/ld-linux-x86-64.so.2 (0x000055aa4d0a4000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4605ac2000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f46057b9000)

我在Ubuntu Linux 16.04上运行这个程序。我使用"slurm"来查看运行命令时的网络流量。该机器没有运行其他网络密集型任务,所以我确信我看到的流量是由我的代码生成的。

当我运行

trickle -s -v -u2500 myexecutable ...args

我看到我的TX网络流量突增到约12000KB/s(网络的最大处理能力),而不是遵守我设定的2500KB/s的限制。

有人能想到为什么会发生这种情况,或者我可以尝试什么来解决它吗?

英文:

I have a golang program that uploads a ton of data to OpenStack Object Storage over https. It relies on the golang standard library "net/http" to do the work. I would like to use trickle to rate-limit the upload of the data, but running my code using trickle does not seem to have any effect (as though I'm not using trickle at all).

Why does this happen? Is there some limitation to trickle or golang that prevents them from working together? Is there some gotcha that I haven't considered?

This is my setup:

I know that trickle only works on dynamically-linked executables (see first paragraph of trickle documentation), so I've compiled my code with go build -compiler gccgo mycode.go and the output of ldd myexecutable is:

linux-vdso.so.1 =>  (0x00007ffee27b8000)
libgo.so.9 => /usr/lib/x86_64-linux-gnu/libgo.so.9 (0x00007f46062bf000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f46060a9000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4605cdf000)
/lib64/ld-linux-x86-64.so.2 (0x000055aa4d0a4000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4605ac2000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f46057b9000)

I'm running this on Ubuntu Linux 16.04. I use slurm to view the network traffic as my command runs. The machine isn't running any other network-intensive jobs, so I'm confident that I'm seeing the traffic generated by my code.

When I run

trickle -s -v -u2500 myexecutable ...args

I see my TX network traffic spike to about 12000KB/s (the maximum that the network can handle) instead of respecting my limit of 2500KB/s.

Can anyone think of why this might happen or what I could try to fix it?

答案1

得分: 6

Trickle依赖于使用LD_PRELOAD来替换libc中所有与网络相关的调用,以使用自己的实现。这就是为什么trickle不能与静态二进制文件一起使用。

Go直接进行所有系统调用,不使用libc接口,因此不会使用trickle提供的插入函数。

英文:

Trickle relies on using LD_PRELOAD to replace all network related calls through libc with its own implementation. This is why trickle doesn't work with static binaries.

Go makes all its own syscalls directly and does not use the libc interface, so the inter-positioned functions provided by trickle are not used.

huangapple
  • 本文由 发表于 2016年11月3日 02:12:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/40386936.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定