Java Code Examples for org.apache.flink.runtime.operators.testutils.types.IntPair#setValue()

The following examples show how to use org.apache.flink.runtime.operators.testutils.types.IntPair#setValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HashTableITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public IntPair next(IntPair reuse) {
	if (this.numLeft > 0) {
		this.numLeft--;
		reuse.setKey(this.key);
		reuse.setValue(this.value);
		return reuse;
	}
	else {
		return null;
	}
}
 
Example 2
Source File: UniformIntPairGenerator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public IntPair next(IntPair target) {
	if(!repeatKey) {
		if(valCnt >= numVals) {
			return null;
		}
		
		target.setKey(keyCnt++);
		target.setValue(valCnt);
		
		if(keyCnt == numKeys) {
			keyCnt = 0;
			valCnt++;
		}
	} else {
		if(keyCnt >= numKeys) {
			return null;
		}
		
		target.setKey(keyCnt);
		target.setValue(valCnt++);
		
		if(valCnt == numVals) {
			valCnt = 0;
			keyCnt++;
		}
	}
	
	return target;
}
 
Example 3
Source File: HashTableITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public IntPair next(IntPair reuse) {
	if (this.numLeft > 0) {
		this.numLeft--;
		reuse.setKey(this.key);
		reuse.setValue(this.value);
		return reuse;
	}
	else {
		return null;
	}
}
 
Example 4
Source File: RandomIntPairGenerator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public IntPair next(IntPair reuse) {
	if (this.count++ < this.numRecords) {
		reuse.setKey(this.rnd.nextInt());
		reuse.setValue(this.rnd.nextInt());
		return reuse;
	} else {
		return null;
	}
}
 
Example 5
Source File: RandomIntPairGenerator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public IntPair next(IntPair reuse) {
	if (this.count++ < this.numRecords) {
		reuse.setKey(this.rnd.nextInt());
		reuse.setValue(this.rnd.nextInt());
		return reuse;
	} else {
		return null;
	}
}
 
Example 6
Source File: UniformIntPairGenerator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public IntPair next(IntPair target) {
	if(!repeatKey) {
		if(valCnt >= numVals) {
			return null;
		}
		
		target.setKey(keyCnt++);
		target.setValue(valCnt);
		
		if(keyCnt == numKeys) {
			keyCnt = 0;
			valCnt++;
		}
	} else {
		if(keyCnt >= numKeys) {
			return null;
		}
		
		target.setKey(keyCnt);
		target.setValue(valCnt++);
		
		if(valCnt == numVals) {
			valCnt = 0;
			keyCnt++;
		}
	}
	
	return target;
}
 
Example 7
Source File: RandomIntPairGenerator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public IntPair next(IntPair reuse) {
	if (this.count++ < this.numRecords) {
		reuse.setKey(this.rnd.nextInt());
		reuse.setValue(this.rnd.nextInt());
		return reuse;
	} else {
		return null;
	}
}
 
Example 8
Source File: UniformIntPairGenerator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public IntPair next(IntPair target) {
	if(!repeatKey) {
		if(valCnt >= numVals) {
			return null;
		}
		
		target.setKey(keyCnt++);
		target.setValue(valCnt);
		
		if(keyCnt == numKeys) {
			keyCnt = 0;
			valCnt++;
		}
	} else {
		if(keyCnt >= numKeys) {
			return null;
		}
		
		target.setKey(keyCnt);
		target.setValue(valCnt++);
		
		if(valCnt == numVals) {
			valCnt = 0;
			keyCnt++;
		}
	}
	
	return target;
}
 
Example 9
Source File: HashTableITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public IntPair next(IntPair reuse) {
	if (this.numLeft > 0) {
		this.numLeft--;
		reuse.setKey(this.key);
		reuse.setValue(this.value);
		return reuse;
	}
	else {
		return null;
	}
}
 
