Recently, when talking to a company that creates consumer electronics, an interesting idea popped up. This company is really struggling in minimizing their electricity bill and I was asked if GridGain could help. Interestingly enough, GridGain can help. Let's suppose you have two data centers, A and B, and data center A has low electricity costs between 12am and 12pm and data center B has low costs between 12pm and 12am. All you need to do to make sure that either data center is used during low cost time window is create GridLowElectricityTopologySpi as follows:
@GridSpiInfo(author = "Your Name", version = "1.0")
@GridSpiMultipleInstancesSupport(true)
public class GridLowElectricityTopologySpi
extends GridSpiAdapter
implements GridTopologySpi {
/** Auto-inject logger. */
@GridLoggerResource
private GridLogger log = null;
/**
* Start SPI.
*/
public void spiStart(String gridName) {
if (log.isInfoEnabled() == true) {
log.info(startInfo());
}
}
/**
* Stop SPI.
*/
public void spiStop() {
if (log.isInfoEnabled() == true) {
log.info(stopInfo());
}
}
/**
* Given whole grid topology return only nodes
* selected for execution of this task.
*/
public Collection<GridNode> getTopology(
GridTaskSession ses,
Collection<GridNode> grid) {
int hour = Calendar.getInstance(Calendar.HOUR_OF_DAY);
List<GridNode> top = new ArrayList<GridNode>(grid.size());
for (GridNode node : grid) {
String segment = node.getAttribute("segment");
if (hour <= 12) {
if (segment.equals("A")) {
top.add(node);
}
}
else if (segment.equals("B")) {
top.add(node);
}
}
return top;
}
}
Now, the nodes from data center A need to have the following in their configuration (the configuration for data center B is analogous).
<bean
id="grid.cfg"
class="org.gridgain.grid.GridConfigurationAdapter"
scope="singleton">
...
<property name="userAttributes">
<map>
<entry key="segment" value="A"/>
</map>
</property>
...
</bean>
This is all that needs to be done to lower your electric bill. Now all tasks will be routed to the data center with lowest electricity cost.
Enjoy!






