add APT for retrieving slave counters
diff --git a/hyracks/hyracks-client/src/main/java/edu/uci/ics/hyracks/client/stats/Counters.java b/hyracks/hyracks-client/src/main/java/edu/uci/ics/hyracks/client/stats/Counters.java
index 7a75b2a..da30e20 100644
--- a/hyracks/hyracks-client/src/main/java/edu/uci/ics/hyracks/client/stats/Counters.java
+++ b/hyracks/hyracks-client/src/main/java/edu/uci/ics/hyracks/client/stats/Counters.java
@@ -16,6 +16,8 @@
package edu.uci.ics.hyracks.client.stats;
public class Counters {
+ public static final String NUM_PROCESSOR = "num-processors";
+
public static final String SYSTEM_LOAD = "system-load-averages";
public static final String MEMORY_USAGE = "heap-used-sizes";
diff --git a/hyracks/hyracks-client/src/main/java/edu/uci/ics/hyracks/client/stats/IClusterCounterContext.java b/hyracks/hyracks-client/src/main/java/edu/uci/ics/hyracks/client/stats/IClusterCounterContext.java
new file mode 100644
index 0000000..356ef34
--- /dev/null
+++ b/hyracks/hyracks-client/src/main/java/edu/uci/ics/hyracks/client/stats/IClusterCounterContext.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package edu.uci.ics.hyracks.client.stats;
+
+import edu.uci.ics.hyracks.api.job.profiling.counters.ICounter;
+import edu.uci.ics.hyracks.api.job.profiling.counters.ICounterContext;
+
+public interface IClusterCounterContext extends ICounterContext {
+
+ public ICounter getCounter(String machineName, String counterName, boolean create);
+
+}
diff --git a/hyracks/hyracks-client/src/main/java/edu/uci/ics/hyracks/client/stats/impl/ClientCounterContext.java b/hyracks/hyracks-client/src/main/java/edu/uci/ics/hyracks/client/stats/impl/ClientCounterContext.java
index cd785a0..46487eb 100644
--- a/hyracks/hyracks-client/src/main/java/edu/uci/ics/hyracks/client/stats/impl/ClientCounterContext.java
+++ b/hyracks/hyracks-client/src/main/java/edu/uci/ics/hyracks/client/stats/impl/ClientCounterContext.java
@@ -29,17 +29,17 @@
import org.json.simple.parser.JSONParser;
import edu.uci.ics.hyracks.api.job.profiling.counters.ICounter;
-import edu.uci.ics.hyracks.api.job.profiling.counters.ICounterContext;
import edu.uci.ics.hyracks.client.stats.AggregateCounter;
import edu.uci.ics.hyracks.client.stats.Counters;
+import edu.uci.ics.hyracks.client.stats.IClusterCounterContext;
import edu.uci.ics.hyracks.control.common.job.profiling.counters.Counter;
/**
* @author yingyib
*/
-public class ClientCounterContext implements ICounterContext {
+public class ClientCounterContext implements IClusterCounterContext {
private static String[] RESET_COUNTERS = { Counters.NETWORK_IO_READ, Counters.NETWORK_IO_WRITE,
- Counters.MEMORY_USAGE, Counters.DISK_READ, Counters.DISK_WRITE };
+ Counters.MEMORY_USAGE, Counters.DISK_READ, Counters.DISK_WRITE, Counters.NUM_PROCESSOR };
private static String[] AGG_COUNTERS = { Counters.SYSTEM_LOAD };
private static int UPDATE_INTERVAL = 10000;
@@ -58,6 +58,14 @@
for (String aggCounterName : AGG_COUNTERS) {
counterMap.put(aggCounterName, new AggregateCounter(aggCounterName));
}
+ for (String slave : slaveMachines) {
+ for (String restCounterName : RESET_COUNTERS) {
+ counterMap.put(slave + "$" + restCounterName, new AggregateCounter(restCounterName));
+ }
+ for (String aggCounterName : AGG_COUNTERS) {
+ counterMap.put(slave + "$" + aggCounterName, new AggregateCounter(aggCounterName));
+ }
+ }
requestCounters();
updateThread.start();
}
@@ -70,6 +78,12 @@
AggregateCounter aggCounter = (AggregateCounter) counterMap.get(aggCounterName);
aggCounter.reset();
}
+ for (String slave : slaveMachines) {
+ for (String aggCounterName : RESET_COUNTERS) {
+ AggregateCounter aggCounter = (AggregateCounter) counterMap.get(slave + "$" + aggCounterName);
+ aggCounter.reset();
+ }
+ }
}
public void resetAll() {
@@ -78,6 +92,12 @@
AggregateCounter aggCounter = (AggregateCounter) counterMap.get(aggCounterName);
aggCounter.reset();
}
+ for (String slave : slaveMachines) {
+ for (String aggCounterName : AGG_COUNTERS) {
+ AggregateCounter aggCounter = (AggregateCounter) counterMap.get(slave + "$" + aggCounterName);
+ aggCounter.reset();
+ }
+ }
}
@Override
@@ -89,6 +109,16 @@
return counter;
}
+ @Override
+ public ICounter getCounter(String machineName, String counterName, boolean create) {
+ Counter counter = counterMap.get(machineName + "$" + counterName);
+ if (counter == null) {
+ throw new IllegalStateException("request an unknown counter: " + counterName + " on slave machine "
+ + machineName + "!");
+ }
+ return counter;
+ }
+
/**
* request to each slave machine for all the counters
*/
@@ -99,7 +129,10 @@
String slaveProfile = requestProfile(slave);
JSONParser parser = new JSONParser();
JSONObject jo = (JSONObject) parser.parse(slaveProfile);
- updateCounterMap((JSONObject) jo.get("result"));
+ Object counterObject = jo.get("result");
+ if (counterObject instanceof JSONObject) {
+ updateCounterMapWithJSONArray(slave, (JSONObject) counterObject);
+ }
}
} catch (Exception e) {
throw new IllegalStateException(e);
@@ -112,11 +145,32 @@
* @param jo
* the Profile JSON object
*/
- private void updateCounterMap(JSONObject jo) {
+ private void updateCounterMapWithJSONArray(String slave, JSONObject jo) {
for (String counterName : RESET_COUNTERS) {
- JSONArray jArray = (JSONArray) jo.get(counterName);
+ updateCounter(slave, jo, counterName);
+ }
+
+ for (String counterName : AGG_COUNTERS) {
+ updateCounter(slave, jo, counterName);
+ }
+ }
+
+ private void updateCounter(String slave, JSONObject jo, String counterName) {
+ Object counterObject = jo.get(counterName);
+ long counterValue = extractCounterValue(counterObject);
+ // global counter
+ ICounter counter = getCounter(counterName, true);
+ counter.set(counterValue);
+ //local counters
+ ICounter localCounter = getCounter(slave, counterName, true);
+ localCounter.set(counterValue);
+ }
+
+ private long extractCounterValue(Object counterObject) {
+ long counterValue = 0;
+ if (counterObject instanceof JSONArray) {
+ JSONArray jArray = (JSONArray) counterObject;
Object[] values = jArray.toArray();
- long counterValue = 0;
for (Object value : values) {
if (value instanceof Double) {
Double dValue = (Double) value;
@@ -127,9 +181,11 @@
}
}
counterValue /= values.length;
- ICounter counter = getCounter(counterName, true);
- counter.set(counterValue);
+ } else {
+ Long val = (Long) counterObject;
+ counterValue = val.longValue();
}
+ return counterValue;
}
/**
diff --git a/hyracks/hyracks-client/src/test/java/edu/uci/ics/hyracks/client/stats/ClientCounterContextTest.java b/hyracks/hyracks-client/src/test/java/edu/uci/ics/hyracks/client/stats/ClientCounterContextTest.java
index 8394daf..bbf212f 100644
--- a/hyracks/hyracks-client/src/test/java/edu/uci/ics/hyracks/client/stats/ClientCounterContextTest.java
+++ b/hyracks/hyracks-client/src/test/java/edu/uci/ics/hyracks/client/stats/ClientCounterContextTest.java
@@ -34,10 +34,16 @@
wait(20000);
}
String[] counters = { Counters.MEMORY_USAGE, Counters.NETWORK_IO_READ, Counters.NETWORK_IO_WRITE,
- Counters.SYSTEM_LOAD, Counters.DISK_READ, Counters.DISK_WRITE };
+ Counters.SYSTEM_LOAD, Counters.NUM_PROCESSOR, Counters.DISK_READ, Counters.DISK_WRITE };
for (String counterName : counters) {
ICounter counter = ccContext.getCounter(counterName, false);
- System.out.println(counter.get());
+ System.out.println(counterName + ": " + counter.get());
+ }
+ for (String slave : ncs) {
+ for (String counterName : counters) {
+ ICounter counter = ccContext.getCounter(slave, counterName, false);
+ System.out.println(slave + " " + counterName + ": " + counter.get());
+ }
}
ccContext.stop();
HyracksUtils.deinit();
diff --git a/pregelix/pregelix-core/src/main/java/edu/uci/ics/pregelix/core/driver/Driver.java b/pregelix/pregelix-core/src/main/java/edu/uci/ics/pregelix/core/driver/Driver.java
index 4604bc7..b3a90e9 100644
--- a/pregelix/pregelix-core/src/main/java/edu/uci/ics/pregelix/core/driver/Driver.java
+++ b/pregelix/pregelix-core/src/main/java/edu/uci/ics/pregelix/core/driver/Driver.java
@@ -59,8 +59,8 @@
@SuppressWarnings("rawtypes")
public class Driver implements IDriver {
- public static final String[] COUNTERS = { Counters.SYSTEM_LOAD, Counters.MEMORY_USAGE, Counters.DISK_READ,
- Counters.DISK_WRITE, Counters.NETWORK_IO_READ, Counters.NETWORK_IO_WRITE };
+ public static final String[] COUNTERS = { Counters.NUM_PROCESSOR, Counters.SYSTEM_LOAD, Counters.MEMORY_USAGE,
+ Counters.DISK_READ, Counters.DISK_WRITE, Counters.NETWORK_IO_READ, Counters.NETWORK_IO_WRITE };
private static final Log LOG = LogFactory.getLog(Driver.class);
private IHyracksClientConnection hcc;
private Class exampleClass;