Last active
December 12, 2016 19:09
-
-
Save apivovarov/2b5eb4aa6da8f8ae38d6b14eb07ecf96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package aaa; | |
import java.util.HashMap; | |
/** | |
* Use -Xmx30G -Xms30G for 100,000,000 rows | |
*/ | |
public class MapUpdater { | |
public static void main(String[] args) throws InterruptedException { | |
if (args.length != 2) { | |
throw new RuntimeException("Usage: MapUpdater <map_size_mil> <update_count_mil>"); | |
} | |
int mapSize = Integer.parseInt(args[0]) * 1000000; | |
int updCnt = Integer.parseInt(args[1]) * 1000000; | |
HashMap<String, Row> map = new HashMap<>((int) (mapSize * 1.1)); | |
for (int i = 0; i < mapSize; i++) { | |
String dom = getDomain(i); | |
map.put(dom, new Row()); | |
} | |
System.out.println("Map Init Done"); | |
update(map, updCnt); | |
update(map, updCnt); | |
update(map, updCnt); | |
update(map, updCnt); | |
} | |
static void update(HashMap<String, Row> map, int updCnt) throws InterruptedException { | |
long s1 = System.currentTimeMillis(); | |
for (int i = 0; i < updCnt; i++) { | |
String dom = getDomain(i); | |
Row row = map.get(dom); | |
row.v1 += 1L; | |
} | |
long s2 = System.currentTimeMillis(); | |
System.out.println(s2 - s1); | |
} | |
static class Row { | |
public long v1; | |
@Override | |
public String toString() { | |
return "row.v1: " + v1; | |
} | |
} | |
static String getDomain(int i) { | |
if (i < 10) { | |
return "d00000000" + i; | |
} else if (i < 100) { | |
return "d0000000" + i; | |
} else if (i < 1000) { | |
return "d000000" + i; | |
} else if (i < 10000) { | |
return "d00000" + i; | |
} else if (i < 100000) { | |
return "d0000" + i; | |
} else if (i < 1000000) { | |
return "d000" + i; | |
} else if (i < 10000000) { | |
return "d00" + i; | |
} else if (i < 100000000) { | |
return "d0" + i; | |
} else { | |
return "d" + i; | |
} | |
} | |
} | |
// Map Init Done | |
// 128 | |
// 107 | |
// 87 | |
// 99 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment