summaryrefslogtreecommitdiff
path: root/doc/note/openshift/dbg-mem-issues.txt
blob: ef69f7a42b9d48f9f9c2a0be2ca73e9d2373da21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

How to hunt memory issues in production
=======================================

true \
  && SVCNAME=foo-prod \
  && PID=42 \
  && OC= \
  && JMX= \
  && MemLeakTry1="lua -W MemLeakTry1.lua" \
  && dropPadding () { sed -E 's_ *; *_;_g'; } \
  && getPodName () { ${OC:?} get pods | egrep ston-[0-9] | cut -d' ' -f1; } \
  && true


${OC:?} exec -ti "$(${OC:?} get pods|egrep ston-1|cut -f1 -d' ')" -- pmap 9 > "pmap/${SVCNAME:?}"-pmap-$(date -u +%Y%m%d-%H%M%S).txt

true `# Track pod memory` \
  && ${OC:?} exec -ti "$(${OC:?} get pods|grep ston-[1-9]|cut -f1 -d' ')" -- sh -c 'true \
    && printf '\''h;PageSize;%s\n'\'' $(getconf PAGESIZE) \
    && printf '\''c;%-24s;%8s;%8s;%8s;%5s;%4s;%3s;%8s;%3s;%7s\n'\'' When nThrds size RSS SHR text lib data dt nFds \
    && while true; do true \
      && printf '\''r;%s;%8s;%8d;%8d;%5d;%4d;%3d;%8d;%3d;%7d\n'\'' \
           "$(date -Is)" \
           $(cat /proc/'${PID:?}'/stat|cut -d" " -f20) \
           $(cat /proc/'${PID:?}'/statm) \
           $(ls -1 /proc/'${PID:?}'/fd | wc -l) \
      && sleep $(expr 60 - \( $(date +%s) % 60 \)) || break; done' \
    | tee "mem/${SVCNAME:?}"-mem-$(date +%Y%m%d-%H%M%S%z).csv

true `# log JMX stuff` \
  && grepUsed () { egrep 'used : ' | sed -r 's_^[^0-9]+ ([0-9]+) [^0-9]+$_\1_'; } \
  && grepPureNumberLine () { egrep $(printf '^[0-9]+\r?$') | sed -r 's_^(.*)\r$_\1_'; } \
  && (true \
    && printf 'c; When                    ; JvmMetaspace; jvmNonHeap; JvmClassCnt;    JvmHeap\n' \
    && while true; do true \
      && metaSpcByts="$(curl -sS "${JMX:?}"'/servers/0/domains/java.lang/mbeans/name=Metaspace,type=MemoryPool/attributes/Usage/' | grepUsed)" \
      && jvmNonHeap="$(curl -sS "${JMX:?}"'/servers/0/domains/java.lang/mbeans/type=Memory/attributes/NonHeapMemoryUsage/' | grepUsed)" \
      && ldClassCnt="$(curl -sS "${JMX:?}"'/servers/0/domains/java.lang/mbeans/type=ClassLoading/attributes/LoadedClassCount/' | grepPureNumberLine)" \
      && jvmHeap="$(curl -sS "${JMX:?}"'/servers/0/domains/java.lang/mbeans/type=Memory/attributes/HeapMemoryUsage/' | grepUsed)" \
      && printf 'r;%s;%13d;%11d;%12d;%11d\n'  "$(date -Is)"  "${metaSpcByts:?}"  "${jvmNonHeap:?}"  "${ldClassCnt:?}"  "${jvmHeap:?}" \
      && sleep $(expr 60 - \( $(date +%s) % 60 \)) || break \
      ; done) \
    | tee "jmx/houston-prod-jmx-Metaspace-used-$(date +%Y%m%d-%H%M%S).log" \
  && true

(true `# Fetch logs` \
  && while true; do true \
    && printf '%s - Fetch logs\n' "$(date -Is)" \
    && ${OC:?} exec -i "$(getPodName)" -- sh -c 'cd /usr/local/vertx/logs && (tar -cz houston* || test $? -eq 1)' \
      > "logs/${SVCNAME:?}-log-$(date -u +%Y%m%d-%H%M%SZ).tgz" \
    && sleep $(expr 14400 - \( $(date +%s) % 14400 \)) || break; done \
  && true)

