【 在 dvlt (-: :-) 的大作中提到: 】
: 标 题: 关于 user hash 的一个问题
: 发信站: 水木社区 (Thu Nov 3 15:21:54 2005), 转信
:
: 根据 smthbbs 1.2.2 的 doc/userid 文档,fb 代码原本是没有用 hash 来检索
: 用户id的,而smth的代码采用了自己特制的 hash 来加快检索速度。
:
: ucache 里的代码不太好懂,我看了半天,有两个问题:
:
: 1, hash 加快的检索效率到底对 bbs 的运行有没有实质性的帮助?这个我不知道
: 前辈有没有测试过。会不会实际情况是因为 hash 而提高的效率相对于 io
: 瓶颈来说对bbs的运行效率并没有什么提高?
absolutely, 当人数超过 3K ,基本 hash 加速的效果就很明显了
:
: 2, hash 的一个缺点是查询用户的时候,列出用户是无序的,而且必须先输入两个
: 字符才能查询,代码本身也很复杂。如果用b-tree给用户索引是不是能够解决
: 这个麻烦点呢?
你真的觉得 btree 可以解决你说的这三个问题吗。。。
:
: 3, miscd userd 是添加和删除用户用的吧?为什么要用一个单独的daemon来添加
: 删除用户,而不是直接通过 libBBS 的函数调用实现呢?
:
添加删除用户的操作并不是非常频繁,因此这里偷懒用个独立入口的 daemon 来实现, 可以避免实现时候的很多同步和竞争问题。
: 4, libBBS/ucache.c 里的 fillucache 函数里有一句话似乎不对:
:
: if (uidshm->passwd[*number].numlogins > uentp->numlogins) {
: // the later entry is `newer' than the former entry.
: bbslog("3passwd", "deleted %s in %d", uentp->userid, i - 1);
:
: // delete the former entry from the hash list.
: if (prev == -1)
: uidshm->hashhead[hashkey] = uidshm->next[i - 1];
: else
: uidshm->next[prev - 1] = uidshm->next[i - 1];
:
: // clear the content of the existing user entry.
: uentp->userid[0] = 0;
: uidshm->next[i - 1] = 0;// XXX: 是否应该等于 uidshm->hashhead[0]?
: // But this will confuse 10 lines below:
: // i = uidshm->next[i-1] ...
: uidshm->hashhead[0] = i;
: } else {
: ....
:
: 谢谢前辈啦!^^
:
at3p 牛已经 回答了这个了
: --
:
: ※ 来源:·水木社区 newsmth.net·[FROM: 59.66.199.*]
--
FROM 61.149.26.*