arcus-memcached
arcus-memcached copied to clipboard
FEATURE: Add stats_tcp_retrans()
๐ Related Issue
- https://github.com/jam2in/arcus-works/issues/498
โจ๏ธ What I did
- stats ๋ช ๋ น์ด์ TCP ์ฌ์ ์ก ์์น๋ฅผ ํจ๊ป ์ถ๋ ฅํ๋๋ก ํฉ๋๋ค.
- prometehus์ node_exporter์ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก retrans ์์น๋ฅผ ํ์ธํฉ๋๋ค.
-
/proc/net/snmp
file์์Tcp: RetransSegs
์ ํด๋นํ๋ ๊ฐ์int64_t
๋ก ๋ณํํฉ๋๋ค. -
/proc/net/snmp
ํ์ผ ๋ด์ฉ ์์๋ ์๋์ ๊ฐ์ต๋๋ค.
$ cat /proc/net/snmp
Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates
Ip: 1 64 1157539 0 2 0 0 0 1157535 1017212 0 0 0 0 0 0 0 0 0
Icmp: InMsgs InErrors InCsumErrors InDestUnreachs InTimeExcds InParmProbs InSrcQuenchs InRedirects InEchos InEchoReps InTimestamps InTimestampReps InAddrMasks InAddrMaskReps OutMsgs OutErrors OutDestUnreachs OutTimeExcds OutParmProbs OutSrcQuenchs OutRedirects OutEchos OutEchoReps OutTimestamps OutTimestampReps OutAddrMasks OutAddrMaskReps
Icmp: 151318 127 0 131 7 0 0 1 151158 21 0 0 0 0 151158 0 0 0 0 0 0 0 151158 0 0 0 0
IcmpMsg: InType0 InType3 InType5 InType8 InType11 OutType0
IcmpMsg: 21 131 1 151158 7 151158
Tcp: RtoAlgorithm RtoMin RtoMax MaxConn ActiveOpens PassiveOpens AttemptFails EstabResets CurrEstab InSegs OutSegs RetransSegs InErrs OutRsts InCsumErrors
Tcp: 1 200 120000 -1 6210 26425 2397 3871 6 1000039 866909 14396 0 8094 0
Udp: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors InCsumErrors IgnoredMulti MemErrors
Udp: 6190 0 0 6190 0 0 0 0 0
UdpLite: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors InCsumErrors IgnoredMulti MemErrors
UdpLite: 0 0 0 0 0 0 0 0 0
- ์๋๋ ์ค์ ๋ช ๋ น์ด ์ฌ์ฉ ์ ์ถ๋ ฅ ์์์ ๋๋ค.
$ echo stats | nc localhost 11211
...
STAT tcp_retrans 9815302
...
END
๋ด์ฉ ์ถ๊ฐ
โจ๏ธ What I did
- prometehus์ node_exporter์ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก retrans ์์น๋ฅผ ํ์ธํฉ๋๋ค.
-
/proc/net/snmp
file์์Tcp: RetransSegs
์ ํด๋นํ๋ ๊ฐ์uint64_t
๋ก ๋ณํํฉ๋๋ค. -
/proc/net/snmp
ํ์ผ ๋ด์ฉ ์์๋ ์๋์ ๊ฐ์ต๋๋ค.
$ cat /proc/net/snmp
Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates
Ip: 1 64 1157539 0 2 0 0 0 1157535 1017212 0 0 0 0 0 0 0 0 0
Icmp: InMsgs InErrors InCsumErrors InDestUnreachs InTimeExcds InParmProbs InSrcQuenchs InRedirects InEchos InEchoReps InTimestamps InTimestampReps InAddrMasks InAddrMaskReps OutMsgs OutErrors OutDestUnreachs OutTimeExcds OutParmProbs OutSrcQuenchs OutRedirects OutEchos OutEchoReps OutTimestamps OutTimestampReps OutAddrMasks OutAddrMaskReps
Icmp: 151318 127 0 131 7 0 0 1 151158 21 0 0 0 0 151158 0 0 0 0 0 0 0 151158 0 0 0 0
IcmpMsg: InType0 InType3 InType5 InType8 InType11 OutType0
IcmpMsg: 21 131 1 151158 7 151158
Tcp: RtoAlgorithm RtoMin RtoMax MaxConn ActiveOpens PassiveOpens AttemptFails EstabResets CurrEstab InSegs OutSegs RetransSegs InErrs OutRsts InCsumErrors
Tcp: 1 200 120000 -1 6210 26425 2397 3871 6 1000039 866909 14396 0 8094 0
Udp: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors InCsumErrors IgnoredMulti MemErrors
Udp: 6190 0 0 6190 0 0 0 0 0
UdpLite: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors InCsumErrors IgnoredMulti MemErrors
UdpLite: 0 0 0 0 0 0 0 0 0
์ด์ ์ Offline์์ ๋ง์๋๋ฆฐ ๋ฐ๋ก ํ์ฌ ์ด์ PR๊ณผ ์ถฉ๋์ด ๋ ๊ด๊ณ๋ก stats ๋ชจ๋์ด ์๋ ๋ค๋ฅธ ์์น๋ก ์ด๋ ๋ถํ๋๋ฆฝ๋๋ค.
@namsic
prometehus์ node_exporter์ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก retrans ์์น๋ฅผ ํ์ธํฉ๋๋ค.
์ ํฌ ์ชฝ์์ ๋ง๋ ๋ก์ง์ธ ๊ฑด๊ฐ์? ์๋๋ฉด prometheus ์ ๋ก์ง์ธ๊ฐ์?
@uhm0311
@jhpark816 ๋๊ป์ ๋ง์ํ์ ๋๋ก stats lock์ ์ก๊ณ ๋ค์ด๊ฐ๊ธฐ์ ๋ค๋ฅธ connection์ ์ฑ๋ฅ์ ์ํฅ์ ๋ผ์น ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค. ์ด ๋ถ๋ถ์ ๋ํ์ฌ stats๋ฅผ ๋ ๋ฆฐ connection ๋ฟ๋ง ์๋๋ผ ๋ค๋ฅธ connection์ ๋ช ๋ น์ด ์ํ์ ์ํฅ์ ์ฃผ๋ ์ง ์ฑ๋ฅ ๊ฒ์ฌ๊ฐ ํ์ํ ๊ฒ ๊ฐ์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ /proc/net/snmp ๋ด ๋ด์ฉ์ ๋ณด๋ฉด ํฌ๊ธฐ๊ฐ ํฌ์ง ์์ ๊ฒ์ผ๋ก ๋ณด์ด๋ฏ๋ก stats ํธ์ถ๋ง๋ค ํ์ผ์ ๋ถ๋ฌ์ parsingํ๋ ๊ฒ์ด ์๋ memcached ๊ตฌ๋ ์ด๊ธฐ์ ํด๋น ํ์ผ์ memory mapping ํ๋ ๋ฐฉ์์ ์ด๋ค๊ฐ์?
์ ํฌ ์ชฝ์์ ๋ง๋ ๋ก์ง์ธ ๊ฑด๊ฐ์? ์๋๋ฉด prometheus ์ ๋ก์ง์ธ๊ฐ์?
prometheus์์ ๋ง๋ ๋ก์ง์ ๋๋ค.
memcached ๊ตฌ๋ ์ด๊ธฐ์ ํด๋น ํ์ผ์ memory mapping ํ๋ ๋ฐฉ์์ ์ด๋ค๊ฐ์?
/proc/net/snmp ํ์ผ์ pseudo ํ์ผ๋ก, Disk IO๊ฐ ํ์ํ์ง ์๊ธฐ ๋๋ฌธ์ ๋งคํํ์ง ์์๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค.
https://unix.stackexchange.com/questions/8274/what-happens-when-i-open-and-read-from-proc
๋ช ๋ น์ด ์ํ์ ์ํฅ์ ์ฃผ๋ ์ง ์ฑ๋ฅ ๊ฒ์ฌ๊ฐ ํ์ํ ๊ฒ ๊ฐ์ต๋๋ค.
vCore 4๊ฐ ๊ธฐ์ค ๋ค์๊ณผ ๊ฐ์ ์ฑ๋ฅ์ ๋ณด์ ๋๋ค.
149.169391 seconds for call function 1000003 times.
0.000149 seconds per function call.
ํ
์คํธ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ผ๋ฉฐ, stats_tcp_retrans()
ํจ์์ ๊ตฌํ์ PR ํํ์ ๋์ผํฉ๋๋ค.
uint64_t loop = 1000003;
void with_gettimeofday(void) {
uint64_t i = 0;
struct timeval start, end;
gettimeofday(&start, NULL);
for (i = 0; i < loop; i++) {
stats_tcp_retrans();
}
gettimeofday(&end, NULL);
double elapsed = (end.tv_sec - start.tv_sec) + ((end.tv_usec - start.tv_usec)/1000000.0);
printf("%lf seconds for call function %lld times.\n", elapsed, loop);
printf("%lf seconds per function call.\n", elapsed / loop);
}
int main() {
with_gettimeofday();
return 0;
}
@ing-eoking
๋ฐ์ํ์ต๋๋ค.