Search in sources :

Example 1 with GroupRebalancer

use of edu.snu.mist.core.task.groupaware.rebalancer.GroupRebalancer in project mist by snuspl.

the class EventProcessorManagerTest method setUp.

@Before
public void setUp() throws InjectionException {
    final JavaConfigurationBuilder jcb = Tang.Factory.getTang().newConfigurationBuilder();
    jcb.bindNamedParameter(DefaultNumEventProcessors.class, Integer.toString(DEFAULT_NUM_THREADS));
    jcb.bindNamedParameter(EventProcessorUpperBound.class, Integer.toString(MAX_NUM_THREADS));
    jcb.bindNamedParameter(EventProcessorLowerBound.class, Integer.toString(MIN_NUM_THREADS));
    jcb.bindNamedParameter(GracePeriod.class, Integer.toString(0));
    jcb.bindImplementation(EventProcessorFactory.class, TestEventProcessorFactory.class);
    groupRebalancer = mock(GroupRebalancer.class);
    groupBalancer = new TestGroupAssigner();
    groupIdRequestor = mock(GroupIdRequestor.class);
    taskStatsUpdater = mock(TaskStatsUpdater.class);
    final Injector injector = Tang.Factory.getTang().newInjector(jcb.build());
    injector.bindVolatileInstance(GroupRebalancer.class, groupRebalancer);
    injector.bindVolatileInstance(GroupAssigner.class, groupBalancer);
    injector.bindVolatileInstance(GroupIdRequestor.class, groupIdRequestor);
    injector.bindVolatileInstance(TaskStatsUpdater.class, taskStatsUpdater);
    eventProcessorManager = injector.getInstance(DefaultEventProcessorManager.class);
    groupAllocationTableModifier = injector.getInstance(GroupAllocationTableModifier.class);
}
Also used : GroupRebalancer(edu.snu.mist.core.task.groupaware.rebalancer.GroupRebalancer) Injector(org.apache.reef.tang.Injector) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) Before(org.junit.Before)

Example 2 with GroupRebalancer

use of edu.snu.mist.core.task.groupaware.rebalancer.GroupRebalancer in project mist by snuspl.

the class GroupRebalancerTest method defaultRebalancerTest1.

/**
 * Reassignment.
 * (alpha: 0.85, beta: 0.9, targetload = 0.875)
 * t1: [0.1, 0.05, 0.1, 0.2, 0.1, 0.05, 0.1, 0.2, 0.05] (0.95) overloaded
 * t2: [0.05, 0.05, 0.05, 0.1, 0.2, 0.1, 0.05, 0.1, 0.2, 0.05] (0.95) overloaded
 * t3: [0.1, 0.2, 0.3, 0.2, 0.05] (0.85) normal
 * t4: [0.1, 0.1] (0.2) underloaded
 * t5: [0.1, 0.1, 0.1, 0.1] (0.4) underloaded
 *
 * After rebalancing
 * t1: [0.1,  0.1, 0.2, 0.1, 0.05, 0.1, 0.2, 0.05] (0.9) overloaded
 * t2: [0.05, 0.05, 0.1, 0.2, 0.1, 0.05, 0.1, 0.2, 0.05] (0.9) overloaded
 * t3: [0.1, 0.2, 0.3, 0.2, 0.05] (0.85) normal
 * t4: [0.1, 0.1, 0.05, 0.05] (0.3) underloaded
 * t5: [0.1, 0.1, 0.1, 0.1] (0.4) underloaded
 */
