2013年7月5日 星期五

collection : queue (standard)


Data Queue  is a particular kind of abstract data type or collection. This makes the queue a First-in-First-Out (FIFO) data structure.

python queue socket example

MCAST_ADDR1 = '10.0.0.1';MCAST_PORT1 = 1;
MCAST_ADDR2 = '10.0.0.2';MCAST_PORT2 = 1;
try:
        sock.bind((MCAST_ADDR1, MCAST_PORT1))
except socket.error as e:
        print('[ERROR] Cannot bind address: ', HOST, e)
s = struct.pack("=4sl", socket.inet_aton(MCAST_ADDR2), socket.INADDR_ANY)
status=sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, s)
data= sock.recv(1024)
packetQueue.put(data)            











2013年7月4日 星期四

mysql view memory

mysql view memory cache tunning 

show variables;
show status;
SHOW STATUS LIKE "qcache%"
可以查詢到以下的值:

Qcache_free_blocks:空的快取記憶體破碎區塊
Qcache_free_memory:目前剩餘快取記憶體空間
Qcache_hits:快取記憶體重複查詢率
Qcache_inserts:快取記憶體存放過的查詢總數
Qcache_lowmem_prunes:快取記憶體不足警示次數
Qcache_not_cached:沒有放入快取記憶體的查詢數
Qcache_queries_in_cache:目前在快取記憶體內的查詢數
Qcache_total_blocks:快取記憶體區塊總數

如果 Qcache_lowmem_prunes 的值過大(最好是保持為0)
表示該部MySQL的 query_cache_size 容量過小
MySQL 5.1 使用 my-huge.ini 的設定時,query_cache_size 已經設定為32M
基本上個人使用是很足夠,但在一些服務需要用到大量查詢時,就顯得不足
此時可以試著將 query_cache_size 調大一點(我是調到128M啦~)
但也要注意伺服器是否有充足的記憶體可供MySQL使用。
另外,當 Qcache_free_blocks 的數量過大時,表示快取記憶體破碎區塊過多
這會浪費可用的快取記憶體空間,則可以使用以下指令:FLUSH QUERY CACHE




information from : http://chibakuma.com/blog/?p=174

Javascript 5 ways to call a function

Javascript 5 ways to call a function



  1. function make Array(arg1,arg2)
    {return [this, arg1,arg2]}
    e.g. makeArray('one','two');
    global Function call
  2. alter(typeof window.makeArray); = function
    window.makeArray('One','Two'); [window, 'one','two'] 


jsp utf-8

jsp -utf8 jsp utf-8

<%@ page contentType="text/html;" charset="utf-8" %>

jsp if ... else if ... else

<% if (Type.equals("Template")) { %>  Something  <% } %>   


javascript table add row

Javascript table add row (table add line, grid add row, grid add line html table add line)


the following is New Row -> New Column -> New Text

var table = document.getElementByID("tableName");
var lastRow =  table.rows.length;
var newRow = table.insertRow(-1);
var newColumn = newRow.insertCell(0);  // 0 to number of columns
var newText = document.createElement('input');
newText.style.cssText='width:30em';
newColumn.appendChild(NewText);
newColumn.height='20';

Remark

Remark (standard)

LanguageLineBlock
Html<!-- --><!--                        -->
JavaScript///*                             */
CSS/*           *//*                             */
JSP<%--  --%><%--                      --%>
PHP#
MySQL#
python#"""............................"""

2013年7月3日 星期三

Linux view monitor (cpu memory disk network lan net status)


view cpu
sar
sar - q
mpstat -P ALL 1 1000 # view multi cpu
mpstat 1 10000
ps
top , and then press 1

view memory

cat /proc/meminfo | less
free -u
sar -r
vmstat 5 5
ps
top


view disk
iostat
sar-d
vmstat


view net 


route -n;
nmap -sT 127.0.0.1  ## view open port 
netstat -tlunp ## view connect ; 
netstat -tl ## view listen ; traceroute; nslookup -q=mx domain.com 
netstat -tlnp | grep dovecot ; 

tcpdump -i eth0 -nn host 20.0.0.243 ; 
tcpdump host 20.0.0.244


netstat -i
bwm-ng

sar
tcpdump

dig@8.8.8.8 www.domainName.com ## view dbs
eth tool eth0
iwconfig
ifconfig eth0
mii -tool -u eth0 
lsof -i -n | egrep ## command | listen
arping 20.0.0.111 ## find mac from ip
arp ## list lan ip# abd Mac #


Network Monitor

iptraf

yum install iptraf ## view lan traffic  ## iptraf
apt-get install ntop
iptraf ;


ntop

yum install ntop -yabc123

ntop
i.e. : http:// ipnumber:3000
http://hongkong2000.no-ip.org:3000/

run ntop in background

#nohup ntop > /dev/null 2>&1 &
#kill PID <- it is ntop PID


linux background 
1. nohup means: Do not terminate this process even when the stty is cut off.
2. > /dev/null means: stdout goes to /dev/null (which is a dummy device that does not record any output).
3. 2>&1 means: stderr also goes to the stdout (which is already redirected to /dev/null). You may replace &1 with a file path to keep a log of errors, e.g.: 2>/tmp/myLog
4. & at the end means: run this command as a background task.















ftop

yum install ftop -y
ftop