This project has retired. For details please refer to its Attic page.
PartitionStats 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  package org.apache.giraph.partition;
19  
20  import java.io.DataInput;
21  import java.io.DataOutput;
22  import java.io.IOException;
23  
24  import org.apache.hadoop.io.Writable;
25  
26  /**
27   * Used to keep track of statistics of every {@link Partition}. Contains no
28   * actual partition data, only the statistics.
29   */
30  public class PartitionStats implements Writable {
31    /** Id of partition to keep stats for */
32    private int partitionId = -1;
33    /** Vertices in this partition */
34    private long vertexCount = 0;
35    /** Finished vertices in this partition */
36    private long finishedVertexCount = 0;
37    /** Edges in this partition */
38    private long edgeCount = 0;
39    /** Messages sent from this partition */
40    private long messagesSentCount = 0;
41    /** Message byetes sent from this partition */
42    private long messageBytesSentCount = 0;
43    /**
44     * How long did compute take on this partition
45     * (excluding time spent in GC) (TODO and waiting on open requests)
46     */
47    private long computeMs;
48    /** Hostname and id of worker owning this partition */
49    private String workerHostnameId;
50  
51    /**
52     * Default constructor for reflection.
53     */
54    public PartitionStats() { }
55  
56    /**
57     * Constructor with the initial stats.
58     *
59     * @param partitionId Partition count.
60     * @param vertexCount Vertex count.
61     * @param finishedVertexCount Finished vertex count.
62     * @param edgeCount Edge count.
63     * @param messagesSentCount Number of messages sent
64     * @param messageBytesSentCount Number of message bytes sent
65     * @param workerHostnameId Hostname and id of worker owning this partition
66     */
67    public PartitionStats(int partitionId,
68        long vertexCount,
69        long finishedVertexCount,
70        long edgeCount,
71        long messagesSentCount,
72        long messageBytesSentCount,
73        String workerHostnameId) {
74      this.partitionId = partitionId;
75      this.vertexCount = vertexCount;
76      this.finishedVertexCount = finishedVertexCount;
77      this.edgeCount = edgeCount;
78      this.messagesSentCount = messagesSentCount;
79      this.messageBytesSentCount = messageBytesSentCount;
80      this.workerHostnameId = workerHostnameId;
81    }
82  
83    /**
84     * Set the partition id.
85     *
86     * @param partitionId New partition id.
87     */
88    public void setPartitionId(int partitionId) {
89      this.partitionId = partitionId;
90    }
91  
92    /**
93     * Get partition id.
94     *
95     * @return Partition id.
96     */
97    public int getPartitionId() {
98      return partitionId;
99    }
100 
101   /**
102    * Increment the vertex count by one.
103    */
104   public void incrVertexCount() {
105     ++vertexCount;
106   }
107 
108   /**
109    * Get the vertex count.
110    *
111    * @return Vertex count.
112    */
113   public long getVertexCount() {
114     return vertexCount;
115   }
116 
117   /**
118    * Increment the finished vertex count by one.
119    */
120   public void incrFinishedVertexCount() {
121     ++finishedVertexCount;
122   }
123 
124   /**
125    * Get the finished vertex count.
126    *
127    * @return Finished vertex count.
128    */
129   public long getFinishedVertexCount() {
130     return finishedVertexCount;
131   }
132 
133   /**
134    * Add edges to the edge count.
135    *
136    * @param edgeCount Number of edges to add.
137    */
138   public void addEdgeCount(long edgeCount) {
139     this.edgeCount += edgeCount;
140   }
141 
142   /**
143    * Get the edge count.
144    *
145    * @return Edge count.
146    */
147   public long getEdgeCount() {
148     return edgeCount;
149   }
150 
151   /**
152    * Add messages to the messages sent count.
153    *
154    * @param messagesSentCount Number of messages to add.
155    */
156   public void addMessagesSentCount(long messagesSentCount) {
157     this.messagesSentCount += messagesSentCount;
158   }
159 
160   /**
161    * Get the messages sent count.
162    *
163    * @return Messages sent count.
164    */
165   public long getMessagesSentCount() {
166     return messagesSentCount;
167   }
168 
169   /**
170    * Add message bytes to messageBytesSentCount.
171    *
172    * @param messageBytesSentCount Number of message bytes to add.
173    */
174   public void addMessageBytesSentCount(long messageBytesSentCount) {
175     this.messageBytesSentCount += messageBytesSentCount;
176   }
177 
178   /**
179    * Get the message bytes sent count.
180    *
181    * @return Message bytes sent count.
182    */
183   public long getMessageBytesSentCount() {
184     return messageBytesSentCount;
185   }
186 
187   public long getComputeMs() {
188     return computeMs;
189   }
190 
191   public void setComputeMs(long computeMs) {
192     this.computeMs = computeMs;
193   }
194 
195   public String getWorkerHostnameId() {
196     return workerHostnameId;
197   }
198 
199   @Override
200   public void readFields(DataInput input) throws IOException {
201     partitionId = input.readInt();
202     vertexCount = input.readLong();
203     finishedVertexCount = input.readLong();
204     edgeCount = input.readLong();
205     messagesSentCount = input.readLong();
206     messageBytesSentCount = input.readLong();
207     computeMs = input.readLong();
208     workerHostnameId = input.readUTF();
209   }
210 
211   @Override
212   public void write(DataOutput output) throws IOException {
213     output.writeInt(partitionId);
214     output.writeLong(vertexCount);
215     output.writeLong(finishedVertexCount);
216     output.writeLong(edgeCount);
217     output.writeLong(messagesSentCount);
218     output.writeLong(messageBytesSentCount);
219     output.writeLong(computeMs);
220     output.writeUTF(workerHostnameId);
221   }
222 
223   @Override
224   public String toString() {
225     return "(id=" + partitionId + ",vtx=" + vertexCount + ",finVtx=" +
226         finishedVertexCount + ",edges=" + edgeCount + ",msgsSent=" +
227         messagesSentCount + ",msgBytesSent=" +
228         messageBytesSentCount + ",computeMs=" + computeMs +
229         ")";
230   }
231 }