@Test
public void defaultRebalancerTest1() throws InjectionException {
    final JavaConfigurationBuilder jcb = Tang.Factory.getTang().newConfigurationBuilder();
    jcb.bindNamedParameter(DefaultNumEventProcessors.class, "0");
    jcb.bindImplementation(LoadUpdater.class, TestLoadUpdater.class);
    final Injector injector = Tang.Factory.getTang().newInjector(jcb.build());
    final GroupAllocationTable groupAllocationTable = injector.getInstance(GroupAllocationTable.class);
    final GroupRebalancer rebalancer = injector.getInstance(DefaultGroupRebalancerImpl.class);
    final LoadUpdater loadUpdater = injector.getInstance(LoadUpdater.class);
    final EventProcessorFactory epFactory = injector.getInstance(DefaultEventProcessorFactory.class);
    final List<EventProcessor> eventProcessors = new LinkedList<>();
    for (int i = 0; i < 5; i++) {
        eventProcessors.add(epFactory.newEventProcessor());
        groupAllocationTable.put(eventProcessors.get(i));
    }
    final List<Double> loadsForEp1 = Arrays.asList(0.1, 0.05, 0.1, 0.2, 0.1, 0.05, 0.1, 0.2, 0.05);
    final List<Double> loadsForEp2 = Arrays.asList(0.05, 0.05, 0.05, 0.1, 0.2, 0.1, 0.05, 0.1, 0.2, 0.05);
    final List<Double> loadsForEp3 = Arrays.asList(0.1, 0.2, 0.3, 0.2, 0.05);
    final List<Double> loadsForEp4 = Arrays.asList(0.1, 0.1);
    final List<Double> loadsForEp5 = Arrays.asList(0.1, 0.1, 0.1, 0.1);
    final List<List<Double>> loads = Arrays.asList(loadsForEp1, loadsForEp2, loadsForEp3, loadsForEp4, loadsForEp5);
    for (int i = 0; i < 5; i++) {
        final EventProcessor eventProcessor = eventProcessors.get(i);
        final List<Double> loadList = loads.get(i);
        for (final Double load : loadList) {
            final Group group = mock(Group.class);
            when(group.getLoad()).thenReturn(load);
            when(group.toString()).thenReturn(Double.toString(load));
            when(group.isSplited()).thenReturn(false);
            groupAllocationTable.getValue(eventProcessor).add(group);
        }
    }
    loadUpdater.update();
    rebalancer.triggerRebalancing();
    Assert.assertEquals(0.9, calculateLoadOfGroups(groupAllocationTable.getValue(eventProcessors.get(0))), 0.0001);
    Assert.assertEquals(0.9, calculateLoadOfGroups(groupAllocationTable.getValue(eventProcessors.get(1))), 0.0001);
    Assert.assertEquals(0.85, calculateLoadOfGroups(groupAllocationTable.getValue(eventProcessors.get(2))), 0.0001);
    Assert.assertEquals(0.3, calculateLoadOfGroups(groupAllocationTable.getValue(eventProcessors.get(3))), 0.0001);
    Assert.assertEquals(0.4, calculateLoadOfGroups(groupAllocationTable.getValue(eventProcessors.get(4))), 0.0001);
}
Also used : LoadUpdater(edu.snu.mist.core.task.groupaware.rebalancer.LoadUpdater) DefaultEventProcessorFactory(edu.snu.mist.core.task.groupaware.eventprocessor.DefaultEventProcessorFactory) EventProcessorFactory(edu.snu.mist.core.task.groupaware.eventprocessor.EventProcessorFactory) LinkedList(java.util.LinkedList) GroupRebalancer(edu.snu.mist.core.task.groupaware.rebalancer.GroupRebalancer) Injector(org.apache.reef.tang.Injector) EventProcessor(edu.snu.mist.core.task.groupaware.eventprocessor.EventProcessor) List(java.util.List) LinkedList(java.util.LinkedList) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) Test(org.junit.Test)

Example 3 with GroupRebalancer

use of edu.snu.mist.core.task.groupaware.rebalancer.GroupRebalancer in project mist by snuspl.

the class GroupRebalancerTest method firstFitRebalancerTest1.

