App server scaling

use load balancer to spread the request to different servers.

different servers will have different cahce
but the cache could be different according to different servers.

Use Memcached to solve this.

image.png
image.png

Code:

# implement the basic memcache functions

CACHE = {}

#return True after setting the data
def set(key, value):
    CACHE[key] = value
    return True
    
#return the value for key
def get(key):
    return CACHE.get(key)
#delete key from the cache
def delete(key):
    if key in CACHE:
        del CACHE[key]
#clear the entire cache
def flush():
    CACHE.clear()
#print set('x', 1)
#>>> True

#print get('x')
#>>> 1

#print get('y')
#>>> None

#delete('x')
#print get('x')
#>>> None

Note:

  • Load balancer is just for spreading request to servers. See Round Robin
  • Memcached is all in memory:
  • fast
  • not durable
  • limited by memory
  • Memcached throw data that is least recently used. (LRU) when no more memory available.

References:
https://en.wikipedia.org/wiki/Cache_stampede
https://en.wikipedia.org/wiki/Memcached

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 7,961评论 0 0
  • 我的上一篇文章里有提到 Anki ,这里放出我根据网上的一个教程自己调出来的适合背单词的 Anki 参数。
    y0rkl1u阅读 7,222评论 0 1
  • 潜藏在记忆深处的 关于所有人事物的那些记忆 其实都是感觉而已 就像经常听到有人说 再也吃不到小时候5角钱一碗 那样...
    米飞阅读 1,639评论 0 0

友情链接更多精彩内容