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