MYSQL篇
新增如果unique索引字段重复,则更新;
insert into mg_user(key,key2,key3)value(‘value‘,‘value2‘,‘value3‘) on duplicate key update key=value,key2=value2,key3=value3
show global variables;
if(!mysql_real_connect(&logdb, my_hostname, my_user, my_password, my_dbname, my_port, my_sock, 0)){ //mysql长连接
ast_log(LOG_ERROR, "Failed to connect to mysql database %s on %s.\n", my_dbname, my_hostname);
use_mysql = 0;
} else {
char value = 1;
mysql_options(&logdb, MYSQL_OPT_RECONNECT, (char*)&value);
use_mysql = 1;
}
NGINX篇
例如,NGINX对一个没有长连接支持的后端机器,会出现大量TIME_WAIT 状态的连接,使用以下命令验证之:
netstat -n | grep TIME_WAIT
1. 启用到 memcache 服务器的长连接
在upstream 配置段中增加 keepalive N 指令即可:
upstream memcached_backend {
server 127.0.0.1:11211;
server 10.0.0.2:11211;
keepalive 32;
}
server {
...
location /memcached/ {
set $memcached_key $uri;
memcached_pass memcached_backend;
}
}
2. 启用fastcgi 长连接支持
除了需要在upstream 中配置 keepalive N 外,还需要在 location 中增加 fastcgi_keep_conn on;
upstream fastcgi_backend {
server 127.0.0.1:9000;
keepalive 8;
}
server {
...
location /fastcgi/ {
fastcgi_pass fastcgi_backend;
fastcgi_keep_conn on;
...
}
}
3. 启用对后端机器HTTP 长连接支持
upstream http_backend {
server 127.0.0.1:8080;
keepalive 16;
}
server {
location /http/ {
proxy_pass http://http_backend;
proxy_http_version 1.1;
proxy_set_header Connection "";
...
}
}
http://blog.itpub.net/29754888/viewspace-1406479/