Skip to content

Instantly share code, notes, and snippets.

View yangg's full-sized avatar

Brook yangg

  • ShenZhen, China
View GitHub Profile
@valyala
valyala / README.md
Last active April 18, 2024 13:51
Optimizing postgresql table for more than 100K inserts per second

Optimizing postgresql table for more than 100K inserts per second

  • Create UNLOGGED table. This reduces the amount of data written to persistent storage by up to 2x.
  • Set WITH (autovacuum_enabled=false) on the table. This saves CPU time and IO bandwidth on useless vacuuming of the table (since we never DELETE or UPDATE the table).
  • Insert rows with COPY FROM STDIN. This is the fastest possible approach to insert rows into table.
  • Minimize the number of indexes in the table, since they slow down inserts. Usually an index on time timestamp with time zone is enough.
  • Add synchronous_commit = off to postgresql.conf.
  • Use table inheritance for fast removal of old data:
@yangg
yangg / README.mkd
Created March 29, 2012 09:53
Emacs Scripts
@yangg
yangg / crc32.js
Created March 29, 2012 09:55
Javascript Functions
/*
===============================================================================
Crc32 is a JavaScript function for computing the CRC32 of a string
...............................................................................
Version: 1.2 - 2006/11 - http://noteslog.com/category/javascript/
-------------------------------------------------------------------------------
Copyright (c) 2006 Andrea Ercolino
http://www.opensource.org/licenses/mit-license.php
@yangg
yangg / functions.vim
Created March 29, 2012 09:29
Vim Scripts
" auto reload nginx & apache
function! Reload()
let output = system(&ft == 'nginx' ? 'service nginx configtest && service nginx reload' : 'service apache2 reload')
if v:shell_error
echohl WarningMsg | echo output
endif
endfunction
autocmd! BufWritePost */nginx*conf,*/apache*conf call Reload()
@yangg
yangg / dev.conf
Created March 26, 2012 05:29
Nginx Configs
server {
root /home/brook/Public/$host;
location / {
# default_server
if (!-d /home/brook/Public/$host) {
proxy_pass http://localhost;
break;
}
@yangg
yangg / gist:1062232
Created July 3, 2011 13:41
Shell scripts(Ubuntu)
Mint
# screenlets
# Show bandwidth use oneliner
while true; do cat /proc/net/dev; sleep 1; done | awk -v dc="date \"+%T\"" '/eth0/{i = $2 - oi; o = $10 - oo; oi = $2; oo = $10; dc|getline d; close(dc); if (a++) printf "%s %8.2f KiB/s in %8.2f KiB/s out\n", d, i/1024, o/1024}'
# limit the cpu usage of a process
sudo cpulimit -p pid -l 50
# ubuntu root