web應(yīng)用為了記錄點(diǎn)擊次數(shù),可以設(shè)計(jì)一個(gè)點(diǎn)擊次數(shù)表,create table hit_counter(cnt int unsigned not null);由于只有一條記錄這樣鎖爭(zhēng)用太嚴(yán)重,想到了什么解決方案,同concurrenthashmap一樣做鎖拆分。
表結(jié)構(gòu)修改為:
create table hit_counter(slot tinyint unsigned not null primary key,cnt int unsigned not null);--phpfensi.com
預(yù)先放入100條數(shù)據(jù),這樣修改的時(shí)候可以使用如下語(yǔ)句,update hit_counter set cnt = cnt+1 where slot = RAND()*100;獲取的時(shí)候求和就可以了,select sum(cnt) cnt from hit_counter;不知道iteye的博客計(jì)數(shù)是不是也采用了類似的設(shè)計(jì).