This project has retired. For details please refer to its Attic page.
GlobalStats xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.giraph.graph;
20  
21  import java.io.DataInput;
22  import java.io.DataOutput;
23  import java.io.IOException;
24  
25  import org.apache.giraph.bsp.checkpoints.CheckpointStatus;
26  import org.apache.giraph.partition.PartitionStats;
27  import org.apache.hadoop.io.Writable;
28  
29  /**
30   * Aggregated stats by the master.
31   */
32  public class GlobalStats implements Writable {
33    /** All vertices in the application */
34    private long vertexCount = 0;
35    /** All finished vertices in the last superstep */
36    private long finishedVertexCount = 0;
37    /** All edges in the last superstep */
38    private long edgeCount = 0;
39    /** All messages sent in the last superstep */
40    private long messageCount = 0;
41    /** All message bytes sent in the last superstep */
42    private long messageBytesCount = 0;
43    /** Whether the computation should be halted */
44    private boolean haltComputation = false;
45    /** Bytes of data stored to disk in the last superstep */
46    private long oocStoreBytesCount = 0;
47    /** Bytes of data loaded to disk in the last superstep */
48    private long oocLoadBytesCount = 0;
49    /** Lowest percentage of graph in memory throughout the execution */
50    private int lowestGraphPercentageInMemory = 100;
51    /**
52     * Master's decision on whether we should checkpoint and
53     * what to do next.
54     */
55    private CheckpointStatus checkpointStatus =
56        CheckpointStatus.NONE;
57  
58    /**
59     * Add the stats of a partition to the global stats.
60     *
61     * @param partitionStats Partition stats to be added.
62     */
63    public void addPartitionStats(PartitionStats partitionStats) {
64      this.vertexCount += partitionStats.getVertexCount();
65      this.finishedVertexCount += partitionStats.getFinishedVertexCount();
66      this.edgeCount += partitionStats.getEdgeCount();
67    }
68  
69    public long getVertexCount() {
70      return vertexCount;
71    }
72  
73    public long getFinishedVertexCount() {
74      return finishedVertexCount;
75    }
76  
77    public long getEdgeCount() {
78      return edgeCount;
79    }
80  
81    public long getMessageCount() {
82      return messageCount;
83    }
84  
85    public long getMessageBytesCount() {
86      return messageBytesCount;
87    }
88  
89    public boolean getHaltComputation() {
90      return haltComputation;
91    }
92  
93    public void setHaltComputation(boolean value) {
94      haltComputation = value;
95    }
96  
97    public long getOocStoreBytesCount() {
98      return oocStoreBytesCount;
99    }
100 
101   public long getOocLoadBytesCount() {
102     return oocLoadBytesCount;
103   }
104 
105   public CheckpointStatus getCheckpointStatus() {
106     return checkpointStatus;
107   }
108 
109   public void setCheckpointStatus(CheckpointStatus checkpointStatus) {
110     this.checkpointStatus = checkpointStatus;
111   }
112 
113   public int getLowestGraphPercentageInMemory() {
114     return lowestGraphPercentageInMemory;
115   }
116 
117   public void setLowestGraphPercentageInMemory(
118       int lowestGraphPercentageInMemory) {
119     this.lowestGraphPercentageInMemory = lowestGraphPercentageInMemory;
120   }
121 
122   /**
123    * Add bytes loaded to the global stats.
124    *
125    * @param oocLoadBytesCount number of bytes to be added
126    */
127   public void addOocLoadBytesCount(long oocLoadBytesCount) {
128     this.oocLoadBytesCount += oocLoadBytesCount;
129   }
130 
131   /**
132    * Add bytes stored to the global stats.
133    *
134    * @param oocStoreBytesCount number of bytes to be added
135    */
136   public void addOocStoreBytesCount(long oocStoreBytesCount) {
137     this.oocStoreBytesCount += oocStoreBytesCount;
138   }
139 
140   /**
141    * Add messages to the global stats.
142    *
143    * @param messageCount Number of messages to be added.
144    */
145   public void addMessageCount(long messageCount) {
146     this.messageCount += messageCount;
147   }
148 
149   /**
150    * Add messages to the global stats.
151    *
152    * @param msgBytesCount Number of message bytes to be added.
153    */
154   public void addMessageBytesCount(long msgBytesCount) {
155     this.messageBytesCount += msgBytesCount;
156   }
157 
158   @Override
159   public void readFields(DataInput input) throws IOException {
160     vertexCount = input.readLong();
161     finishedVertexCount = input.readLong();
162     edgeCount = input.readLong();
163     messageCount = input.readLong();
164     messageBytesCount = input.readLong();
165     oocLoadBytesCount = input.readLong();
166     oocStoreBytesCount = input.readLong();
167     lowestGraphPercentageInMemory = input.readInt();
168     haltComputation = input.readBoolean();
169     if (input.readBoolean()) {
170       checkpointStatus = CheckpointStatus.values()[input.readInt()];
171     } else {
172       checkpointStatus = null;
173     }
174   }
175 
176   @Override
177   public void write(DataOutput output) throws IOException {
178     output.writeLong(vertexCount);
179     output.writeLong(finishedVertexCount);
180     output.writeLong(edgeCount);
181     output.writeLong(messageCount);
182     output.writeLong(messageBytesCount);
183     output.writeLong(oocLoadBytesCount);
184     output.writeLong(oocStoreBytesCount);
185     output.writeInt(lowestGraphPercentageInMemory);
186     output.writeBoolean(haltComputation);
187     output.writeBoolean(checkpointStatus != null);
188     if (checkpointStatus != null) {
189       output.writeInt(checkpointStatus.ordinal());
190     }
191   }
192 
193   @Override
194   public String toString() {
195     return "(vtx=" + vertexCount + ",finVtx=" +
196         finishedVertexCount + ",edges=" + edgeCount + ",msgCount=" +
197         messageCount + ",msgBytesCount=" +
198           messageBytesCount + ",haltComputation=" + haltComputation +
199         ", checkpointStatus=" + checkpointStatus + ')';
200   }
201 }