多次循环获得 memecache 用时 10 ms
写道
Map<String,String result = new HashMap<String,String();
for(int i = 0; len = leys.lenght; i < len; i ++){
//loop get memecached use 10 ms
result.put(keys[i],memcacheGet(keys[i]));
}
for(int i = 0; len = leys.lenght; i < len; i ++){
//loop get memecached use 10 ms
result.put(keys[i],memcacheGet(keys[i]));
}
一次批量获得 用时 2ms
写道
//batch get use 2ms
Map<String,Object> objMapt = client.get(Arrays.asList(keys));
Map<String,Object> objMapt = client.get(Arrays.asList(keys));
时间消耗在网络IO。
java 实现 IP 段快速查询方法:
写道
//TreeMap<IPEntry,String> 可以轻松实现 按照ip 段进行查询。
class IPEntry implements Comparable<IPEntry> {
final long start;
final long end;
IPEntry(long start, long end){
public int compartTo(IPEntry t){
long t1 = start - t.start;
if ( t1 < 0 )
return -1;
long t2 = end - t.end;
if ( t1 >= 0 && t2 <= 0)
return 0;
return 1;
}
.....
}
class IPEntry implements Comparable<IPEntry> {
final long start;
final long end;
IPEntry(long start, long end){
public int compartTo(IPEntry t){
long t1 = start - t.start;
if ( t1 < 0 )
return -1;
long t2 = end - t.end;
if ( t1 >= 0 && t2 <= 0)
return 0;
return 1;
}
.....
}