Subject: | Net::Statsd could be much more efficient |
For every single send() Net::Statsd does much more work than it needs to because it creates and destroys a socket every single time.
The cost is high. All these system calls:
open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 19
fstat(19, {st_mode=S_IFREG|0444, st_size=5429, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5666607000
read(19, "################################"..., 4096) = 4096
read(19, "om\ttinyproxy07\t; git\n10.16.252.2"..., 4096) = 1333
read(19, "", 4096) = 0
close(19) = 0
munmap(0x7f5666607000, 4096) = 0
socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP) = 19
ioctl(19, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7ffff70be160) = -1 EINVAL (Invalid argument)
lseek(19, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
ioctl(19, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7ffff70be160) = -1 EINVAL (Invalid argument)
lseek(19, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
fcntl(19, F_SETFD, FD_CLOEXEC) = 0
connect(19, {sa_family=AF_INET, sin_port=htons(8125), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
getpeername(19, {sa_family=AF_INET, sin_port=htons(8125), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
getpeername(19, {sa_family=AF_INET, sin_port=htons(8125), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
sendto(19, "logsender.type-.status-200:1|c", 30, 0, NULL, 0) = 30
close(19) = 0
could be reduced to just one:
sendto(19, "logsender.type-test.status-200:1|c", 30, 0, NULL, 0) = 30