Example 10
Source File: HashTablePerformanceComparison.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testCompactingHashMapPerformance() {
	
	try {
		final int NUM_MEM_PAGES = SIZE * NUM_PAIRS / PAGE_SIZE;
		
		MutableObjectIterator<IntPair> buildInput = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
		
		MutableObjectIterator<IntPair> probeTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
		
		MutableObjectIterator<IntPair> updater = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> updateTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
		
		long start;
		long end;
		
		long first = System.currentTimeMillis();
		
		System.out.println("Creating and filling CompactingHashMap...");
		start = System.currentTimeMillis();
		AbstractMutableHashTable<IntPair> table = new CompactingHashTable<IntPair>(serializer, comparator, getMemory(NUM_MEM_PAGES, PAGE_SIZE));
		table.open();
		
		IntPair target = new IntPair();
		while(buildInput.next(target) != null) {
			table.insert(target);
		}
		end = System.currentTimeMillis();
		System.out.println("HashMap ready. Time: " + (end-start) + " ms");
		
		System.out.println("Starting first probing run...");
		start = System.currentTimeMillis();
		
		AbstractHashTableProber<IntPair, IntPair> prober = table.getProber(comparator, pairComparator);
		IntPair temp = new IntPair();
		while(probeTester.next(target) != null) {
			assertNotNull(prober.getMatchFor(target, temp));
			assertEquals(temp.getValue(), target.getValue());
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");
		
		System.out.println("Starting update...");
		start = System.currentTimeMillis();
		while(updater.next(target) != null) {
			target.setValue(target.getValue() + 1);
			table.insertOrReplaceRecord(target);
		}
		end = System.currentTimeMillis();
		System.out.println("Update done. Time: " + (end-start) + " ms");
		
		System.out.println("Starting second probing run...");
		start = System.currentTimeMillis();
		while (updateTester.next(target) != null) {
			assertNotNull(prober.getMatchFor(target, temp));
			assertEquals(target.getValue() + 1, temp.getValue());
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");
		
		table.close();
		
		end = System.currentTimeMillis();
		System.out.println("Overall time: " + (end-first) + " ms");
		
		assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail("Error: " + e.getMessage());
	}
}
 
Example 11
Source File: HashTablePerformanceComparison.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testMutableHashMapPerformance() {
	try (IOManager ioManager = new IOManagerAsync()) {
		final int NUM_MEM_PAGES = SIZE * NUM_PAIRS / PAGE_SIZE;
		
		MutableObjectIterator<IntPair> buildInput = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> probeInput = new UniformIntPairGenerator(0, 1, false);
		
		MutableObjectIterator<IntPair> probeTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
		
		MutableObjectIterator<IntPair> updater = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> updateTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
		
		long start;
		long end;
		
		long first = System.currentTimeMillis();
		
		System.out.println("Creating and filling MutableHashMap...");
		start = System.currentTimeMillis();
		MutableHashTable<IntPair, IntPair> table = new MutableHashTable<IntPair, IntPair>(serializer, serializer, comparator, comparator, pairComparator, getMemory(NUM_MEM_PAGES, PAGE_SIZE), ioManager);				
		table.open(buildInput, probeInput);
		end = System.currentTimeMillis();
		System.out.println("HashMap ready. Time: " + (end-start) + " ms");
		
		System.out.println("Starting first probing run...");
		start = System.currentTimeMillis();
		IntPair compare = new IntPair();
		HashBucketIterator<IntPair, IntPair> iter;
		IntPair target = new IntPair(); 
		while(probeTester.next(compare) != null) {
			iter = table.getMatchesFor(compare);
			iter.next(target);
			assertEquals(target.getKey(), compare.getKey());
			assertEquals(target.getValue(), compare.getValue());
			assertTrue(iter.next(target) == null);
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");

		System.out.println("Starting update...");
		start = System.currentTimeMillis();
		while(updater.next(compare) != null) {
			compare.setValue(compare.getValue() + 1);
			iter = table.getMatchesFor(compare);
			iter.next(target);
			iter.writeBack(compare);
			//assertFalse(iter.next(target));
		}
		end = System.currentTimeMillis();
		System.out.println("Update done. Time: " + (end-start) + " ms");
		
		System.out.println("Starting second probing run...");
		start = System.currentTimeMillis();
		while(updateTester.next(compare) != null) {
			compare.setValue(compare.getValue() + 1);
			iter = table.getMatchesFor(compare);
			iter.next(target);
			assertEquals(target.getKey(), compare.getKey());
			assertEquals(target.getValue(), compare.getValue());
			assertTrue(iter.next(target) == null);
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");
		
		table.close();
		
		end = System.currentTimeMillis();
		System.out.println("Overall time: " + (end-first) + " ms");
		
		assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreedMemory().size());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail("Error: " + e.getMessage());
	}
}
 
Example 12
Source File: HashTablePerformanceComparison.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testInPlaceMutableHashTablePerformance() {
	try {
		final int NUM_MEM_PAGES = SIZE * NUM_PAIRS / PAGE_SIZE;

		MutableObjectIterator<IntPair> buildInput = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> probeTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> updater = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> updateTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		long start;
		long end;

		long first = System.currentTimeMillis();

		System.out.println("Creating and filling InPlaceMutableHashTable...");
		start = System.currentTimeMillis();
		InPlaceMutableHashTable<IntPair> table = new InPlaceMutableHashTable<>(serializer, comparator, getMemory(NUM_MEM_PAGES, PAGE_SIZE));
		table.open();

		IntPair target = new IntPair();
		while(buildInput.next(target) != null) {
			table.insert(target);
		}
		end = System.currentTimeMillis();
		System.out.println("HashMap ready. Time: " + (end-start) + " ms");

		System.out.println("Starting first probing run...");
		start = System.currentTimeMillis();

		AbstractHashTableProber<IntPair, IntPair> prober = table.getProber(comparator, pairComparator);
		IntPair temp = new IntPair();
		while(probeTester.next(target) != null) {
			assertNotNull(prober.getMatchFor(target, temp));
			assertEquals(temp.getValue(), target.getValue());
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");

		System.out.println("Starting update...");
		start = System.currentTimeMillis();
		while(updater.next(target) != null) {
			target.setValue(target.getValue() + 1);
			table.insertOrReplaceRecord(target);
		}
		end = System.currentTimeMillis();
		System.out.println("Update done. Time: " + (end-start) + " ms");

		System.out.println("Starting second probing run...");
		start = System.currentTimeMillis();
		while (updateTester.next(target) != null) {
			assertNotNull(prober.getMatchFor(target, temp));
			assertEquals(target.getValue() + 1, temp.getValue());
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");

		table.close();

		end = System.currentTimeMillis();
		System.out.println("Overall time: " + (end-first) + " ms");

		assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail("Error: " + e.getMessage());
	}
}
 
Example 13
Source File: HashTablePerformanceComparison.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testCompactingHashMapPerformance() {
	
	try {
		final int NUM_MEM_PAGES = SIZE * NUM_PAIRS / PAGE_SIZE;
		
		MutableObjectIterator<IntPair> buildInput = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
		
		MutableObjectIterator<IntPair> probeTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
		
		MutableObjectIterator<IntPair> updater = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> updateTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
		
		long start;
		long end;
		
		long first = System.currentTimeMillis();
		
		System.out.println("Creating and filling CompactingHashMap...");
		start = System.currentTimeMillis();
		AbstractMutableHashTable<IntPair> table = new CompactingHashTable<IntPair>(serializer, comparator, getMemory(NUM_MEM_PAGES, PAGE_SIZE));
		table.open();
		
		IntPair target = new IntPair();
		while(buildInput.next(target) != null) {
			table.insert(target);
		}
		end = System.currentTimeMillis();
		System.out.println("HashMap ready. Time: " + (end-start) + " ms");
		
		System.out.println("Starting first probing run...");
		start = System.currentTimeMillis();
		
		AbstractHashTableProber<IntPair, IntPair> prober = table.getProber(comparator, pairComparator);
		IntPair temp = new IntPair();
		while(probeTester.next(target) != null) {
			assertNotNull(prober.getMatchFor(target, temp));
			assertEquals(temp.getValue(), target.getValue());
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");
		
		System.out.println("Starting update...");
		start = System.currentTimeMillis();
		while(updater.next(target) != null) {
			target.setValue(target.getValue() + 1);
			table.insertOrReplaceRecord(target);
		}
		end = System.currentTimeMillis();
		System.out.println("Update done. Time: " + (end-start) + " ms");
		
		System.out.println("Starting second probing run...");
		start = System.currentTimeMillis();
		while (updateTester.next(target) != null) {
			assertNotNull(prober.getMatchFor(target, temp));
			assertEquals(target.getValue() + 1, temp.getValue());
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");
		
		table.close();
		
		end = System.currentTimeMillis();
		System.out.println("Overall time: " + (end-first) + " ms");
		
		assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail("Error: " + e.getMessage());
	}
}
 
Example 14
Source File: TestData.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public IntPair readWithKeyDenormalization(IntPair reuse, DataInputView source) throws IOException {
	reuse.setKey(source.readInt() + Integer.MIN_VALUE);
	reuse.setValue(source.readInt());
	return reuse;
}
 
Example 15
Source File: TestData.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public IntPair readWithKeyDenormalization(IntPair reuse, DataInputView source) throws IOException {
	reuse.setKey(source.readInt() + Integer.MIN_VALUE);
	reuse.setValue(source.readInt());
	return reuse;
}
 
Example 16
Source File: HashTablePerformanceComparison.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testMutableHashMapPerformance() {
	try (IOManager ioManager = new IOManagerAsync()) {
		final int NUM_MEM_PAGES = SIZE * NUM_PAIRS / PAGE_SIZE;
		
		MutableObjectIterator<IntPair> buildInput = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> probeInput = new UniformIntPairGenerator(0, 1, false);
		
		MutableObjectIterator<IntPair> probeTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
		
		MutableObjectIterator<IntPair> updater = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> updateTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
		
		long start;
		long end;
		
		long first = System.currentTimeMillis();
		
		System.out.println("Creating and filling MutableHashMap...");
		start = System.currentTimeMillis();
		MutableHashTable<IntPair, IntPair> table = new MutableHashTable<IntPair, IntPair>(serializer, serializer, comparator, comparator, pairComparator, getMemory(NUM_MEM_PAGES, PAGE_SIZE), ioManager);				
		table.open(buildInput, probeInput);
		end = System.currentTimeMillis();
		System.out.println("HashMap ready. Time: " + (end-start) + " ms");
		
		System.out.println("Starting first probing run...");
		start = System.currentTimeMillis();
		IntPair compare = new IntPair();
		HashBucketIterator<IntPair, IntPair> iter;
		IntPair target = new IntPair(); 
		while(probeTester.next(compare) != null) {
			iter = table.getMatchesFor(compare);
			iter.next(target);
			assertEquals(target.getKey(), compare.getKey());
			assertEquals(target.getValue(), compare.getValue());
			assertTrue(iter.next(target) == null);
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");

		System.out.println("Starting update...");
		start = System.currentTimeMillis();
		while(updater.next(compare) != null) {
			compare.setValue(compare.getValue() + 1);
			iter = table.getMatchesFor(compare);
			iter.next(target);
			iter.writeBack(compare);
			//assertFalse(iter.next(target));
		}
		end = System.currentTimeMillis();
		System.out.println("Update done. Time: " + (end-start) + " ms");
		
		System.out.println("Starting second probing run...");
		start = System.currentTimeMillis();
		while(updateTester.next(compare) != null) {
			compare.setValue(compare.getValue() + 1);
			iter = table.getMatchesFor(compare);
			iter.next(target);
			assertEquals(target.getKey(), compare.getKey());
			assertEquals(target.getValue(), compare.getValue());
			assertTrue(iter.next(target) == null);
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");
		
		table.close();
		
		end = System.currentTimeMillis();
		System.out.println("Overall time: " + (end-first) + " ms");
		
		assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreedMemory().size());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail("Error: " + e.getMessage());
	}
}
 
Example 17
Source File: HashTablePerformanceComparison.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testInPlaceMutableHashTablePerformance() {
	try {
		final int NUM_MEM_PAGES = SIZE * NUM_PAIRS / PAGE_SIZE;

		MutableObjectIterator<IntPair> buildInput = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> probeTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> updater = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> updateTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		long start;
		long end;

		long first = System.currentTimeMillis();

		System.out.println("Creating and filling InPlaceMutableHashTable...");
		start = System.currentTimeMillis();
		InPlaceMutableHashTable<IntPair> table = new InPlaceMutableHashTable<>(serializer, comparator, getMemory(NUM_MEM_PAGES, PAGE_SIZE));
		table.open();

		IntPair target = new IntPair();
		while(buildInput.next(target) != null) {
			table.insert(target);
		}
		end = System.currentTimeMillis();
		System.out.println("HashMap ready. Time: " + (end-start) + " ms");

		System.out.println("Starting first probing run...");
		start = System.currentTimeMillis();

		AbstractHashTableProber<IntPair, IntPair> prober = table.getProber(comparator, pairComparator);
		IntPair temp = new IntPair();
		while(probeTester.next(target) != null) {
			assertNotNull(prober.getMatchFor(target, temp));
			assertEquals(temp.getValue(), target.getValue());
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");

		System.out.println("Starting update...");
		start = System.currentTimeMillis();
		while(updater.next(target) != null) {
			target.setValue(target.getValue() + 1);
			table.insertOrReplaceRecord(target);
		}
		end = System.currentTimeMillis();
		System.out.println("Update done. Time: " + (end-start) + " ms");

		System.out.println("Starting second probing run...");
		start = System.currentTimeMillis();
		while (updateTester.next(target) != null) {
			assertNotNull(prober.getMatchFor(target, temp));
			assertEquals(target.getValue() + 1, temp.getValue());
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");

		table.close();

		end = System.currentTimeMillis();
		System.out.println("Overall time: " + (end-first) + " ms");

		assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail("Error: " + e.getMessage());
	}
}
 
Example 18
Source File: HashTablePerformanceComparison.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testInPlaceMutableHashTablePerformance() {
	try {
		final int NUM_MEM_PAGES = SIZE * NUM_PAIRS / PAGE_SIZE;

		MutableObjectIterator<IntPair> buildInput = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> probeTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> updater = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> updateTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		long start;
		long end;

		long first = System.currentTimeMillis();

		System.out.println("Creating and filling InPlaceMutableHashTable...");
		start = System.currentTimeMillis();
		InPlaceMutableHashTable<IntPair> table = new InPlaceMutableHashTable<>(serializer, comparator, getMemory(NUM_MEM_PAGES, PAGE_SIZE));
		table.open();

		IntPair target = new IntPair();
		while(buildInput.next(target) != null) {
			table.insert(target);
		}
		end = System.currentTimeMillis();
		System.out.println("HashMap ready. Time: " + (end-start) + " ms");

		System.out.println("Starting first probing run...");
		start = System.currentTimeMillis();

		AbstractHashTableProber<IntPair, IntPair> prober = table.getProber(comparator, pairComparator);
		IntPair temp = new IntPair();
		while(probeTester.next(target) != null) {
			assertNotNull(prober.getMatchFor(target, temp));
			assertEquals(temp.getValue(), target.getValue());
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");

		System.out.println("Starting update...");
		start = System.currentTimeMillis();
		while(updater.next(target) != null) {
			target.setValue(target.getValue() + 1);
			table.insertOrReplaceRecord(target);
		}
		end = System.currentTimeMillis();
		System.out.println("Update done. Time: " + (end-start) + " ms");

		System.out.println("Starting second probing run...");
		start = System.currentTimeMillis();
		while (updateTester.next(target) != null) {
			assertNotNull(prober.getMatchFor(target, temp));
			assertEquals(target.getValue() + 1, temp.getValue());
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");

		table.close();

		end = System.currentTimeMillis();
		System.out.println("Overall time: " + (end-first) + " ms");

		assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail("Error: " + e.getMessage());
	}
}
 
Example 19
Source File: TestData.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public IntPair readWithKeyDenormalization(IntPair reuse, DataInputView source) throws IOException {
	reuse.setKey(source.readInt() + Integer.MIN_VALUE);
	reuse.setValue(source.readInt());
	return reuse;
}
 
Example 20
Source File: HashTablePerformanceComparison.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testMutableHashMapPerformance() {
	final IOManager ioManager = new IOManagerAsync();
	try {
		final int NUM_MEM_PAGES = SIZE * NUM_PAIRS / PAGE_SIZE;
		
		MutableObjectIterator<IntPair> buildInput = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> probeInput = new UniformIntPairGenerator(0, 1, false);
		
		MutableObjectIterator<IntPair> probeTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
		
		MutableObjectIterator<IntPair> updater = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> updateTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
		
		long start;
		long end;
		
		long first = System.currentTimeMillis();
		
		System.out.println("Creating and filling MutableHashMap...");
		start = System.currentTimeMillis();
		MutableHashTable<IntPair, IntPair> table = new MutableHashTable<IntPair, IntPair>(serializer, serializer, comparator, comparator, pairComparator, getMemory(NUM_MEM_PAGES, PAGE_SIZE), ioManager);				
		table.open(buildInput, probeInput);
		end = System.currentTimeMillis();
		System.out.println("HashMap ready. Time: " + (end-start) + " ms");
		
		System.out.println("Starting first probing run...");
		start = System.currentTimeMillis();
		IntPair compare = new IntPair();
		HashBucketIterator<IntPair, IntPair> iter;
		IntPair target = new IntPair(); 
		while(probeTester.next(compare) != null) {
			iter = table.getMatchesFor(compare);
			iter.next(target);
			assertEquals(target.getKey(), compare.getKey());
			assertEquals(target.getValue(), compare.getValue());
			assertTrue(iter.next(target) == null);
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");

		System.out.println("Starting update...");
		start = System.currentTimeMillis();
		while(updater.next(compare) != null) {
			compare.setValue(compare.getValue() + 1);
			iter = table.getMatchesFor(compare);
			iter.next(target);
			iter.writeBack(compare);
			//assertFalse(iter.next(target));
		}
		end = System.currentTimeMillis();
		System.out.println("Update done. Time: " + (end-start) + " ms");
		
		System.out.println("Starting second probing run...");
		start = System.currentTimeMillis();
		while(updateTester.next(compare) != null) {
			compare.setValue(compare.getValue() + 1);
			iter = table.getMatchesFor(compare);
			iter.next(target);
			assertEquals(target.getKey(), compare.getKey());
			assertEquals(target.getValue(), compare.getValue());
			assertTrue(iter.next(target) == null);
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");
		
		table.close();
		
		end = System.currentTimeMillis();
		System.out.println("Overall time: " + (end-first) + " ms");
		
		assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreedMemory().size());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail("Error: " + e.getMessage());
	} finally {
		ioManager.shutdown();
	}
}