数据分片处理时分片数奇偶差别分析

为了提高数据处理的速度,会经常用到分片的方法。为了数据能够分片均匀分片数该怎么取?
public static void main(String[] args) {
Map<String,Integer> map = new HashMap<>();
for (int i = 0; i <100000000; i++) {
int code = String.valueOf(i).hashCode();
int mode = Math.abs(code%7);
switch(mode){
case 0:
Integer count = map.get(“0”);
if(count == null){
map.put(“0”,1);
}else {
map.put(“0”,++count);
}
continue;
case 1:
Integer count1 = map.get(“1”);
if(count1 == null){
map.put(“1”,1);
}else {
map.put(“1”,++count1);
}
continue;
case 2:
Integer count2 = map.get(“2”);
if(count2 == null){
map.put(“2”,1);
}else {
map.put(“2”,++count2);
}
continue;
case 3:
Integer count3 = map.get(“3”);
if(count3 == null){
map.put(“3”,1);
}else {
map.put(“3”,++count3);
}
continue;
case 4:
Integer count4 = map.get(“4”);
if(count4 == null){
map.put(“4”,1);
}else {
map.put(“4”,++count4);
}
continue;
case 5:
Integer count5 = map.get(“1”);
if(count5 == null){
map.put(“5”,1);
}else {
map.put(“5”,++count5);
}
continue;
case 6:
Integer count6 = map.get(“6”);
if(count6 == null){
map.put(“6”,1);
}else {
map.put(“6”,++count6);
}
continue;
}

    }
    System.out.println("map = " + map);
    consle:当分片数为7时map = {0=14285714, 1=14285717, 2=14285716, 3=14285711, 4=14285714, 5=14285717, 6=14285713};
    当分片数为8时map = {0=12500038, 1=12499999, 2=12499964, 3=12499955, 4=12499970, 5=12500000, 6=12500028}
    实测看奇偶数对数据分片的影响不大。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值