Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EM plan and optimizer packages. #163

Merged
merged 5 commits into from
Sep 28, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2015 Seoul National University
*
* 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 at
*
* 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.snu.cay.services.em.optimizer.api;

/**
* Information about a dataType stored at an Evaluator.
*/
public interface DataInfo {

/**
* @return the dataType
*/
String getDataType();

/**
* @return number of units stored with the dataType
*/
int getNumUnits();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2015 Seoul National University
*
* 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 at
*
* 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.snu.cay.services.em.optimizer.api;

import java.util.Collection;

/**
* The current state of an evaluator, represented as a set of input parameters for an optimizer.
*/
public interface EvaluatorParameters {
/**
* @return the evaluator's context ID
*/
String getId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a context id or an evaluator id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should match the IDs passed to the ElasticMemory interface (in short: the context ID). In that interface, we loosely define it as a "identifier of the source evaluator." But, as far as I know, this has to be the Context ID. The Context ID is used in the SimpleEM example.

@jsjason can you confirm that the Context ID is what we need for the ElasticMemory primitives?


/**
* @return information about all data on the evaluator
*/
Collection<DataInfo> getDataInfos();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2015 Seoul National University
*
* 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 at
*
* 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.snu.cay.services.em.optimizer.api;

import edu.snu.cay.services.em.plan.api.Plan;

import java.util.Collection;

/**
* Given the current state of evaluators (as parameters) and available resources (as the number of available
* evaluators), the optimizer generates an optimized plan.
*/
public interface Optimizer {
/**
* @param activeEvaluators all currently active evaluators and their parameters
* @param availableEvaluators the total number of evaluators available for optimization.
* If availableEvaluators < activeEvaluators.size(), the optimized plan must delete evaluators.
* If availableEvaluators > activeEvaluators.size(), the optimized plan may add evaluators.
* @return the optimized plan
*/
Plan optimize(Collection<EvaluatorParameters> activeEvaluators, int availableEvaluators);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (C) 2015 Seoul National University
*
* 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 at
*
* 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.
*/
/**
* An optimizer that takes the current state of evaluators (as parameters) and available resources
* (as the number of available evaluators), and generates a plan {@link edu.snu.cay.services.em.plan.api}.
*/
package edu.snu.cay.services.em.optimizer.api;
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2015 Seoul National University
*
* 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 at
*
* 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.snu.cay.services.em.optimizer.impl;

import edu.snu.cay.services.em.optimizer.api.DataInfo;

/**
* A plain-old-data implementation of DataInfo.
*/
public final class DataInfoImpl implements DataInfo {
private final String dataType;
private final int numUnits;

public DataInfoImpl(final String dataType, final int numUnits) {
this.dataType = dataType;
this.numUnits = numUnits;
}

@Override
public String getDataType() {
return dataType;
}

@Override
public int getNumUnits() {
return numUnits;
}

@Override
public String toString() {
return "DataInfoImpl{" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringBuilder

"dataType='" + dataType + '\'' +
", numUnits=" + numUnits +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2015 Seoul National University
*
* 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 at
*
* 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.snu.cay.services.em.optimizer.impl;

import edu.snu.cay.services.em.optimizer.api.DataInfo;
import edu.snu.cay.services.em.optimizer.api.EvaluatorParameters;

import java.util.Collection;

/**
* A plain-old-data implementation of EvaluatorParameters.
*/
public final class EvaluatorParametersImpl implements EvaluatorParameters {
private final String id;
private final Collection<DataInfo> dataInfos;

public EvaluatorParametersImpl(final String id, final Collection<DataInfo> dataInfos) {
this.id = id;
this.dataInfos = dataInfos;
}

@Override
public String getId() {
return id;
}

@Override
public Collection<DataInfo> getDataInfos() {
return dataInfos;
}
}
Loading