Expire Time of Memcached

Source code from Memcached refers to expire time:

#define REALTIME_MAXDELTA 60*60*24*30

/*
 * given time value that's either unix time or delta from current unix time, return
 * unix time. Use the fact that delta can't exceed one month (and real time value can't
 * be that low).
 */

static rel_time_t realtime(const time_t exptime) {
    /* no. of seconds in 30 days - largest possible delta exptime */
 
    if (exptime == 0) return 0; /* 0 means never expire */
 
    if (exptime > REALTIME_MAXDELTA) {
        /* if item expiration is at/before the server started, give it an
           expiration time of 1 second after the server started.
           (because 0 means don't expire).  without this, we'd
           underflow and wrap around to some large value way in the
           future, effectively making items expiring in the past
           really expiring never */
        if (exptime <= process_started)
            return (rel_time_t)1;
        return (rel_time_t)(exptime - process_started);
    } else {
        return (rel_time_t)(exptime + current_time);
    }
}

2014-02-04 memcached, yii

Bloom Filter

场景

判断某个元素是否已经存在于一个大的集合(亿级)中,并容许少量的误报的情况下使用。

实现

初始化 m 位的位数组,被 0 填充。定义 k 个不同的 hash 函数,每个 hash 函数将一个输入元素映射到位数组的一个位上,一个确定的输入则有 k 个索引。


2014-01-19 algorithm

strace

strace 是 Linux 平台和一些类 Unix 平台调试工具,可以方便的查看程序执行时的系统调用和接收到的信号。它几乎存在于所有的 Linux 系统中并且可以解决非常多的问题。


2014-01-16 debug, system tool

Vagrant

vagrant logo

Vagrant 是一个开源工具,使用它可以轻松创建和配置虚拟开发环境。它可以基于 VirtualBox 和配置管理工具如 Puppet, Chef 等。从 1.1 版本开始,它不只局限于 VirtualBox, 同时支持了其它虚拟化软件如 VMware 和亚马逊 EC2 等.


2013-12-28 virtualization, cloud

MySQL 执行计划

执行 SQL query 时,MySQL 会为 SQL 的执行尝试一个最优的执行计划。通过在查询命令前加 EXPLAIN 就可以看到 MySQL 的执行计划。EXPLAIN 是了解和优化 MySQL 查询的利器之一。


2013-12-15 MySQL

在 30 瓶水中找出一瓶有毒的

问题

有 30 瓶水,其中一个瓶子是有毒的,毒性在 n 分钟发作,最少用多少只白鼠可以一次找出那瓶毒水,判断和操作时间不能超过 n 分钟。


2013-12-10 puzzle