[2001-7-18 5:07:19] A:
hi, something about adstorge server....
in adstoragesvr.cpp, the .Get() function of adcache, and the lock of the cache has some problems i think.....
[2001-7-18 5:08:59] B:
ok, please give more info.
[2001-7-18 5:11:58] A:
I think u can lock the cache between get and store the cache...so
the sequence is lock the cache->Get()-> Fetchtemplate->Store->release lock, otherwise it may cause multi-thread problem...
and the process above should be put in Cache.Get() function....
[2001-7-18 5:13:41] A:
the reason that puting the process to Get() function is that it is better that the lock is used just in the cache class...
[2001-7-18 5:14:48] B:
It's Rayman who advice me to separate database access from
ADCache......
[2001-7-18 5:19:26] A:
yes, separate the db access is better , but then the interal level acess of adcache will appear ...
[2001-7-18 5:22:07] A:
maybe we can give an function to lock the cache in some hashbask, it is not good but better....
[2001-7-18 5:22:46] B:
do you think that the OnRequest function at now would cause
a deadlock in multithread case?
[2001-7-18 5:24:36] A:
no, it maynot...
but the efficency is not good...
and a more serious problem...it is possible that many thread can't get the mid content at the same time, and they get it from db just for one mail content....
[2001-7-18 5:27:25] A:
if we don't consider about the structure of this program, at least
the lock code of adcache should be placed before u invoke Cache's Get() function...
[2001-7-18 5:31:37] B:
按你这么说其实PORTAL Server的ipaecache也有此问题....
[2001-7-18 5:32:52] A:
yes, I do all the process in IPAECache's Get() function, and the lock is between those process as I wrote to you before...
[2001-7-18 5:37:27] B:
我觉得其实区别不大, 不同点就是我现在的写法在Cache中没有letter的时候要多加锁和释放锁一次, 性能可能下降一些.
不过其实我原来是参照ipaecache的把数据库访问,Store等全封装在同一个Get()函数里, 后来Rayman说把数据库访问和Cache分开来, 才改成了现在这样的,
[2001-7-18 5:45:08] A:
HEHE..
由程序结构來说, 兩种做法都是差不多的.只是在兩种风格上取舍那种好而已.
不过你看看, 在你的程序中, 调用GET时从CACHE中取出信內容, 如沒有則就从DB中取, 存入CACHE, 你可以设想有很多thread一起去到GET这行取某一MID的內容. 但是它们取得的都是null, 即很多thread都不能从CACHE中取到同一个MID的內容. 它们到走过了ad.isnull这行, 但都未过Store那行, 此时它们都会从DB中取, 都重复地存入CACHE了.
[2001-7-18 5:48:47] A:
情況可能比较复杂...这样写可能不太清楚...
[2001-7-18 5:49:53] B:
我已经明白你的意思了.
[2001-7-18 5:51:54] A:
你应为呢?
我忘了cache中遇到已有內容时的处理方式...如果它是采用原來的指針进行內容替換的话, 你现有的那段程序可能还有其它一些多線程问题...
[2001-7-18 5:57:44] A:
現在回想起來, 其实当时的PAECACHE设计得很差...如果你覺得有不好的地方, 你不一定要跟它一样的...
[2001-7-18 5:58:29] B:
其实统一写到Get()函数里, 能够避免你这次说的很多thread并发取Cache中没有的信件的问题, 但对于很多thread并发取同一在Cache里有的信件的问题, 统一写到Get()里并加锁的效率一样是不高的, 亦即ipaecache的做法的效率也不会高......
:) 谢谢你的提醒, 我会考虑更好的实现方法.
[2001-7-18 6:03:51] A:
是的, 但是按PAECACHE这种做法是把一个HASH桶鎖上, 它每次都只鎖上CACHE中的一部分而已, 但是它鎖的时间间隔是较長的...所以如果按PAECACHE这种做法, 代价只是在某一个HASH桶上的結點存取时间長一点, 但是与多个thread从数据库中取出并重复执行STORE操作相比, 效率始终高出很多...最少数据库那边已不是一个小的开銷了....
[2001-7-18 6:12:51] A:
好像adcache中的settimetolive和setnodesize等函数沒有存在的必要吧?
当时我只是因为PAE那边较特殊才写的...那兩个函数不太好....
[2001-7-18 6:34:26] B:
IHashCache中的Fetch()函数都是先LockNodeByKey()加锁, 这意味着一个时间只能有一个thread调用Fetch读取Cache中的Node,
看来ihashcache.cpp也得动手改..... 改成读写锁.....
[2001-7-18 6:35:59] A:
这些鎖的粒度都是按HASH桶, 就是說在同一时间, 只要結點位于不同的桶, 就能同时存取...
[2001-7-18 6:38:32] A:
至于读写锁, 我们当时都有考慮, 但是因为好像用到读锁的地方不太多, 所以就干脆省掉了...
[2001-7-18 6:39:12] B:
但无论如何把X锁改成RW锁会more efficient, 况且广告信的数量不会很多, 可能就几封而已....