duanchi1230 2015-11-15 21:07
浏览 58
已采纳

在Memcached中正确存储数据

I am using Memchache for storing some data, and single item in memcahce looks like the following structure:

`locale1` => [
   'domain1' => [
        'key1-1' => 'value1-1',
        'key1-2' => 'value1-2'
    ],
   'domain2' => [ ... ]
]

so in memcache I have multiple items with similar keys, values that lays in side locale->domain can be changed by web interface. My question is:

What if I will place all locales to single memcache item called locales_holder, and then will fetch all data from it, would it be critical to performance or its ok?

Thanks!

  • 写回答

1条回答 默认 最新

  • dongzhao1865 2015-11-15 21:40
    关注

    This would not be very efficient. Memcache deletes keys that are not used often or when space is needed.

    Building the keys and storing small to medium sized data gives the best results.

    Memcache key: locale/domain1/key1/1
    Memcache value: 'value1-1'
    

    Whenever something gets changed you don't have to write the entire blob of data back into the memcache instance.

    Also, if you are using multiple servers the data gets distributed better over the servers because it can split up the entire locale section over multiple servers.

    If you have two servers, the memcached client calculates a numeric value from the key and performs a simple calculation on it (for example, modulus) to determine whether it should store the value on the first, or second, configured memcached instance.

    See also: - Memcached best practices - small objects and lots of keys or big objects and few keys? - http://www.ibm.com/developerworks/library/os-memcached/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥18 深度学习tensorflow1,ssdv1,coco数据集训练一个模型
  • ¥100 关于注册表摄像头和麦克风的问题
  • ¥30 代码本地运行正常,但是TOMCAT部署时闪退
  • ¥15 关于#python#的问题
  • ¥15 主机可以ping通路由器但是连不上网怎么办
  • ¥15 数据库一张以时间排好序的表中,找出多次相邻的那些行
  • ¥50 关于DynamoRIO处理多线程程序时候的问题
  • ¥15 kubeadm部署k8s出错
  • ¥15 Abaqus打不开cae文件怎么办?
  • ¥15 小程序准备上线,软件开发公司需要提供哪些资料给甲方