레이블이 profile인 게시물을 표시합니다. 모든 게시물 표시
레이블이 profile인 게시물을 표시합니다. 모든 게시물 표시

nvm slow start

# zsh 시작이 오래 걸리는 문제가 있다.
# zprof(bulitin) 모듈을 추가해 zsh 시작을 프로파일링 해보자.
# ~/.zshrc 첫번째 라인
zmodload zsh/zprof
# ~/.zshrc 마지막 라인
zprof

# 이제 zsh 를 시작하면 다음과 같이 처리시간이 큰 커맨드를 확인할 수 있다. 
zsh
num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)    1        1413.91  1413.91   93.77%    532.48   532.48   35.31%  nvm_auto
 2)    2         881.44   440.72   58.45%    468.15   234.08   31.05%  nvm
 3)    1         349.74   349.74   23.19%    309.31   309.31   20.51%  nvm_ensure_version_installed
 4)    1          63.34    63.34    4.20%     49.80    49.80    3.30%  nvm_die_on_prefix
 5)    5          92.76    18.55    6.15%     41.40     8.28    2.75%  pmodload
 6)    1          40.43    40.43    2.68%     40.43    40.43    2.68%  nvm_is_version_installed
 7)    1          15.33    15.33    1.02%     15.33    15.33    1.02%  compinit
 8)    1          13.19    13.19    0.87%     13.19    13.19    0.87%  nvm_grep
 9)    1           9.20     9.20    0.61%      9.00     9.00    0.60%  _zsh_highlight_load_highlighters
10)    2           7.27     3.63    0.48%      7.27     3.63    0.48%  promptinit
11)    2          11.93     5.97    0.79%      6.86     3.43    0.45%  prompt_sorin_ysoftman_setup

# nvm.sh 의 nvm_auto(), nvm(), nvm_ensure_versin_installed() 이 오래걸린다는걸 알 수 있다.
# --no-use 를 옵션을 사용해 로딩하면 nvm 명령은 사용할 수 있지만 새로운 쉘 시작시 항상 system node 가 되어
# 특정 node 버전이 필요한 경우 nvm use v{버전} 으로 변경해야 하는 수고가 있다.
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" --no-use

# 관련해서 이슈가 있고 nvm lazy 로딩등을 얘기하는데 아직 정식으로 해결되진 않았다.

python profiling tool py-spy

# py-spy 를 사용하면 파이썬 실행을 쉽게 프로파일링 해준다.

# python 실행이 끝아면 프로파일링 결과(.svg)가 브라우저로 열린다.
sudo py-spy record -o profile.svg -- python ysoftman.py

# top 은 function 의 처리시간 비율을 실시간으로 보여준다.
sudo py-spy top -- python ysoftman.py

golang chi 사용시 높은 CPU 사용율

# golang chi 웹프레임워크 기반 웹서버 성능 테스트를 했다.
# 참고로 jplot 까지 보려면 iterm2(tmux 사용하지 않고)에서 실행해야 한다.
echo 'GET https://localhost/version' | \
vegeta attack -rate=2000/1s -workers=100 -duration 60s --insecure | vegeta encode | \
jaggr @count=rps \
      hist\[100,200,300,400,500\]:code \
      p25,p50,p95:latency \
      sum:bytes_in \
      sum:bytes_out | \
jplot rps+code.hist.100+code.hist.200+code.hist.300+code.hist.400+code.hist.500 \
      latency.p95+latency.p50+latency.p25 \
      bytes_in.sum+bytes_out.sum

# 아주 간단한 정보 요청에 대해 너무 많은 CPU 가 사용되고 있었다.

# 특이한 점은 content-type: application/json 헤더를 설정한 api에서 발생한다.

# 스트레스 테스트 돌리는 중에 30초동안 프로파일링 덤프 받고
curl -k 'https://localhost/debug/pprof/profile?seconds=30' -o z.out 
# 로컬 브라우저로 띄워 보기
go tool pprof -http=:9999 z.out
# view -> top 을 보면 compress 부분이 보인다.

# 코드에 보니 다음과 같이 chi middleware compress 를 사용한다.
import "github.com/go-chi/chi/middleware"
... 생략 ...
r := chi.NewRouter()
r.Use(middleware.DefaultCompress)

# middleware.DefaultCompress 를 활성화하면 json 과 같은 몇몇 디폴트 content-type 에 대해 압축을 시도하게 되고 이때 많은 CPU 를 사용한다.
w.Header().Set("Content-Type", application/json; charset=UTF-8) 

# middleware.DefaultCompress 제거후 cpu 사용률이 1/4 이상 줄었다.

vim slow loading

# 언제부터인가 vim 으로 파일 열기가 아주 오래 걸린다.
# 불과 수십MB 정도 파일 오픈이 완료되기까지 수십초가 걸린다.
# 물론 설정된 .vimrc 를 지우면 빠르다.

# 테스트 파일 40MB 정도의 바이너라파일 다운로드
curl -o aws-iam-authenticator https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-01-05/bin/darwin/amd64/aws-iam-authenticator