// ep1: [1.0, 2.0, 3.0, 4.0, 0.5, 0.5, 1.0] (total 12)
// ep2: [1.0, 1.0, 1.0, 1.0, 0.5, 0.5] (total 5)
// ep3: [0.5, 5.0, 0.5, 0.5, 0.5, 0.5] (total 7.5)
// ep4: [2.0, 0.3, 0.2, 0.5, 0.5] (total 3.5)
// ==> total_load: 28
// ==> desirable load: 7
// Items: [1.0, 2.0, 3.0, 0.5]
// ep1: [4.0, 0.5, 0.5, 1.0] (total 6)
// ep2: [1.0, 1.0, 1.0, 1.0, 0.5, 0.5] (total 5)
// ep3: [5.0, 0.5, 0.5, 0.5, 0.5] (total 7)
// ep4: [2.0, 0.3, 0.2, 0.5, 0.5] (total 3.5)
// First-fit algorithm:
// ep1: [4.0, 0.5, 0.5, 1.0, 1.0] (total 7)
// ep2: [1.0, 1.0, 1.0, 1.0, 0.5, 0.5, 2] (total 7)
// ep3: [5.0, 0.5, 0.5, 0.5, 0.5] (total 7)
// ep4: [2.0, 0.3, 0.2, 0.5, 0.5, 3.0, 0.5] (total 7)
@Test
public void firstFitRebalancerTest1() throws InjectionException {
    final JavaConfigurationBuilder jcb = Tang.Factory.getTang().newConfigurationBuilder();
    jcb.bindNamedParameter(DefaultNumEventProcessors.class, "0");
    jcb.bindImplementation(LoadUpdater.class, TestLoadUpdater.class);
    final Injector injector = Tang.Factory.getTang().newInjector(jcb.build());
    final GroupAllocationTable groupAllocationTable = injector.getInstance(GroupAllocationTable.class);
    final GroupRebalancer rebalancer = injector.getInstance(FirstFitRebalancerImpl.class);
    final LoadUpdater loadUpdater = injector.getInstance(LoadUpdater.class);
    final EventProcessorFactory epFactory = injector.getInstance(DefaultEventProcessorFactory.class);
    final List<EventProcessor> eventProcessors = new LinkedList<>();
    for (int i = 0; i < 4; i++) {
        eventProcessors.add(epFactory.newEventProcessor());
        groupAllocationTable.put(eventProcessors.get(i));
    }
    final List<Double> loadsForEp1 = Arrays.asList(1.0, 2.0, 3.0, 4.0, 0.5, 0.5, 1.0);
    final List<Double> loadsForEp2 = Arrays.asList(1.0, 1.0, 1.0, 1.0, 0.5, 0.5);
    final List<Double> loadsForEp3 = Arrays.asList(0.5, 5.0, 0.5, 0.5, 0.5, 0.5);
    final List<Double> loadsForEp4 = Arrays.asList(2.0, 0.3, 0.2, 0.5, 0.5);
    final List<List<Double>> loads = Arrays.asList(loadsForEp1, loadsForEp2, loadsForEp3, loadsForEp4);
    for (int i = 0; i < 4; i++) {
        final EventProcessor eventProcessor = eventProcessors.get(i);
        final List<Double> loadList = loads.get(i);
        for (final Double load : loadList) {
            final Group group = mock(Group.class);
            when(group.getLoad()).thenReturn(load);
            when(group.isSplited()).thenReturn(false);
            when(group.toString()).thenReturn(Double.toString(load));
            groupAllocationTable.getValue(eventProcessor).add(group);
        }
    }
    loadUpdater.update();
    rebalancer.triggerRebalancing();
    Assert.assertEquals(7.0, calculateLoadOfGroups(groupAllocationTable.getValue(eventProcessors.get(0))));
    Assert.assertEquals(7.0, calculateLoadOfGroups(groupAllocationTable.getValue(eventProcessors.get(1))));
    Assert.assertEquals(7.0, calculateLoadOfGroups(groupAllocationTable.getValue(eventProcessors.get(2))));
    Assert.assertEquals(7.0, calculateLoadOfGroups(groupAllocationTable.getValue(eventProcessors.get(3))));
}
Also used : LoadUpdater(edu.snu.mist.core.task.groupaware.rebalancer.LoadUpdater) DefaultEventProcessorFactory(edu.snu.mist.core.task.groupaware.eventprocessor.DefaultEventProcessorFactory) EventProcessorFactory(edu.snu.mist.core.task.groupaware.eventprocessor.EventProcessorFactory) LinkedList(java.util.LinkedList) GroupRebalancer(edu.snu.mist.core.task.groupaware.rebalancer.GroupRebalancer) Injector(org.apache.reef.tang.Injector) EventProcessor(edu.snu.mist.core.task.groupaware.eventprocessor.EventProcessor) List(java.util.List) LinkedList(java.util.LinkedList) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) Test(org.junit.Test)

Aggregations

GroupRebalancer (edu.snu.mist.core.task.groupaware.rebalancer.GroupRebalancer)3 Injector (org.apache.reef.tang.Injector)3 JavaConfigurationBuilder (org.apache.reef.tang.JavaConfigurationBuilder)3 DefaultEventProcessorFactory (edu.snu.mist.core.task.groupaware.eventprocessor.DefaultEventProcessorFactory)2 EventProcessor (edu.snu.mist.core.task.groupaware.eventprocessor.EventProcessor)2 EventProcessorFactory (edu.snu.mist.core.task.groupaware.eventprocessor.EventProcessorFactory)2 LoadUpdater (edu.snu.mist.core.task.groupaware.rebalancer.LoadUpdater)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Test (org.junit.Test)2 Before (org.junit.Before)1