Github user samarthjain commented on a diff in the pull request:
https://github.com/apache/phoenix/pull/89#discussion_r32846666
--- Diff:
phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WorkloadExecutor.java
---
@@ -19,95 +19,92 @@
package org.apache.phoenix.pherf.workload;
import org.apache.phoenix.pherf.PherfConstants;
-import org.apache.phoenix.pherf.PherfConstants.RunMode;
-import org.apache.phoenix.pherf.configuration.XMLConfigParser;
-import org.apache.phoenix.pherf.jmx.MonitorManager;
-import org.apache.phoenix.pherf.loaddata.DataLoader;
-
-import org.apache.phoenix.pherf.util.ResourceList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Properties;
+import java.util.*;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
public class WorkloadExecutor {
private static final Logger logger =
LoggerFactory.getLogger(WorkloadExecutor.class);
- private final XMLConfigParser parser;
- private MonitorManager monitor;
- private Future monitorThread;
private final int poolSize;
+ private final Map<Workload, Future> jobs = new HashMap<>();
private final ExecutorService pool;
-
public WorkloadExecutor() throws Exception {
this(PherfConstants.create().getProperties(PherfConstants.PHERF_PROPERTIES));
}
- public WorkloadExecutor(Properties properties) throws Exception{
- this(properties,PherfConstants.DEFAULT_FILE_PATTERN);
+ public WorkloadExecutor(Properties properties) throws Exception {
+ this(properties, new ArrayList());
}
- public WorkloadExecutor(Properties properties, String filePattern)
throws Exception {
- this(properties,
- new XMLConfigParser(filePattern),
- true);
+ public WorkloadExecutor(Properties properties, List<Workload>
workloads) throws Exception {
+ this.poolSize =
+ (properties.getProperty("pherf.default.threadpool") ==
null) ?
+ PherfConstants.DEFAULT_THREAD_POOL_SIZE :
+
Integer.parseInt(properties.getProperty("pherf.default.threadpool"));
+
+ this.pool = Executors.newFixedThreadPool(this.poolSize);
+ init(workloads);
}
- public WorkloadExecutor(Properties properties, XMLConfigParser parser,
boolean monitor) throws Exception {
- this.parser = parser;
- this.poolSize =
(properties.getProperty("pherf.default.threadpool") == null)
- ? PherfConstants.DEFAULT_THREAD_POOL_SIZE
- :
Integer.parseInt(properties.getProperty("pherf.default.threadpool"));
+ public void add(Workload workload) throws Exception {
+ this.jobs.put(workload, pool.submit(workload.execute()));
+ }
- this.pool = Executors.newFixedThreadPool(this.poolSize);
- if (monitor) {
-
initMonitor(Integer.parseInt(properties.getProperty("pherf.default.monitorFrequency")));
+ /**
+ * Blocks on waiting for all workloads to finish. If a
+ * {@link org.apache.phoenix.pherf.workload.Workload} Requires
complete() to be called, it must
+ * be called prior to using this method. Otherwise it will block
infinitely.
+ */
+ public synchronized void get() {
--- End diff --
The synchronization is probably not needed here unless member variable
"jobs" is being modified concurrently. In that case you want to have
synchronization everywhere "jobs" is accessed (both read and modified) (for ex
- complete() ). It would be also good to add a @GuardedBy("this") annotation
for "jobs".
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---