【问题标题】:Any performance benefits of using apc_store vs apc_add (or vice versa)?使用 apc_store 与 apc_add(反之亦然)有什么性能优势?
【发布时间】:2013-10-28 21:55:58
【问题描述】:

虽然我了解 apc_store 和 apc_add 之间的区别,但我想知道使用其中一个是否有任何性能优势?

人们会认为 apc_store 可以更快一些,因为它不需要在插入之前检查是否存在。

我的想法正确吗?

或者在我们确定该条目不存在的情况下使用 apc_add 会更快一些?

【问题讨论】:

    标签: php caching store add apc


    【解决方案1】:

    简短:apc_store() 应该比apc_add() 稍慢。

    更长:两者之间的唯一区别是传递给apc_store_helper()exclusive 标志,这反过来又导致apc_cache_insert() 中的行为差异。

    这里发生了什么:

    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;
    }
    

    主要区别在于apc_add() 如果值已经存在,则保存一个槽删除。现实世界的基准测试显然对确认该分析很有意义。

    【讨论】:

      猜你喜欢
      • 2013-02-22
      • 2011-11-21
      • 2016-11-24
      • 1970-01-01
      • 2021-12-15
      • 1970-01-01
      • 2023-02-05
      • 2014-05-12
      • 1970-01-01
      相关资源
      最近更新 更多