瀏覽單個文章
chlang
Master Member
 
chlang的大頭照
 

加入日期: Dec 2001
文章: 1,747
引用:
作者TRG-pro
2000% 的資料量=重複率又變成20了?怎麼變來變去?

舉個500%資料量的例子,

資料首先會先打散成 100 份. (假設1% 作一個切割)

然後儲存在 500 台電腦中. (每台儲存 1%, 全部總共有 500% 的資料量)

因此是 500個1%的來源。只要其中有10台不開機,順利完檔的機率有多少?


這個20倍/5倍的假設是可以調整的.
你覺得現在需要針對這個作討論嗎 ?

其次, 根據不同的上線機器數量, 而完檔率的假設,
這邊有個模擬程式, 是針對不同機器數量以及資料內容 作假設, 麻煩你參考.

http://forum.dodopie.com/viewthread.php?tid=2387

程式碼片段: (模擬單一台電腦的容量/上下線狀態)
代碼:

        public class Node
        {
                int nodeNo;
                boolean active=false;
                int nextActiveTime=0; // minute;
                ArrayList <String>pieces=new ArrayList<String>();
                int curActiveTime=0; // how many minute I left;
                Random r = new Random();
                int nodeSpeed=2; // mb/Min
                
                
                StaticsSimulator staticx=null;
                public Node(StaticsSimulator x)
                {
                        staticx=x;
                        this.nodeSpeed = x.nodeSpeed;
                }
                
                /**
                 * initialize my active time/status
                 */
                public void init() {
                        nextActiveTime = r.nextInt(avgSleepTime);
                }

                public ArrayList<String> getPieces()
                {
                        return pieces;
                }
                
                public void tick()
                {
                        nextActiveTime-=1;
                        curActiveTime-=1;
                        updateStatus();
                        if (active && pieces.size()<1)
                                System.out.println("What ?! I am empty:" + pieces.size());
                        
                }
                
                public void updateStatus()
                {
                        double rx = r.nextDouble();
                        if (rx<staticx.nodeCrashRate)
                        {
                                forceDeActiveX();
                                if (active)
                                        forceDeActive();
                                // node crashed.
                                pieces.clear();
                                staticx.failNodeCnt++;
                                active=false;
                                calcNextActive();
                                return;
                        }
                                
                        if (curActiveTime==0){
                                active=false;
                                forceDeActive();
                        }else
                        if (nextActiveTime==0){
                                forceActive();
                        }
                        
                        if (active)
                        {
                                // check my pieces. purge too onLineHealth pieces
                                // get less healthy pieces from other peer.
                                for (int i=0; i< nodeSpeed;i++)
                                {
                                        String myMostHealthPiece = "";
                                        if (pieces.size() >=nodeCapability){
                                                myMostHealthPiece=getMyMostHealthPiece();
                                                
                                                // don't do anything if my piece is too unhealthy.
                                                PieceHealth ph = totalPieces.get(myMostHealthPiece);
                                                if (ph.getGlobalHealth()<=1){
                                                        myMostHealthPiece="";
                                                        continue;
                                                }
                                                
                                        }
                                        String leastHealthPiece=staticx.getLeastHealthPiece(pieces);
                                        
        
                                        if (leastHealthPiece!=null && leastHealthPiece.length()>0){
                                                if (myMostHealthPiece!=""){
                                                        if (pieces.size()>=nodeCapability){
                                                                pieces.remove(myMostHealthPiece);
                                                                staticx.unRegPiece(myMostHealthPiece);
                                                                staticx.delPiece(myMostHealthPiece);
                                                        }
                                                }
                                                pieces.add(leastHealthPiece);
                                                staticx.regPiece(leastHealthPiece);
                                                staticx.addPiece(leastHealthPiece);
                                                
                                        }else
                                        {
                                                System.out.println("XD. no Least Health Piece exists ?");
                                        }
                                }
                                
                        }
                }
                
                /**
                 * 
                 * @return
                 */
                private String getMyMostHealthPiece() {
                        String ret="";
                        int health=-1;
                        for (String x:pieces)
                        {
                                PieceHealth ph=staticx.totalPieces.get(x);
                                if (ph.getOnLineHealth()>health)
                                {
                                        ret = x;
                                        health=ph.getOnLineHealth();
                                }
                        }
                        return ret;
                }

                
                private void forceDeActiveX()
                {
                        for (String i:pieces)
                        {
                                staticx.delPiece(i);
                        }
                }
                
                private void forceDeActive() {
                        for (String i:pieces)
                        {
                                staticx.unRegPiece(i);
                        }
                }
                


                /**
                 * 
                 * @param pieceNo
                 * @return -1 = no removal.
                 */
                public String addPiece(String pieceNo)
                {
                        String removed="";
                        if (pieces.size()>= nodeCapability)
                        {
                                removed=pieces.remove(0);
                        }
                        pieces.add(pieceNo);
                        
                        return removed;
                }
                
                public void forceActive()
                {
                        active=true;
                        calcNextActive();
                        calcCurActive();
                        // register my pieces
                        for (String i:pieces)
                        {
                                staticx.regPiece(i);
                        }
                }
                
                public void calcNextActive()
                {
                        
                        while (nextActiveTime <=0){
                                double d=r.nextGaussian();
                                nextActiveTime = avgSleepTime + (int)(d*avgSleepTime/4);
                        }
                }
                
                public void calcCurActive()
                {
                        double d=r.nextGaussian();
                        curActiveTime = activeDuration + (int)(d*activeDuration/4);
                }
                
                public boolean isActive()
                {
                        return active;
                }
                
                @Override
                public String toString()
                {
                        StringBuffer sb = new StringBuffer();
                        sb.append("Active:" + active);
                        sb.append("\nPieces:");
                        for (String pie:pieces)
                        {
                                sb.append(pie + "\t");
                        }
                        sb.append("\n");
                        return sb.toString();
                }
        }
 
舊 2009-03-04, 02:39 AM #42
回應時引用此文章
chlang離線中