??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲国产精品久久久久婷婷老年,精品人妻伦九区久久AAA片69,国产三级精品久久http://www.shnenglu.com/fwxjj/archive/2014/08/31/208188.html大龙大龙Sun, 31 Aug 2014 06:59:00 GMThttp://www.shnenglu.com/fwxjj/archive/2014/08/31/208188.htmlhttp://www.shnenglu.com/fwxjj/comments/208188.htmlhttp://www.shnenglu.com/fwxjj/archive/2014/08/31/208188.html#Feedback0http://www.shnenglu.com/fwxjj/comments/commentRss/208188.htmlhttp://www.shnenglu.com/fwxjj/services/trackbacks/208188.html用String的hashcode得到intcd作ؓ主键。其实hashcode重复的可能性超大,下面是java的缺省算法:
 public int hashCode() {
    
int h = hash;
    
if (h == 0{
        
int off = offset;
        
char val[] = value;
        
int len = count;

            
for (int i = 0; i < len; i++{
                h 
= 31*+ val[off++];
            }

            hash 
= h;
        }

        
return h;
    }
但是什么情况下会重复?下面是测试代?




import java.util.HashMap;

public class Test {

    
static HashMap map = new HashMap();

    
private static char startChar = 'A';

    
private static char endChar = 'z';

    
private static int offset = endChar - startChar + 1;

    
private static int dup = 0;

    
public static void main(String[] args) {
        
int len = 3;
        
char[] chars = new char[len];
        tryBit(chars, len);
        System.
out.println((int)Math.pow(offset, len) + ":" + dup);
    }


    
private static void tryBit(char[] chars, int i) {
        
for (char j = startChar; j <= endChar; j++{
            chars[i 
- 1= j;
            
if (i > 1)
                tryBit(chars, i 
- 1);
            
else
                test(chars);
        }

    }


    
private static void test(char[] chars) {

        String str 
= new String(chars).replaceAll("[^a-zA-Z_]""").toUpperCase();// 195112:0
        
//String str = new String(chars).toLowerCase();//195112:6612
        
//String str = new String(chars).replaceAll("[^a-zA-Z_]","");//195112:122500
        
//String str = new String(chars);//195112:138510
        int hash = str.hashCode();
        
if (map.containsKey(hash)) {
            String s 
= (String) map.get(hash);
            
if (!s.equals(str)) {
                dup
++;
                System.
out.println(s + ":" + str);
            }

        }
 else {
            map.put(hash, str);
            
// System.out.println(str);
        }

    }

}


在A-z范围内有Ҏ字符Q从l果看,仅仅3位长度的字符Ԍ
不处理: 138510ơ重?
L字母意外字符Q 122500ơ重?
所有字W{写Q?612ơ重?了很多Q?
L字母意外字符Qƈ且{写Q没有重复!4位字W串也没见重?

不难看出Q?
1. ~省实现文字母优?
2. 字母大小写可能导致重?

可能Q?
长字W串可能hashcode重复
中文字符串和Ҏ字符可能hashcode重复

注:׃?006q的事,所以上面得出的数据有误。可自己q行试。hash冲突ơ数大大减少?/span>


大龙 2014-08-31 14:59 发表评论
]]>
TCP/IP协议选项——TCP_KEEPALIVEhttp://www.shnenglu.com/fwxjj/archive/2014/08/18/208055.html大龙大龙Mon, 18 Aug 2014 09:41:00 GMThttp://www.shnenglu.com/fwxjj/archive/2014/08/18/208055.htmlhttp://www.shnenglu.com/fwxjj/comments/208055.htmlhttp://www.shnenglu.com/fwxjj/archive/2014/08/18/208055.html#Feedback0http://www.shnenglu.com/fwxjj/comments/commentRss/208055.htmlhttp://www.shnenglu.com/fwxjj/services/trackbacks/208055.html1、KEEPALIVE作用

KEEPALIVE机制Q是TCP协议规定的TCP层(非应用层业务代码实现的)TCP本端到对方主机的TCPq接的连通性的行ؓ。避免服务器在客L出现各种不良状况时无法感知,而永q等在这条TCPq接上?/p>

2、KEEPALIVE代码CZ

该选项可以讄q个行为的l节Q如下代码所C:

  1. int keepAlive = 1;    // ?|开启keepalive属?  
  2. int keepIdle = 60;    // 如该q接?0U内没有M数据往?则进行此TCP层的探测   
  3. int keepInterval = 5; // 探测发包间隔?U?  
  4. int keepCount = 3;        // 试探测的次?如果W?ơ探包收到响应了,则后2ơ的不再?  
  5. setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (void *)&keepAlive, sizeof(keepAlive));  
  6. setsockopt(sockfd, SOL_TCP, TCP_KEEPIDLE, (void*)&keepIdle, sizeof(keepIdle));  
  7. setsockopt(sockfd, SOL_TCP, TCP_KEEPINTVL, (void *)&keepInterval, sizeof(keepInterval));  
  8. setsockopt(sockfd, SOL_TCP, TCP_KEEPCNT, (void *)&keepCount, sizeof(keepCount));  

讄该选项后,如果60U内在此套接口所对应q接的Q一方向都没有数据交换,TCP层就自动l对方发一个保zL分?keepalive probe)。这是一个对方必d应的TCP分节。它会导致以下三U情况:
    Ҏ接收一切正常:以期望的ACK响应?0U后QTCP重新开始下一轮探?br />    Ҏ已崩溃且已重新启动:以RST响应。套接口的待处理错误被置为ECONNRESET?br />    Ҏ无Q何响应:比如客户端那边已l断|,或者客L直接L。以讑֮的时间间隔尝?ơ,无响应就攑ּ。套接口的待处理错误被置为ETIMEOUT?/p>

3、KEEPALIVE脚本讄

全局讄可更?etc/sysctl.conf,加上:
net.ipv4.tcp_keepalive_intvl = 5
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_time = 60
在程序中表现为:
d模型下,当TCP层检到对端socket不再可用Ӟ内核无法d通知应用层出错,只有应用层主动调用read()或者write()q样的IOpȝ调用Ӟ内核才会利用出错来通知应用层?br />非阻塞模型下Qselect或者epoll会返回sockfd可读,应用层对其进行读取时Qread()会报错?/p>


一点经验:
实际上我们在做服务器E序的时候,对客L的保zL基本上不依赖于q个TCP层的keepalive探测机制?br />而是我们自己做一套应用层的请求应{消息,在应用层实现q样一个功能?/p>

大龙 2014-08-18 17:41 发表评论
]]>
haproxy+keepalived实现高可用负载均?/title><link>http://www.shnenglu.com/fwxjj/archive/2014/08/15/208027.html</link><dc:creator>大龙</dc:creator><author>大龙</author><pubDate>Fri, 15 Aug 2014 08:15:00 GMT</pubDate><guid>http://www.shnenglu.com/fwxjj/archive/2014/08/15/208027.html</guid><wfw:comment>http://www.shnenglu.com/fwxjj/comments/208027.html</wfw:comment><comments>http://www.shnenglu.com/fwxjj/archive/2014/08/15/208027.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/fwxjj/comments/commentRss/208027.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/fwxjj/services/trackbacks/208027.html</trackback:ping><description><![CDATA[     摘要: 软g负蝲均衡一般通过两种方式来实玎ͼZ操作pȝ的Y负蝲实现和基于第三方应用的Y负蝲实现。LVS是ZLinux操作pȝ实现的一UY负蝲QHAProxy是开源的q且ZW三应用实现的Y负蝲。HAProxy相比LVS的用要单很多,功能斚w也很丰富。当 前,HAProxy支持两种主要的代理模?"tcp"也即4层(大多用于邮g服务器、内部协议通信服务器等Q,?层(HTTPQ。在4层模?下,...  <a href='http://www.shnenglu.com/fwxjj/archive/2014/08/15/208027.html'>阅读全文</a><img src ="http://www.shnenglu.com/fwxjj/aggbug/208027.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/fwxjj/" target="_blank">大龙</a> 2014-08-15 16:15 <a href="http://www.shnenglu.com/fwxjj/archive/2014/08/15/208027.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HAProxy负蝲均衡器的安装及配|?/title><link>http://www.shnenglu.com/fwxjj/archive/2014/08/15/208026.html</link><dc:creator>大龙</dc:creator><author>大龙</author><pubDate>Fri, 15 Aug 2014 07:52:00 GMT</pubDate><guid>http://www.shnenglu.com/fwxjj/archive/2014/08/15/208026.html</guid><wfw:comment>http://www.shnenglu.com/fwxjj/comments/208026.html</wfw:comment><comments>http://www.shnenglu.com/fwxjj/archive/2014/08/15/208026.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/fwxjj/comments/commentRss/208026.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/fwxjj/services/trackbacks/208026.html</trackback:ping><description><![CDATA[<div bgf8f8f8"="" style="background-color: #f8f8f8; width: 597px; padding-top: 12px; padding-right: 18px; padding-left: 18px; margin-top: 10px; border-top-color: #d8d9d9; border-right-color: #d8d9d9; border-left-color: #d8d9d9; border-top-width: 1px; border-right-width: 1px; border-left-width: 1px; border-style: solid solid none; color: #333333; font-family: 宋体; font-size: 12px; line-height: 18px;"><div style="background-color: #ffffff; border: 1px dashed #73a0cf; line-height: 26px; padding: 8px 12px; background-position: initial initial; background-repeat: initial initial;"><p green"="" style="margin: 0px; padding: 0px; color: #006600; background-color: transparent; font-size: 14px;">软g负蝲均衡一般通过两种方式来实玎ͼZ操作pȝ的Y负蝲实现和基于第三方应用的Y负蝲实现。LVS是ZLinux操作pȝ实现的一UY负蝲QHAProxy是开源的q且ZW三应用实现的Y负蝲?/p><p style="margin: 0px; padding: 0px; background-color: transparent;">ADQ?/p></div></div><div bgf8f8f8="" f14"="" style="background-color: #f8f8f8; padding-top: 12px; padding-right: 18px; padding-left: 18px; line-height: 28px; margin-bottom: 10px; position: relative; min-height: 500px; overflow: hidden; color: #333333; font-family: 宋体;"><div class="gqkeyes" id="content"><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;"></p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">?1CTO.com 独家特稿】Y件负载均衡一般通过两种方式来实玎ͼZ操作pȝ的Y负蝲实现和基于第三方应用的Y负蝲实现。LVS是ZLinux操作pȝ实现的一UY负蝲QHAProxy是开源的q且ZW三应用实现的Y负蝲?/p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">HAProxy相比LVS的用要单很多,功能斚w也很丰富。当 前,HAProxy支持两种主要的代理模?"tcp"也即4层(大多用于邮g服务器、内部协议通信服务器等Q,?层(HTTPQ。在4层模?下,<strong><a target="_blank" style="color: #004276;">HAProxy</a></strong>仅在客户端和服务器之间{发双向流量?层模式下QHAProxy会分析协议,q且能通过允许、拒l、交换、增加、修Ҏ者删除请?(request)或者回?response)里指定内Ҏ控制协议Q这U操作要Z特定规则?/p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">我现在用HAProxy主要在于它有以下优点Q这里我ȝ下:</p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;"><strong>一?/strong>免费开源,E_性也是非常好Q这个可通过我做的一些小目可以看出来,单Haproxy也跑得不错,E_性可以与LVS相媲;</p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;"><strong>二?/strong>Ҏ官方文档QHAProxy可以跑满10Gbps-New benchmark of HAProxy at 10 Gbps using Myricom's 10GbE NICs (Myri-10G PCI-Express)Q这个作Y件负蝲均衡Q也是比较惊人的Q?/p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;"><strong>三?/strong>HAProxy可以作ؓMySQL、邮件或其它的非web?strong>负蝲均衡</strong>Q我们常用于它作为MySQL(?负蝲均衡Q?/p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;"><strong>四?/strong>自带强大的监控服务器状态的面Q实际环境中我们l合Nagiosq行邮g或短信报警,q个也是我非常喜Ƣ它的原因之一Q?/p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;"><strong>五?/strong>HAProxy支持虚拟L?/p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">实验环境也很单:</p><pre style="margin-top: 0px; padding: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 591.015625px; overflow: auto; background-color: #e6e6e6;">HAProxy  IP:192.168.4.192 Centos5.5-64bit<br style="clear: both; width: 0px; height: 0px;" />Web1 IP:192.168.4.45 Centos5.4-64bit<br style="clear: both; width: 0px; height: 0px;" />Web2 IP:192.168.21.45 FreeBSD8.0-64bit</pre><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">具体安装及配|文档如下:</p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">一、HAProxy的下载及安装q程Q?/p><pre style="margin-top: 0px; padding: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 591.015625px; overflow: auto; background-color: #e6e6e6;">wget <span style="color: #0000ff;">http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.20.tar.gz<br style="clear: both; width: 0px; height: 0px;" /></span>make TARGET=linux26 prefix=/usr/local/haproxy install<br style="clear: both; width: 0px; height: 0px;" />cd /usr/local/haproxy<br style="clear: both; width: 0px; height: 0px;" />mkdir conf<br style="clear: both; width: 0px; height: 0px;" />cd conf<br style="clear: both; width: 0px; height: 0px;" />vim haproxy.conf</pre><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">内容 如下Q?/p><pre style="margin-top: 0px; padding: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 591.015625px; overflow: auto; background-color: #e6e6e6;"><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">global<br style="clear: both; width: 0px; height: 0px;" />        log 127.0.0.1   local0<br style="clear: both; width: 0px; height: 0px;" />        maxconn 4096<br style="clear: both; width: 0px; height: 0px;" />        chroot /usr/local/haproxy<br style="clear: both; width: 0px; height: 0px;" />        uid 501<br style="clear: both; width: 0px; height: 0px;" />        gid 501<br style="clear: both; width: 0px; height: 0px;" />        daemon<br style="clear: both; width: 0px; height: 0px;" />        nbproc 1<br style="clear: both; width: 0px; height: 0px;" />        pidfile /usr/local/haproxy/logs/haproxy.pid<br style="clear: both; width: 0px; height: 0px;" />        debug</p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">defaults<br style="clear: both; width: 0px; height: 0px;" />        log     127.0.0.1       local3<br style="clear: both; width: 0px; height: 0px;" />        mode    http<br style="clear: both; width: 0px; height: 0px;" />        option httplog<br style="clear: both; width: 0px; height: 0px;" />        option httpclose<br style="clear: both; width: 0px; height: 0px;" />        option dontlognull<br style="clear: both; width: 0px; height: 0px;" />        option forwardfor<br style="clear: both; width: 0px; height: 0px;" />        option redispatch<br style="clear: both; width: 0px; height: 0px;" />        retries 2<br style="clear: both; width: 0px; height: 0px;" />        maxconn 2000<br style="clear: both; width: 0px; height: 0px;" />        balance roundrobin<br style="clear: both; width: 0px; height: 0px;" />        stats   uri     /haproxy-stats<br style="clear: both; width: 0px; height: 0px;" />        contimeout      5000<br style="clear: both; width: 0px; height: 0px;" />        clitimeout      50000<br style="clear: both; width: 0px; height: 0px;" />        srvtimeout      50000</p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">listen web_proxy 192.168.4.192:80<br style="clear: both; width: 0px; height: 0px;" />        #option httpchk HEAD /index.php  HTTP/1.0<br style="clear: both; width: 0px; height: 0px;" />        server web1_192.168.21.45 192.168.21.45:80 cookie app1inst1 check inter 2000 rise 2 fall 5<br style="clear: both; width: 0px; height: 0px;" />        server web2_192.168.4.45  192.168.4.45:80 cookie app1inst2 check inter 2000 rise 2 fall 5</p></pre><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">配置文g刚从服务器上copy下来的,保证可用。这里有个事情说明一下,有时候我们进入页?span style="color: #0000ff;">http://192.168.4.192/</span>׃报如下错误:</p><pre style="margin-top: 0px; padding: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 591.015625px; overflow: auto; background-color: #e6e6e6;"><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">503 Service UnavailableNo server is available to handle this request.</p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">option httpchk HEAD /check.txt HTTP/1.0</p></pre><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">此问题出在这句话上面Q它的意思是Haproxy会判断你的后端web的根上存在check.txt没有Q以此作为haproxy-status的监控状态依据,它#掉即可;如果是生产环境,你可check.txt改ؓindex.jsp或index.php卛_Q?/p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">另外Q徏议配|一个HAProxy的启动、关闭、重启脚本,攑֜/etc/init.d下,我们在^时的工作中应该养成一个习惯,服务器的启动或重启应该是最单的Q万一C生环境下出错时Q我们可以以最快的方式启动Q如果不用脚本的话,我们p试以如下方式启动:</p><pre style="margin-top: 0px; padding: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 591.015625px; overflow: auto; background-color: #e6e6e6;">/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg</pre><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">以下脚本生成后,我们直接可以?etc/init.d/haproxy  start来启动HAProxy服务了?/p><pre style="margin-top: 0px; padding: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 591.015625px; overflow: auto; background-color: #e6e6e6;"><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">#!/bin/bash<br style="clear: both; width: 0px; height: 0px;" />BASE_DIR="/usr/local/haproxy"<br style="clear: both; width: 0px; height: 0px;" />ARGV="$@"</p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">start()<br style="clear: both; width: 0px; height: 0px;" />{<br style="clear: both; width: 0px; height: 0px;" />echo "START HAPoxy SERVERS"<br style="clear: both; width: 0px; height: 0px;" />$BASE_DIR/sbin/haproxy -f $BASE_DIR/conf/haproxy.cfg<br style="clear: both; width: 0px; height: 0px;" />}</p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">stop()<br style="clear: both; width: 0px; height: 0px;" />{<br style="clear: both; width: 0px; height: 0px;" />echo "STOP HAPoxy Listen"<br style="clear: both; width: 0px; height: 0px;" />kill -TTOU $(cat $BASE_DIR/logs/haproxy.pid)<br style="clear: both; width: 0px; height: 0px;" />echo "STOP HAPoxy process"<br style="clear: both; width: 0px; height: 0px;" />kill -USR1 $(cat $BASE_DIR/logs/haproxy.pid)<br style="clear: both; width: 0px; height: 0px;" />}<br style="clear: both; width: 0px; height: 0px;" />case $ARGV in</p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">start)<br style="clear: both; width: 0px; height: 0px;" />start<br style="clear: both; width: 0px; height: 0px;" />ERROR=$?<br style="clear: both; width: 0px; height: 0px;" />;;</p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">stop)<br style="clear: both; width: 0px; height: 0px;" />stop<br style="clear: both; width: 0px; height: 0px;" />ERROR=$?<br style="clear: both; width: 0px; height: 0px;" />;;</p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">restart)<br style="clear: both; width: 0px; height: 0px;" />stop<br style="clear: both; width: 0px; height: 0px;" />start<br style="clear: both; width: 0px; height: 0px;" />ERROR=$?<br style="clear: both; width: 0px; height: 0px;" />;;</p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">*)<br style="clear: both; width: 0px; height: 0px;" />echo "hactl.sh [start|restart|stop]"<br style="clear: both; width: 0px; height: 0px;" />esac<br style="clear: both; width: 0px; height: 0px;" />exit $ERROR</p></pre><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">我们在Firefox或IE上输?span style="color: #0000ff;">http://192.168.4.192</span>  可以轮询的看到后端的web的页面了Q另外我们可以随时监控页?span style="color: #0000ff;">http://192.168.4.192/haproxy-status/</span>Q效果图如下Q?/p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;"><a target="_blank" style="color: #004276;"><img border="0" alt="效果? width="498" height="184" src="http://images.51cto.com/files/uploadimg/20110317/0939540.jpg" style="border: 0px;" /></a></p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">另外Q如果要做HAProxy的高可用Q我推荐用HAProxy+KeepalivedQ网上成功的安例也有许多Q大家可以googel学习下,如果你对此篇文章有疑问或其它Q希望通过我在51cto的博客与我交?a style="color: #004276;">http://andrewyu.blog.51cto.com</a>(抚琴煮酒)?/p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">?1CTO.com独家特稿Q非l授权谢l{载!合作媒体转蝲h明原文出处及出处Q?/p><div align="right">【责ȝ辑:<a href="mailto:tongyw@51cto.com" style="color: #004276; text-decoration: none;">佟媛?/a> TELQ(010Q?8476606?/div></div></div><img src ="http://www.shnenglu.com/fwxjj/aggbug/208026.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/fwxjj/" target="_blank">大龙</a> 2014-08-15 15:52 <a href="http://www.shnenglu.com/fwxjj/archive/2014/08/15/208026.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>python fabric实现q程操作和部|?-- ?/title><link>http://www.shnenglu.com/fwxjj/archive/2014/06/02/207174.html</link><dc:creator>大龙</dc:creator><author>大龙</author><pubDate>Mon, 02 Jun 2014 03:21:00 GMT</pubDate><guid>http://www.shnenglu.com/fwxjj/archive/2014/06/02/207174.html</guid><wfw:comment>http://www.shnenglu.com/fwxjj/comments/207174.html</wfw:comment><comments>http://www.shnenglu.com/fwxjj/archive/2014/06/02/207174.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/fwxjj/comments/commentRss/207174.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/fwxjj/services/trackbacks/207174.html</trackback:ping><description><![CDATA[     摘要: fabrictitle是开发,但是同时要干开发测试还有运l的z?(o(╯□╰)o)q期接手来多的东西,发布和运l的工作相当机械Q加上频率还蛮高Q导致时间浪费还是优点多。修复bug什么的Q测试,提交版本?2分钟)Qssh到测试环境pull部vQ?分钟Q,rsync到线上机器A,B,C,D,EQ?分钟Q,分别ssh到ABCDE五台机器Q逐一重启(8-10分钟)...  <a href='http://www.shnenglu.com/fwxjj/archive/2014/06/02/207174.html'>阅读全文</a><img src ="http://www.shnenglu.com/fwxjj/aggbug/207174.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/fwxjj/" target="_blank">大龙</a> 2014-06-02 11:21 <a href="http://www.shnenglu.com/fwxjj/archive/2014/06/02/207174.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【{】PHP有关跨域的请求header("P3P: CP=CURa ADMa...)cookie -session解决Ҏhttp://www.shnenglu.com/fwxjj/archive/2013/12/29/205056.html大龙大龙Sun, 29 Dec 2013 06:23:00 GMThttp://www.shnenglu.com/fwxjj/archive/2013/12/29/205056.htmlhttp://www.shnenglu.com/fwxjj/comments/205056.htmlhttp://www.shnenglu.com/fwxjj/archive/2013/12/29/205056.html#Feedback0http://www.shnenglu.com/fwxjj/comments/commentRss/205056.htmlhttp://www.shnenglu.com/fwxjj/services/trackbacks/205056.html

对于IE来说(默认安全U别?Q?strong>iframe、img、link{标{?/strong>都是只发送session cookieQ又?W一方cookieQ,拦截本地cookie发送(又叫W三方cookieQ。当q些标签跨域引用一个页面,实际上是发v了一ơGETh?/p>

在php文g头部?header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"')

或者加 header("P3P: CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR");
如果q个跨域的请?/strong>QHTTPq回头中带有Set-Cookie Q?那么q个cookieҎ览器来说Q实际上是无效的?br />
看如下测?br />
假设?www.a.com    ?www.b.com 两个?br />
?www.b.com 上有一个页面,其中包含一个指?www.a.com 的iframe

http://www.b.com/test.html 的内容ؓQ?br />----------------------------------------------------------------------

<iframe width=300 height=300 src="http://www.a.com/test.php" ></iframe>

----------------------------------------------------------------------


http://www.a.com/test.php 是一个对 a.com 域设|?cookie的页面,其内容ؓQ?br />----------------------------------------------------------------------

<?php

header("Set-Cookie: test=axis; domain=.a.com; path=/");

?>

<script>
    alert(document.cookie);
</script>

----------------------------------------------------------------------


此时我们h http://www.b.com/test.html , 他包含一个iframeQ会去跨域请?www.a.com/test.php Q该php面会尝?set-cookie

W一ơ请求, test.php ?set-cookieQ所以浏览器会收C个cookie?br />
如果 set-cookie 成功Q再ơ请求该面Q浏览器应该?sent 刚才 recieve 到的cookie。可是由于前面说的跨域限Ӟ在IE里的iframe标签?set-cookie不成功的Q所以无法sent刚才收到的cookie?q里无论?session cookie q是本地cookie都是一栗?/strong>


可以看到Q第二次发包Q还是没能sent出去cookie


但是q种情况在加入了P3P header 后会改变?br />
P3P header允许跨域讉K隐私数据Q从而可以跨域set-cookie成功

我们修改 www.a.com/test.php ?br />----------------------------------------------------------------------

<?php

header("P3P: CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR");

header("Set-Cookie: test=axis; expires=Sun, 23-Dec-2018 08:13:02 GMT; domain=.a.com; path=/");

?>

<script>
    alert(document.cookie);
</script>

----------------------------------------------------------------------

再次讉K两次上面的测试过E?br />
可以看到W二个包已经发送出了收到的cookie

而我们写的javascript也能够弹出cookie了?br />

值得注意的是Q?strong>P3P header只需要设|一?/strong>Q这栯在这个P3P header后面的所?set-cookieQ都可以跨域讉K了。也是? 被P3P header讄q一ơ后Q之后的h不再需要P3P headerQ也能够在iframe里跨域发送这些cookie?/strong>

但是如果?set-cookie L变设|好的cookieQ则不再hq种跨域讉KҎ?br />

P3P header q有一个特点就?strong>同一个包?/strong>只能讄一ơ,后面的P3P Header不会覆盖前面的P3P headerQ浏览器只认W一个?br />
P3P ?The Platform for Privacy Preferences 的简U?br />
更多具体的内容可以参?strong>W3C
的标?http://www.w3.org/TR/P3P/

在这里,我们看到的很q P3P header里的东西Q都不知道是什么ؕ七八p的{略内容Q实际上q是一些简?br />
比如 上面用到?br />
P3P: CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR

CP ?Compact Policy 的简?br />
CURa ?CUR ?<current/> 的简写, a ?always 的简?br />
当然P3P header也可以直?引用一?xml {略文g

比如q么?br />HTTP/1.1 200 OK
P3P: policyref="http://catalog.example.com/P3P/PolicyReferences.xml"
Content-Type: text/html
Content-Length: 7413
Server: CC-Galaxy/1.3.18使用P3P的方法还有很多,q里不一一列D了?br />

最后,利用P3P Header 的这U特性,在实际攻MQ还是可以利用一下的?br />
比如利用CRLF插入一个P3P header后,改变一个本地cookie的|该cookie在之后的q程中可以被iframe引用刎ͼ也许会发生一些很奇妙的事情?br />
具体会变成什么样我也不知道,毕竟web应用安全和环境的关系是越来越紧密了?/div>

大龙 2013-12-29 14:23 发表评论
]]>
提高数据更新效率(UPDATE/INSERT) --- ?/title><link>http://www.shnenglu.com/fwxjj/archive/2013/12/10/204702.html</link><dc:creator>大龙</dc:creator><author>大龙</author><pubDate>Tue, 10 Dec 2013 11:27:00 GMT</pubDate><guid>http://www.shnenglu.com/fwxjj/archive/2013/12/10/204702.html</guid><wfw:comment>http://www.shnenglu.com/fwxjj/comments/204702.html</wfw:comment><comments>http://www.shnenglu.com/fwxjj/archive/2013/12/10/204702.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/fwxjj/comments/commentRss/204702.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/fwxjj/services/trackbacks/204702.html</trackback:ping><description><![CDATA[<div><div class="kcgiigg" id="blog_content"> <p>有多U方法可以提高更新的效率.<br />单说来:<br />Q、暂停烦引,更新后恢?避免在更新的q程中涉及到索引的重?<br />Q、批量更斎ͼ每更C些记录后及时q行提交动作.避免大量占用回滚D和或时表I间.<br />Q、创Z临时的大的表I间用来应对q些更新动作Q?br />=========================================================================不同看法<br />如果UPDATE的是索引字段Q就会涉及到索引的重建,暂停索引不会提高多少的速度Q反而有可能降低UPDATE速度Q?br />因ؓ在更新是索引可以提高数据的查询速度Q重建烦引引L速度降低影响不大?/p> <p>ORACLE优化修改参数最多也只能把性能提高15%Q大部分都是<a target="_self"><span style="text-decoration: underline;"><strong>SQL</strong></span></a>语句的优化!</p> <p><br />=========================================================================不同位置<br />updateM来说比insert要慢  <br />几点Q?nbsp; <br />  1、如果更新的数据量接q整个表Q就不应该用index而应该采用全表扫?nbsp; <br />  2、减不必要的indexQ因为update表通常需要update index  <br />  3、如果你的服务器有多个cpuQ采用parellel hintQ可以大q度的提高效?nbsp; <br />   <br />  前年我也遇到cM的问题,300万纪录的一个表Q每天要全表更新20ơ左叻I最初通过cursor多进E(18个进E)更新Q耗时30分钟Q?br />  后来采用full+parallel   hintQ耗时降低?分钟左右。服务器是ibm   rs6000   s590Q?8个CPUQ?4GB内存?nbsp; <br /> <br />  另外Q徏表的参数非常重要Q对于更新非帔RJ的表,加大PCTFREE的|以保证数据块中有_的空间用于UPDATEQ?br />  从而降低CHAINED_ROWS?nbsp;</p> <p><br />=========================================================================不同位置<br />如果有夠CPU以及I/O 的話....<br />ALTER SESSION ENABLE PARALLEL DML;</p> <p>INSERT /*+ PARALLEL(tableA, 2) */<br />INTO tableA NOLOGGING<br />SELECT * FROM tableB;</p> <p>當中?2 是多個進程同時埯. 可應不同情況加減. </p> <p><br />=========================================================================不同位置<br />2比较可行的方?br />Ҏ一Q用oracle中包含在注释中的提示信息<br />insert /*+append*/ into ...nologing<br />select * from ...</p> <p>Ҏ二:使用扚w拯Ҏ<br />set arraysize 20<br />set copycommit 5000<br />copy from<a href="mailto:username/password@oracle_name">username/password@oracle_name</a>append table_name1<br />using select * from table_name2;</p> <p>实际效果Q方法一要比Ҏ二速度q要快些</p> <p>/*+append */ nologging 的方法不?<br />bulk insert好像需要内容够大才可?</p> <p>=========================================================================不同位置<br />set autocommit 100;----------每一百条记录提交一?br />set transaction use rollback segment RBS1;<br />      INSERT INTO table1 NOLOGGING<br />         SELECT * FROM table2;<br />     commit;</p> <p>改变表的存储{略Q?br />ALTER TABLE aaaa1<br />    PCTFREE 30<br />    PCTUSED 60;<br />---------q两个值相加要于100Q把PCTFREE搞大QPCTUSED搞小Q可能会快一?/p> <p>=========================================================================不同位置<br />再提供一U方法,俺曾l用q的Q?br />alter session set sort_area_size=100000000;<br />insert into tableb select * from tablea;<br />commit;</p> <p><br />=========================================================================ȝ<br />提高更新速度ȝQ?br />Q、暂停烦引,更新后恢?避免在更新的q程中涉及到索引的重?<br />    ~点Q?br />        如果UPDATE的是索引字段Q就会涉及到索引的重建,暂停索引不会提高多少的速度Q反而有可能降低UPDATE速度?br />        如果表比较庞大,停烦引后重键需要花比较长的旉<br />    优点Q?br />        如果更新的数据量接近整个表,此方法比较好?br />       <br />Q、批量更斎ͼ每更C些记录后及时q行提交动作.避免大量占用回滚D和或时表I间.<br />Q、创Z临时的大的表I间用来应对q些更新动作Q?br />Q、如果你的服务器有多个cpuQ采用parellel hintQ可以大q度的提高效?br />    ALTER SESSION ENABLE PARALLEL DML;</p> <p>    INSERT /*+ PARALLEL(tableA, 2) */INTO tableA NOLOGGING<br />       SELECT * FROM tableB;<br />    當中?2 是多個進程同時埯. 可應不同情況加減. </p> <p>Q、徏表的参数非常重要Q对于更新非帔RJ的表,加大PCTFREE的|以保证数据块中有_的空间用于UPDATEQ从而降低CHAINED_ROWS<br />    ALTER TABLE aaaa1<br />       PCTFREE 30<br />       PCTUSED 60;<br />    ---------q两个值相加要于100Q把PCTFREE搞大QPCTUSED搞小Q可能会快一?/p> <p>Q、oracle提示及批量拷?br />    Ҏ一Q用oracle中包含在注释中的提示信息<br />        insert /*+append*/ into ...nologing<br />           select * from ...</p> <p>    Ҏ二:使用扚w拯Ҏ<br />        set arraysize 20<br />        set copycommit 5000<br />        copy from<a href="mailto:username/password@oracle_name">username/password@oracle_name</a>append table_name1<br />        using select * from table_name2;</p> <p>    实际效果Q方法一要比Ҏ二速度q要快些</p> <p>Q、加大排序缓冲区<br />    alter session set sort_area_size=100000000;<br />    insert into tableb select * from tablea;<br />    commit;</p> </div></div><img src ="http://www.shnenglu.com/fwxjj/aggbug/204702.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/fwxjj/" target="_blank">大龙</a> 2013-12-10 19:27 <a href="http://www.shnenglu.com/fwxjj/archive/2013/12/10/204702.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【Android框架q阶?0〗】ThinkAndroid注解机制 --- ?/title><link>http://www.shnenglu.com/fwxjj/archive/2013/12/10/204701.html</link><dc:creator>大龙</dc:creator><author>大龙</author><pubDate>Tue, 10 Dec 2013 11:20:00 GMT</pubDate><guid>http://www.shnenglu.com/fwxjj/archive/2013/12/10/204701.html</guid><wfw:comment>http://www.shnenglu.com/fwxjj/comments/204701.html</wfw:comment><comments>http://www.shnenglu.com/fwxjj/archive/2013/12/10/204701.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/fwxjj/comments/commentRss/204701.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/fwxjj/services/trackbacks/204701.html</trackback:ping><description><![CDATA[<div><p style="color:#362e2b; line-height:25.98958396911621px"><span style="font-weight:bold">׃目需要,开始研IThinkAndroid?/span></p> <p style="color:#362e2b; line-height:25.98958396911621px"><span style="font-weight:bold">个h认ؓ该框架的注解机制十分新颖Q所以先研究q个Q顺便学习下 Java 的annotation?/span></p> <p><strong>_略的看了看Q该机制在BaseActivity中初始化。而BaseActivity是所有Activity的基cR?/strong></p> <p><strong>对BaseActivityq行了代码剖,发现在BaseActivity中在onCreate函数里启动注解机制?/strong></p> <ul><li>首先注入布局资源Q绑定layout布局Q?/li><li>其次注入成员资源Q绑定组件资源)</li><li>然后注入成员变量Q初始化普通变量)</li></ul> <p>暂时先搞清楚W二个,怎么l定lg资源的:</p> <p><strong>我写了个demoQMyAnno</strong></p> <ul><li><img src="http://blog.csdn.net/mkrcpp/article/details/13509051" alt="" /><img src="http://img.blog.csdn.net/20131029160827031" alt="" /></li></ul> <p><strong>InjectView.java</strong></p> <div bg_java"=""><ol start="1"><li><span>package com.myanno;  </span></li><li>  </li><li><span>import java.lang.annotation.ElementType;  </span></li><li><span>import java.lang.annotation.Retention;  </span></li><li><span>import java.lang.annotation.RetentionPolicy;  </span></li><li><span>import java.lang.annotation.Target;  </span></li><li>  </li><li>  </li><li><span>/** </span></li><li><span> * 自定义注解,获取资源ID </span></li><li><span> * @使用Ҏ </span></li><li><span> *              @InjectView(id = R.id.settingIv) </span></li><li><span> *              private ImageView imgSetting;  </span></li><li><span> *  </span></li><li><span> * @author      michael.mao@sosino.com </span></li><li><span> * @date        2013-10-29 </span></li><li><span> * @description @Retention: 定义注解的保留策?nbsp;</span></li><li><span> *              @Retention(RetentionPolicy.SOURCE)  //注解仅存在于源码中,在class字节码文件中不包?nbsp;</span></li><li><span> *              @Retention(RetentionPolicy.CLASS)   //默认的保留策略,注解会在class字节码文件中存在Q但q行时无法获得, </span></li><li><span> *              @Retention(RetentionPolicy.RUNTIME) //注解会在class字节码文件中存在Q在q行时可以通过反射获取?nbsp;</span></li><li><span> *              @Inherited                          //说明子类可以l承父类中的该注?nbsp;</span></li><li><span> * </span></li><li><span> *              @Target(ElementType.TYPE)           //接口、类、枚举、注?nbsp;</span></li><li><span> *              @Target(ElementType.FIELD)          //字段、枚丄帔R </span></li><li><span> *              @Target(ElementType.METHOD)         //Ҏ </span></li><li><span> *              @Target(ElementType.PARAMETER)      //Ҏ参数 </span></li><li><span> *              @Target(ElementType.CONSTRUCTOR)    //构造函?nbsp;</span></li><li><span> *              @Target(ElementType.LOCAL_VARIABLE) //局部变?nbsp;</span></li><li><span> *              @Target(ElementType.ANNOTATION_TYPE)//注解 </span></li><li><span> *              @Target(ElementType.PACKAGE)        //?nbsp;   </span></li><li><span> */  </span></li><li>  </li><li><span>@Target(ElementType.FIELD)  </span></li><li><span>@Retention(RetentionPolicy.RUNTIME)  </span></li><li><span>public @interface InjectView  </span></li><li>{  </li><li>    <span>/** View的ID */  </span></li><li>    <span>public int id() default -1;  </span></li><li>}  </li></ol></div> <br /> <strong>MainActivity.java</strong> <div bg_java"=""><ol start="1"><li><span>package com.myanno;  </span></li><li>  </li><li><span>import java.lang.reflect.Field;  </span></li><li>  </li><li><span>import android.app.Activity;  </span></li><li><span>import android.os.Bundle;  </span></li><li><span>import android.util.Log;  </span></li><li><span>import android.view.View;  </span></li><li><span>import android.widget.ImageView;  </span></li><li><span>import android.widget.TextView;  </span></li><li>  </li><li><span>public class MainActivity extends Activity {  </span></li><li>  </li><li>    <span>/** 注解l定UI元素 */  </span></li><li>    <span>@InjectView(id=R.id.myimgview)  </span></li><li>    ImageView myimageview;  </li><li>      </li><li>    <span>@InjectView(id=R.id.mytext)  </span></li><li>    TextView mytext;  </li><li>  </li><li>    <span>@Override  </span></li><li>    <span>protected void onCreate(Bundle savedInstanceState) {  </span></li><li>        <span>super.onCreate(savedInstanceState);  </span></li><li>        setContentView(R.layout.activity_main);  </li><li>          </li><li>        <span>//初始化注解绑定的成员变量  </span></li><li>        injectView(<span>this);  </span></li><li>          </li><li>        <span>//直接使用UI元素  </span></li><li>        mytext.setText(<span>"Text0");  </span></li><li>        myimageview.setImageResource(R.drawable.junny);  </li><li>    }  </li><li>      </li><li>    <span>/** 实例化@InjectView 注解的成?/  </span></li><li>    <span>public void injectView(Activity activity)  </span></li><li>    {  </li><li>        Field[] fields = activity.getClass().getDeclaredFields();<span>//得到Activity中的所有定义的字段  </span></li><li>        <span>if (fields != null && fields.length > 0)  </span></li><li>        {  </li><li>            <span>for (Field field : fields)  </span></li><li>            {  </li><li>                <span>if (field.isAnnotationPresent(InjectView.class))//Ҏq回trueQ如果指定类型的注解存在于此元素?nbsp; </span></li><li>                {  </li><li>                    Log.i(<span>"Field", field.toString());  </span></li><li>                      </li><li>                    InjectView mInjectView = field.getAnnotation(InjectView.<span>class); //获得该成员的annotation  </span></li><li>                    <span>int viewId = mInjectView.id();  //获得该注解的id  </span></li><li>                    View view=activity.findViewById(viewId);<span>//获得ID为viewID的组件对?nbsp; </span></li><li>                      </li><li>                    Log.i(<span>"Field", String.valueOf(viewId));  </span></li><li>                    Log.i(<span>"Field", view.getClass().toString());  </span></li><li>                      </li><li>                    <span>try  </span></li><li>                    {  </li><li>                        field.setAccessible(<span>true);//讄cȝU有成员变量可以被访?nbsp; </span></li><li>                        field.set(activity, view);<span>//field.set(object,value)===object.fieldValue = value  </span></li><li>                    } <span>catch (Exception e) { e.printStackTrace();}  </span></li><li>                }  </li><li>                <span>else  </span></li><li>                    Log.i(<span>"Field", "该字D|有被注解");  </span></li><li>            }  </li><li>        }  </li><li>    }  </li><li>}  </li></ol></div> <br /> <strong>布局文g activity_main.xml</strong> <div bg_html"=""><ol start="1"><li><span><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  </span></li><li>    <span>xmlns:tools="http://schemas.android.com/tools"  </span></li><li>    <span>android:layout_width="match_parent"  </span></li><li>    <span>android:layout_height="match_parent"  </span></li><li>    <span>android:background="#000000"  </span></li><li>    <span>android:orientation="vertical"  </span></li><li>    <span>tools:ignore="ContentDescription" >  </span></li><li>    <span><ImageView  </span></li><li>        <span>android:id="@+id/myimgview"  </span></li><li>        <span>android:layout_width="wrap_content"  </span></li><li>        <span>android:layout_height="wrap_content"  </span></li><li>        <span>android:layout_gravity="center"/>  </span></li><li>    <span><TextView  </span></li><li>        <span>android:id="@+id/mytext"  </span></li><li>        <span>android:layout_width="match_parent"  </span></li><li>        <span>android:layout_height="0dp"  </span></li><li>        <span>android:layout_weight="1"  </span></li><li>        <span>android:gravity="center"  </span></li><li>        <span>android:background="@android:color/darker_gray"  </span></li><li>        <span>android:textSize="30sp" />  </span></li><li><span></LinearLayout>  </span></li></ol></div> <br /> <strong>实验l果</strong> <ul><li><img src="http://img.blog.csdn.net/20131029160835046" alt="" height="427" width="240" /><br /> </li></ul> <p><span style="color:#009900"><strong>x入成功了</strong></span> <img alt="大笑" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif" /></p> <p><br /> </p> <p>需要说下我遇到的问题,在以上的基础上,如果布局文g里的TextView 和ImageView两个布局换个位置Q这时候再q行下,会出现空指针异常?/p> <p>Log向上M发现一个警?/p> <ul><li><img src="http://blog.csdn.net/mkrcpp/article/details/13509051" alt="" /><img src="http://img.blog.csdn.net/20131029160840859" alt="" /></li></ul> <p>即非?strong><span style="color:#ff0000">参数异常</span></strong></p> <p>定位到这一?/p> <div bg_java"=""><ol start="1"><li><span>field.set(activity, view);  </span></li></ol></div> <br /> 通过观察Log打印的日? <ul><li><img src="http://blog.csdn.net/mkrcpp/article/details/13509051" alt="" /><img src="http://img.blog.csdn.net/20131029160851984" alt="" /></li></ul> <p>发现<strong><u>W一二行</u></strong>是对的,卌得注解的<span style="color:#ff0000"><strong>cd和ID(ImageView 2131230720)</strong></span>都是正确的,但是通过findViewById获取view的时候,Log<strong><u>W三?/u></strong>昄?strong><span style="color:#ff0000">却是TextView?/span></strong></p> <p>百思不得其解,最后无赖之下,清理一下项目,搞定?/p> <p>我不知道是怎么回事Q暂且推ؓ资源~存吧?/p></div><img src ="http://www.shnenglu.com/fwxjj/aggbug/204701.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/fwxjj/" target="_blank">大龙</a> 2013-12-10 19:20 <a href="http://www.shnenglu.com/fwxjj/archive/2013/12/10/204701.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> 提高数据更新效率(UPDATE/INSERT) --- ?/title><link>http://www.shnenglu.com/fwxjj/archive/2013/12/04/204579.html</link><dc:creator>大龙</dc:creator><author>大龙</author><pubDate>Wed, 04 Dec 2013 03:39:00 GMT</pubDate><guid>http://www.shnenglu.com/fwxjj/archive/2013/12/04/204579.html</guid><wfw:comment>http://www.shnenglu.com/fwxjj/comments/204579.html</wfw:comment><comments>http://www.shnenglu.com/fwxjj/archive/2013/12/04/204579.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/fwxjj/comments/commentRss/204579.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/fwxjj/services/trackbacks/204579.html</trackback:ping><description><![CDATA[<div><div class="gkewqym" id="blog_content"> <p>有多U方法可以提高更新的效率.<br />单说来:<br />Q、暂停烦引,更新后恢?避免在更新的q程中涉及到索引的重?<br />Q、批量更斎ͼ每更C些记录后及时q行提交动作.避免大量占用回滚D和或时表I间.<br />Q、创Z临时的大的表I间用来应对q些更新动作Q?br />=========================================================================不同看法<br />如果UPDATE的是索引字段Q就会涉及到索引的重建,暂停索引不会提高多少的速度Q反而有可能降低UPDATE速度Q?br />因ؓ在更新是索引可以提高数据的查询速度Q重建烦引引L速度降低影响不大?/p> <p>ORACLE优化修改参数最多也只能把性能提高15%Q大部分都是<a target="_self"><span style="text-decoration: underline;"><strong>SQL</strong></span></a>语句的优化!</p> <p><br />=========================================================================不同位置<br />updateM来说比insert要慢  <br />几点Q?nbsp; <br />  1、如果更新的数据量接q整个表Q就不应该用index而应该采用全表扫?nbsp; <br />  2、减不必要的indexQ因为update表通常需要update index  <br />  3、如果你的服务器有多个cpuQ采用parellel hintQ可以大q度的提高效?nbsp; <br />   <br />  前年我也遇到cM的问题,300万纪录的一个表Q每天要全表更新20ơ左叻I最初通过cursor多进E(18个进E)更新Q耗时30分钟Q?br />  后来采用full+parallel   hintQ耗时降低?分钟左右。服务器是ibm   rs6000   s590Q?8个CPUQ?4GB内存?nbsp; <br /> <br />  另外Q徏表的参数非常重要Q对于更新非帔RJ的表,加大PCTFREE的|以保证数据块中有_的空间用于UPDATEQ?br />  从而降低CHAINED_ROWS?nbsp;</p> <p><br />=========================================================================不同位置<br />如果有夠CPU以及I/O 的話....<br />ALTER SESSION ENABLE PARALLEL DML;</p> <p>INSERT /*+ PARALLEL(tableA, 2) */<br />INTO tableA NOLOGGING<br />SELECT * FROM tableB;</p> <p>當中?2 是多個進程同時埯. 可應不同情況加減. </p> <p><br />=========================================================================不同位置<br />2比较可行的方?br />Ҏ一Q用oracle中包含在注释中的提示信息<br />insert /*+append*/ into ...nologing<br />select * from ...</p> <p>Ҏ二:使用扚w拯Ҏ<br />set arraysize 20<br />set copycommit 5000<br />copy from<a href="mailto:username/password@oracle_name">username/password@oracle_name</a>append table_name1<br />using select * from table_name2;</p> <p>实际效果Q方法一要比Ҏ二速度q要快些</p> <p>/*+append */ nologging 的方法不?<br />bulk insert好像需要内容够大才可?</p> <p>=========================================================================不同位置<br />set autocommit 100;----------每一百条记录提交一?br />set transaction use rollback segment RBS1;<br />      INSERT INTO table1 NOLOGGING<br />         SELECT * FROM table2;<br />     commit;</p> <p>改变表的存储{略Q?br />ALTER TABLE aaaa1<br />    PCTFREE 30<br />    PCTUSED 60;<br />---------q两个值相加要于100Q把PCTFREE搞大QPCTUSED搞小Q可能会快一?/p> <p>=========================================================================不同位置<br />再提供一U方法,俺曾l用q的Q?br />alter session set sort_area_size=100000000;<br />insert into tableb select * from tablea;<br />commit;</p> <p><br />=========================================================================ȝ<br />提高更新速度ȝQ?br />Q、暂停烦引,更新后恢?避免在更新的q程中涉及到索引的重?<br />    ~点Q?br />        如果UPDATE的是索引字段Q就会涉及到索引的重建,暂停索引不会提高多少的速度Q反而有可能降低UPDATE速度?br />        如果表比较庞大,停烦引后重键需要花比较长的旉<br />    优点Q?br />        如果更新的数据量接近整个表,此方法比较好?br />       <br />Q、批量更斎ͼ每更C些记录后及时q行提交动作.避免大量占用回滚D和或时表I间.<br />Q、创Z临时的大的表I间用来应对q些更新动作Q?br />Q、如果你的服务器有多个cpuQ采用parellel hintQ可以大q度的提高效?br />    ALTER SESSION ENABLE PARALLEL DML;</p> <p>    INSERT /*+ PARALLEL(tableA, 2) */INTO tableA NOLOGGING<br />       SELECT * FROM tableB;<br />    當中?2 是多個進程同時埯. 可應不同情況加減. </p> <p>Q、徏表的参数非常重要Q对于更新非帔RJ的表,加大PCTFREE的|以保证数据块中有_的空间用于UPDATEQ从而降低CHAINED_ROWS<br />    ALTER TABLE aaaa1<br />       PCTFREE 30<br />       PCTUSED 60;<br />    ---------q两个值相加要于100Q把PCTFREE搞大QPCTUSED搞小Q可能会快一?/p> <p>Q、oracle提示及批量拷?br />    Ҏ一Q用oracle中包含在注释中的提示信息<br />        insert /*+append*/ into ...nologing<br />           select * from ...</p> <p>    Ҏ二:使用扚w拯Ҏ<br />        set arraysize 20<br />        set copycommit 5000<br />        copy from<a href="mailto:username/password@oracle_name">username/password@oracle_name</a>append table_name1<br />        using select * from table_name2;</p> <p>    实际效果Q方法一要比Ҏ二速度q要快些</p> <p>Q、加大排序缓冲区<br />    alter session set sort_area_size=100000000;<br />    insert into tableb select * from tablea;<br />    commit;</p> </div></div><img src ="http://www.shnenglu.com/fwxjj/aggbug/204579.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/fwxjj/" target="_blank">大龙</a> 2013-12-04 11:39 <a href="http://www.shnenglu.com/fwxjj/archive/2013/12/04/204579.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>лǵվܻԴȤ</p> <a href="http://www.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.gn-online.com.cn" target="_blank">ŷһþ</a>| <a href="http://www.ovnz.cn" target="_blank">ƷۺϾþõһҳ</a>| <a href="http://www.jianfusi.cn" target="_blank">ҰAVþһ</a>| <a href="http://www.fengdingjun.cn" target="_blank">ľƷþþþ޲</a>| <a href="http://www.888wx.cn" target="_blank">ƷþþþӰ</a>| <a href="http://www.baidudianying.cn" target="_blank">þþþƷþþþþ</a>| <a href="http://www.liangfang013.cn" target="_blank">޹ŷۺϾþ</a>| <a href="http://www.4neq.cn" target="_blank">þ99Ʒ99þ6</a>| <a href="http://www.jiademandu.cn" target="_blank">þۺϸϾþúݺݺ97ɫ69</a>| <a href="http://www.xueyang.net.cn" target="_blank">99Ʒ˾þþô߽</a>| <a href="http://www.dageda168.cn" target="_blank">þþþþþþòҰ߳</a>| <a href="http://www.qiaokuo.cn" target="_blank">Ʒ۲ӰԺþ</a>| <a href="http://www.2046film.cn" target="_blank">þþƷAV뽿ɫ</a>| <a href="http://www.07sn.cn" target="_blank">þþþùһëƬ</a>| <a href="http://www.millions.net.cn" target="_blank">þþþ99ƷƬŷ </a>| <a href="http://www.m28587.cn" target="_blank">.Ʒþþ鶹Ʒ</a>| <a href="http://www.fq2.com.cn" target="_blank">þɫ</a>| <a href="http://www.hbksinukse.cn" target="_blank">99þҹɫƷվ</a>| <a href="http://www.odbeqi.cn" target="_blank">Ůþþùһ</a>| <a href="http://www.yinyue580.cn" target="_blank">һһþaþþƷۺ</a>| <a href="http://www.xueyang.net.cn" target="_blank">˾ھƷþþþ</a>| <a href="http://www.iqwn.cn" target="_blank">þþþAVƬ</a>| <a href="http://www.pbxdt.com.cn" target="_blank">þþþþҹƷ</a>| <a href="http://www.gzfbn.cn" target="_blank">պŷ޹ƷĻþþ</a>| <a href="http://www.cg-blog.cn" target="_blank">һaƬþëƬ</a>| <a href="http://www.huaigutang.cn" target="_blank">ھƷþ޻</a>| <a href="http://www.omaw.cn" target="_blank">޾Ʒþþþþ</a>| <a href="http://www.clg8.cn" target="_blank">ھƷþþӰԺ </a>| <a href="http://www.ppmm163.cn" target="_blank">ŷԴƬxxxxxþþ</a>| <a href="http://www.bleg.cn" target="_blank">91Ʒɫ۾þ</a>| <a href="http://www.iaro.cn" target="_blank">ٸ޾þþþþ4</a>| <a href="http://www.ya74.cn" target="_blank">˾Ʒþ޸岻 ˾Ʒþ޸岻 ˾Ʒþ </a>| <a href="http://www.e3668.cn" target="_blank">996þùƷ߹ۿ</a>| <a href="http://www.mir818.cn" target="_blank">þþƷAV㽶</a>| <a href="http://www.awkmqq.cn" target="_blank">þ޾ƷAVӣ</a>| <a href="http://www.92loc.cn" target="_blank">þþһƷ99þþƷ88</a>| <a href="http://www.ding-u.cn" target="_blank">˾þۺ</a>| <a href="http://www.bailidujuan.cn" target="_blank">˾þþƷӰԺ</a>| <a href="http://www.webidea.com.cn" target="_blank">鶹AV뾫Ʒþ</a>| <a href="http://www.88354.com.cn" target="_blank">þþþþҹƷƷ</a>| <a href="http://www.touzhi8.cn" target="_blank">þ99ƷСѼ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>