Skip to content

Instantly share code, notes, and snippets.

@valyala
valyala / README.md
Last active Jun 11, 2021
Optimizing postgresql table for more than 100K inserts per second
View README.md

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 / crc32.js
Created Mar 29, 2012
Javascript Functions
View crc32.js
/*
===============================================================================
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
View functions.vim
" 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 Mar 26, 2012
Nginx Configs
View dev.conf
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 Jul 3, 2011
Shell scripts(Ubuntu)
View gist:1062232
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