-2
我一直在想這個。一個網站每天24小時在線訪問10000個訪問者,運行查詢來選擇lastaction> time() - 300(5分鐘前)的所有行是不行的? 該查詢將每分鐘運行數千次。在線顯示訪問者的最佳方式
我一直在想這個。一個網站每天24小時在線訪問10000個訪問者,運行查詢來選擇lastaction> time() - 300(5分鐘前)的所有行是不行的? 該查詢將每分鐘運行數千次。在線顯示訪問者的最佳方式
使用緩存像memcached(documentation)的東西。
然後,讓這個查詢只運行,如果緩存已經過期
SELECT count(*) FROM users WHERE status = 1 // assume status = 1 = logged in here
像這樣:來自用戶的WHERE狀態= 1`(假設1
$memcache = memcache_connect('localhost', 11211);
// it is highly important to firewall off your memcache port.
$contents = memcache_get($memcache, 'user_count');
if ($contents === false) {
$count = /* query here */
memcache_set($memcache, 'user_count', $count, 0, 2);
} else {
$count = htmlspecialchars($contents);
// note: slightly unsafe in that there is no security. always escape.
}
'SELECT COUNT(*) =登錄) – Amelia
「最好」的方式完全取決於你的個人情況數據庫架構/服務器電源等......如你所提供的,這個問題是有效的答覆。 – Ben
最好 - 在某個預設範圍內的隨機數發生器 - 開銷最小 – 2013-02-03 20:08:21