dqcuq4138 2013-10-20 11:56
浏览 104

使用apc_store vs apc_add的任何性能优势(反之亦然)?

While I understand the differences between apc_store and apc_add, I was wondering if using one or the other has any performance benefits?

One would think apc_store COULD be a bit quicker since it does not need to do a check-if-exists before doing the insert.

Am I correct in my thinking?

Or would using apc_add in situations where we know FOR SURE that the entry does not exist prove to be a bit faster?

  • 写回答

1条回答 默认 最新

  • dongxi1965 2014-07-05 21:46
    关注

    Short: apc_store() should be slightly slower than apc_add().

    Longer: the only difference between the two is the exclusive flag passed to apc_store_helper() that in turns leads to the behavior difference in apc_cache_insert().

    Here is what happens there:

    if (((*slot)->key.h == key.h) && (!memcmp((*slot)->key.str, key.str, key.len))) {
        if(exclusive) {
            if (!(*slot)->value->ttl || (time_t) ((*slot)->ctime + (*slot)->value->ttl) >= t) {
                goto nothing;
            }
        }
        // THIS IS THE MAIN DIFFERENCE
        apc_cache_remove_slot(cache, slot TSRMLS_CC);**
        break;
    } else 
        if((cache->ttl && (time_t)(*slot)->atime < (t - (time_t)cache->ttl)) || 
            ((*slot)->value->ttl && (time_t) ((*slot)->ctime + (*slot)->value->ttl) < t)) {
            apc_cache_remove_slot(cache, slot TSRMLS_CC);
            continue;
        }
    
        slot = &(*slot)->next;      
    }
    
    if ((*slot = make_slot(cache, &key, value, *slot, t TSRMLS_CC)) != NULL) {
        value->mem_size = ctxt->pool->size;
    
        cache->header->mem_size += ctxt->pool->size;
        cache->header->nentries++;
        cache->header->ninserts++;
    } else {
        goto nothing;
    }
    

    The main difference is that apc_add() saves one slot removal if the value is already present. Real world benchmarks would obviously make a lot of sense to confirm that analysis.

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据