@Test public void testAllocateRequests() throws Exception { StringRequest.StringRequestEstimator estimator = new StringRequest.StringRequestEstimator(); RequestAllocatorConfig<StringRequest> configuration = RequestAllocatorConfig.builder(estimator).withPrioritizer(new StringRequest.StringRequestComparator()).build(); PreOrderAllocator<StringRequest> allocator = new PreOrderAllocator<>(configuration); ResourcePool pool = ResourcePool.builder().maxResource(StringRequest.MEMORY, 100.).build(); List<Requestor<StringRequest>> requests = Lists.<Requestor<StringRequest>>newArrayList( new StringRequestor("r1", "a-50", "f-50", "k-20"), new StringRequestor("r2", "j-10", "b-20", "e-20"), new StringRequestor("r3", "g-20", "c-200", "d-30")); AllocatedRequestsIterator<StringRequest> result = allocator.allocateRequests(requests.iterator(), pool); List<StringRequest> resultList = Lists.newArrayList(result); Assert.assertEquals(resultList.size(), 3); Assert.assertEquals(resultList.get(0).getString(), "a-50"); Assert.assertEquals(resultList.get(1).getString(), "b-20"); // No c because it is too large to fit Assert.assertEquals(resultList.get(2).getString(), "d-30"); Assert.assertTrue(estimator.getQueriedRequests().contains("a-50")); Assert.assertTrue(estimator.getQueriedRequests().contains("b-20")); Assert.assertTrue(estimator.getQueriedRequests().contains("c-200")); Assert.assertTrue(estimator.getQueriedRequests().contains("d-30")); Assert.assertFalse(estimator.getQueriedRequests().contains("e-20")); Assert.assertFalse(estimator.getQueriedRequests().contains("f-50")); }
private List<Dataset> prioritize (List<Dataset> datasets, State state) { double maxPool = state.getPropAsDouble(MRCompactor.COMPACTION_DATASETS_MAX_COUNT, MRCompactor.DEFUALT_COMPACTION_DATASETS_MAX_COUNT); ResourcePool pool = ResourcePool.builder().maxResource(SimpleDatasetRequest.SIMPLE_DATASET_COUNT_DIMENSION, maxPool).build(); Iterator<Dataset> newList = Iterators.transform( this.allocator.allocateRequests(datasets.stream().map(SimpleDatasetRequestor::new).iterator(), pool), (input) -> input.getDataset()); return Lists.newArrayList(newList); }
ResourcePool.builder().maxResource(MEMORY, 100.).build());
new StringRequestor("r1", "g-10", "i-10"), new StringRequestor("r3", "a-10", "d-10")); ResourcePool pool = ResourcePool.builder().maxResource(StringRequest.MEMORY, 45.).build();
@Test public void testAllocateRequests() throws Exception { RequestAllocatorConfig<StringRequest> configuration = RequestAllocatorConfig.builder(new StringRequest.StringRequestEstimator()).build(); GreedyAllocator<StringRequest> allocator = new GreedyAllocator<>(configuration); ResourcePool pool = ResourcePool.builder().maxResource(StringRequest.MEMORY, 100.).build(); List<Requestor<StringRequest>> requests = Lists.<Requestor<StringRequest>>newArrayList( new StringRequestor("r1", "a-50", "f-50", "k-20"), new StringRequestor("r2", "j-10", "b-20", "e-20"), new StringRequestor("r3", "g-20", "c-200", "d-30")); AllocatedRequestsIterator<StringRequest> result = allocator.allocateRequests(requests.iterator(), pool); List<StringRequest> resultList = Lists.newArrayList(result); Assert.assertEquals(resultList.size(), 2); // all equal, so no order guaranteed Assert.assertEquals(Sets.newHashSet(Lists.transform(resultList, new Function<StringRequest, String>() { @Override public String apply(StringRequest input) { return input.getString(); } })), Sets.newHashSet("a-50", "f-50")); }
@Test public void testAllocateRequests() throws Exception { RequestAllocatorConfig<StringRequest> configuration = RequestAllocatorConfig.builder(new StringRequest.StringRequestEstimator()) .withPrioritizer(new StringRequest.StringRequestComparator()).build(); BruteForceAllocator<StringRequest> allocator = new BruteForceAllocator<>(configuration); ResourcePool pool = ResourcePool.builder().maxResource(StringRequest.MEMORY, 100.).build(); List<Requestor<StringRequest>> requests = Lists.<Requestor<StringRequest>>newArrayList( new StringRequestor("r1", "a-50", "f-50", "k-20"), new StringRequestor("r2", "j-10", "b-20", "e-20"), new StringRequestor("r3", "g-20", "c-200", "d-30")); AllocatedRequestsIterator<StringRequest> result = allocator.allocateRequests(requests.iterator(), pool); List<StringRequest> resultList = Lists.newArrayList(result); Assert.assertEquals(resultList.size(), 4); Assert.assertEquals(resultList.get(0).getString(), "a-50"); Assert.assertEquals(resultList.get(1).getString(), "b-20"); // No c because it is too large to fit Assert.assertEquals(resultList.get(2).getString(), "d-30"); Assert.assertEquals(resultList.get(3).getString(), "e-20"); } }
@Test public void test() { ResourcePool pool = ResourcePool.builder().maxResource(MEMORY, 1000.).maxResource(TIME, 200.).tolerance(MEMORY, 2.) .defaultRequirement(TIME, 1.).build(); Assert.assertEquals(pool.getNumDimensions(), 2); Assert.assertEquals(pool.getSoftBound(), new double[]{1000, 200}); // Default tolerance is 1.2 Assert.assertEquals(pool.getHardBound(), new double[]{2000, 240}); // Test default resource use Assert.assertEquals(pool.getResourceRequirementBuilder().build().getResourceVector(), new double[]{0, 1}); ResourceRequirement requirement = pool.getResourceRequirementBuilder().setRequirement(MEMORY, 10.).build(); Assert.assertEquals(requirement.getResourceVector(), new double[]{10, 1}); }
private List<Dataset> prioritize (List<Dataset> datasets, State state) { double maxPool = state.getPropAsDouble(MRCompactor.COMPACTION_DATASETS_MAX_COUNT, MRCompactor.DEFUALT_COMPACTION_DATASETS_MAX_COUNT); ResourcePool pool = ResourcePool.builder().maxResource(SimpleDatasetRequest.SIMPLE_DATASET_COUNT_DIMENSION, maxPool).build(); Iterator<Dataset> newList = Iterators.transform( this.allocator.allocateRequests(datasets.stream().map(SimpleDatasetRequestor::new).iterator(), pool), (input) -> input.getDataset()); return Lists.newArrayList(newList); }