# 파일을 열때 zzz.log 파일에 각 단계별 소요 시간 측정
vim --startuptime zzz.log aws-iam-authenticator

# 측정 결과 파일을 열어 보자.
vi zzz.log 
# 시간은 ms 단위로 각 라인은 다음 2가지 포맷 중 하나로 표시된다.
# clock   self+sourced   self:  sourced script
# clock   elapsed:              other lineskj
... 생략 ...
517.709  001.802  001.361: sourcing /Users/ysoftman/.vim/plugged/lightline.vim/autoload/lightline/colorscheme/one.vim
30908.522  000.736  000.736: sourcing /Users/ysoftman/.vim/plugged/ctrlp.vim/autoload/ctrlp/utils.vim
30920.392  30422.338: BufEnter autocommands
30920.397  000.005: editing files in windows
... 생략 ...

# BufEnter autocommand 단계가 30초가 넘는다(30422.338)
# 이 부분은 파일을 버퍼로 읽은 후 파일 타입에 맞는 셋팅들이 자동으로 실행되는 부분이다.
# 확인해보면 다수의 플러그인이 실행된다.
:autocmd BufEnter
--- Autocommands ---
filetypedetect  BufEnter
    *.xpm     if getline(1) =~ "XPM2" |   setf xpm2 | else |   setf xpm | endif
    *.xpm2    setf xpm2
NERDTree  BufEnter
    NERD_tree_*
              stopinsert
NERDTreeHijackNetrw  BufEnter
    *         call nerdtree#checkForBrowse(expand("<amatch>"))
NERDCommenter  BufEnter
    *         :call s:SetUpForNewFiletype(&filetype, 0)

... 생략 ...

vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
fugitive_status  BufEnter
    index     call s:ReloadWinStatus()
    index.lock
              call s:ReloadWinStatus()
fugitive_merge  BufEnter
    *         if exists('s:rebase_continue') |   exe s:MergeRebase('rebase', 0, '', [getfsize(fugitive#Find('.git/rebase-merge
/git-rebase-todo', s:rebase_continue)) > 0 ? '--continue' : '--abort'], remove(s:, 'rebase_continue')) | endif
Colorizer  BufEnter
    *         silent call colorizer#ColorHighlight(1)
youcompleteme  BufEnter
    *         call s:OnBufferEnter()
              call s:UpdateMatches()
TagbarAutoCmds  BufEnter
    *         if expand('<amatch>') !~ '__Tagbar__.*' |     let s:last_alt_bufnr = bufnr('#') | endif
              call s:AutoUpdate(fnamemodify(expand('<afile>'), ':p'), 0)


# 위에 나온 플러그인들을 .vimrc 에서 주석 처리하며 파일 오픈 해본 결과
# 다음 플러그인을 비활성화(주석처리)하면 빠르다.
# #123 처럼 #로 시작하면 컬러값을 표시해주는 플러그인으로 역시 전체 파일에서 해당 부분을 찾아 처리하는게 느린것 같다.
# 꼭 필요한 기능은 아니니 주석처리 하자.
"Plug 'lilydjwg/colorizer'

프로필 이미지

프로필에 사용하는 이미지들...
slayers - xelloss


naruto - naruto uzumaki vs sasuke uchiha


Linux 경로(PATH) 설정하기

# 자주 사용하는 실행파일이 있는 경로를 미리 설정해 두면 어디서나 실행가능하여 편하다.
# bash 를 사용한다면 다음과 같이 원하는 경로를 추가해 주자.
# 참고로 전체 사용자에게 공통으로 적용하려면 /etc/profile 에 추가한다.
vi ~/.bashrc 또는 vi ~/.bash_profile
ysoftman_path=/home1/ysoftman/a/b/c
PATH=$PATH:$HOME:$ysoftman_path
export PATH

# 저장하고 로그아웃 했다가 다시 로그인 하던가 다시 로딩한다.
source ~/.bashrc 또는 source ~/.bash_profile

# 참고로
# ~/.bashrc, ~/.zshrc 는 
# sudo -s 나 bash script.sh 처럼 id,pw 입력이 없는(비로그인) non-interactive 쉘 시작시 로딩하는 파일이다.

# ~/.profile(sh, bourne shell), ~/.bash_profile, ~/.zprofile 는 
# ssh 처럼 id,pw 입력하는(로그인) interactive 쉘 시작할때 로딩하는 파일이다.
# 보통 ~/.bash_profile 에서
다음과 같이 .bashrc 도 같이 로딩하고 있어 .bashrc 에만 필요한 설정을 한다.
if [ -f ~/.bashrc ]; then
  . ~/.bashrc
fi

#####


# interactive mode 은 tty 에 입력된 사용자 명령을 읽는다.
# 스크립트는 기본 non-interactive 로 실행되고 -i 옵션을 붙일대만 강제로 interactive 모드로 동작한다.
# bash -l : 로그인쉘 /etc/profile > /etc/bashrc > ~/.profile 로딩
# bash -i or bash : interactive 쉘 ~/.bashrc 로딩