true `# Merge logs` \
  && PREFX="houston-prod-log-" \
  && SUFFX=".tgz" \
  && for SRCTGZ in \
       ${PREFX:?}20231110-160510Z${SUFFX:?} \
       ${PREFX:?}20231110-181226Z${SUFFX:?} \
       ${PREFX:?}20231114-093133Z${SUFFX:?} \
       ${PREFX:?}20231114-120002Z${SUFFX:?} \
       ${PREFX:?}20231114-123040Z${SUFFX:?} \
       ${PREFX:?}20231114-160001Z${SUFFX:?} \
       ${PREFX:?}20231116-082933Z${SUFFX:?} \
       ${PREFX:?}20231116-120002Z${SUFFX:?} \
       ${PREFX:?}20231116-160002Z${SUFFX:?} \
       ${PREFX:?}20231117-081112Z${SUFFX:?} \
       ${PREFX:?}20231117-120001Z${SUFFX:?} \
       ${PREFX:?}20231117-164612Z${SUFFX:?} \
     ; do true \
       && echo "[INFO ] Create ${SRCTGZ%.*}.log" \
       && tar xf ../logs/${SRCTGZ:?} \
       && unzip houston.log.1.zip \
       && cat houston.log.1 houston.log > "${SRCTGZ%.*}.log" \
       && rm houston.log.1.zip houston.log.1 houston.log \
     ;done && true \
  && printf '%s' '
       local newLogFileMerger = require("AndisLogUtils").newLogFileMerger
       local merger = newLogFileMerger{
         sources = {
             io.open("houston-prod-log-20231110-160510Z.log", "r"),
             io.open("houston-prod-log-20231110-181226Z.log", "r"),
             io.open("houston-prod-log-20231114-093133Z.log", "r"),
             io.open("houston-prod-log-20231114-120002Z.log", "r"),
             io.open("houston-prod-log-20231114-123040Z.log", "r"),
             io.open("houston-prod-log-20231114-160001Z.log", "r"),
             io.open("houston-prod-log-20231116-082933Z.log", "r"),
             io.open("houston-prod-log-20231116-120002Z.log", "r"),
             io.open("houston-prod-log-20231116-160002Z.log", "r"),
             io.open("houston-prod-log-20231117-081112Z.log", "r"),
             io.open("houston-prod-log-20231117-120001Z.log", "r"),
             io.open("houston-prod-log-20231117-164612Z.log", "r"),
         },
         snk = { write = function( t, buf, b, c ) io.stdout:write(buf) io.stdout:write("\n") end, },
       }' | lua -W - | gzip -n > houston-log-merged-$(date -u +%Y%m%d-%H%M%S)Z.log.gz \
  && true


`# Create heap dump`
com.sun.management.dumpHeap("/usr/local/vertx/houston-storage-file/houston-___-heap-2023____-____Z.hprof", true)

`# Inspect`
ocprod exec -i "$(ocprod get pods|egrep ston-[1-9]|cut -f1 -d' ')" -- sh -c 'cd /usr/local/vertx/houston-storage-file && ls -Ahl'

true `# Get made heap dump` \
  && echo create checksum. \
  && ocprod exec -i "$(ocprod get pods|egrep ston-[1-9]|cut -f1 -d' ')" -- sh -c 'cd /usr/local/vertx/houston-storage-file && md5sum -b houston-*.hprof >> MD5SUM-$(date -u +%Y%m%d-%H%M%SZ)' \
  && echo checksum done. Begin dload. \
  && ocprod exec -i "$(ocprod get pods|egrep ston-[1-9]|cut -f1 -d' ')" -- sh -c 'cd /usr/local/vertx/houston-storage-file && tar c houston-*.hprof MD5SUM*' | (cd heapDump && tar x) \
  && echo dload done \
  && true

true `# Probe` \
  && stage=prod \
  && logFile="houston-ready-${stage:?}-$(date -u +%Y%m%d-%H%M%SZ).log" \
  && printf 'c; when                   ;rspCode; connectSec; trsfSec; totlSec; curlExit\n' | tee -a "${logFile:?}" \
  && while true; do true \
     && printf 'r;%s;%7d;%11.3f;%8.3f;%8.3f;%9d\n' \
           $(date +%Y-%m-%dT%H:%M:%S%z) \
           $(curl -sSw "%{http_code} %{time_connect} %{time_starttransfer} %{time_total}" "${houstonServerInfoUrl:?}" -o /dev/null || ex=$? && echo " $ex") \
           | tee -a "${logFile:?}" \
     && sleep $(expr 60 - $(date +%s) % 60) || break \
     ;done \
  && true

true \
  && ONE="houston-prod-pmap-20231102-163425.txt" \
  && TWO="houston-prod-pmap-20231103-074301.txt" \
  && diff -U0 "${ONE:?}" "${TWO:?}" | egrep '^\+' | sed -r 's_\+([^ ]+) .*$_\1_'|sort|uniq \
  && true

(true \
  && for F in $(ls *pmap*.txt); do true \
    && printf "$F\n" \
    && DATE="$(date +%s -d "$(echo $F|sed -r 's_.*([0-9]{4})([0-9]{2})([0-9]{2})-([0-9]{2})([0-9]{2})([0-9]{2}).*_\1-\2-\3T\4:\5:\6Z_')")" \
    && <"$F" ${MemLeakTry1:?} --date "${DATE:?}" > "${F%.*}.csv" \
    ;done)







Zwischenfall auf INT 20231124



`# Create heap dump`
com.sun.management.dumpHeap("/usr/local/vertx/houston-storage-file/houston-___-heap-2023____-____Z.hprof", true)

`# Inspect`
${OC:?} exec -i "$(${OC:?} get pods|egrep ston-[1-9]|cut -f1 -d' ')" -- sh -c 'cd /usr/local/vertx/houston-storage-file && ls -Ahl'

true `# Get made heap dump` \
  && if test ! -d heapDump; then echo "Dir heapDump missing"; false ;fi \
  && echo create checksum. \
  && ${OC:?} exec -i "$(${OC:?} get pods|egrep ston-[1-9]|cut -f1 -d' ')" -- sh -c 'cd /usr/local/vertx/houston-storage-file && md5sum -b houston-*.hprof >> MD5SUM-$(date -u +%Y%m%d-%H%M%SZ)' \
  && echo checksum done. Begin dload. \
  && ${OC:?} exec -i "$(${OC:?} get pods|egrep ston-[1-9]|cut -f1 -d' ')" -- sh -c 'cd /usr/local/vertx/houston-storage-file && tar c houston-*.hprof MD5SUM*' | (cd heapDump && tar x) \
  && echo dload done \
  && true