Memcached调优
文章系本人原创,转载请保持完整性并注明出自 《四火的唠叨》 项目中有一个对实时响应性比较高的服务,引入了Memcached以减少延迟和减少数据库压力。但是期间遇到了一些问题,这里记录一些调优细节。? 客户端选择 最开始我使用的是 Memcached Java Client,
文章系本人原创,转载请保持完整性并注明出自 《四火的唠叨》
项目中有一个对实时响应性比较高的服务,引入了Memcached以减少延迟和减少数据库压力。但是期间遇到了一些问题,这里记录一些调优细节。?
客户端选择
- 最开始我使用的是 Memcached Java Client,但是最后放弃了,放弃原因包括:
- 有时会出现的“No Thread For Socket”异常,我记录在 这里;
- 它不支持NOREPLY模式(在这种模式下,更新缓存的set操作可以不需要Memcached服务端响应,这使得set操作非常非常快)。
- 现在我使用的是 XMemcached。
统计信息
可以通过nc命令向Memcached服务端发送消息来获取统计信息,例如:
echo "stats settings" | nc localhost 20200 | sort
但是,我更需要客户端的统计信息,尤其是缓存命中率,set操作成功率等等。所以在客户端添加了一个简单的统计模块。每次处理用户请求的过程中,通常有两次向Cache服务端的提交get请求,很多情况下还有两次set请求,合计消耗17ms,在把set请求改成NOREPLY模式以后,这个数减少到10ms以内。因此,对于实时性要求比较高的情形,请打开这个模式,或者干脆使用异步的set。
服务端参数
- 可以使用-U来使用UDP传输,但是收效不大。
- -k参数可以阻止换页操作发生,在内存足够的情况下对提高性能有益。
- -C参数可以禁用CAS。
- -t指定使用的线程数,如果你是多CPU、多核CPU,可以把这个值配成和总CPU核数一致。
- -f参数,增长因子,存储大对象把它配大一点可以提高效率,配小一点可以减少浪费。
客户端参数
- 在使用Memcached Java Client的时候:
- 由于它会使用direct memory,一定不能加上DisableExplicitGC这个参数,否则就等着OOM吧;
- 配置大一些的heap size可以提高L1 cache的命中率;
- 把alive check置为false。
- 对于实时性和响应性要求比较高的项目,需要做GC调优,主要是GC时延,比如配置MaxGCPauseMillis参数到一个可以接受的值,但是不是越小越好,减低时延的同时会降低吞吐量。
- 有同事提了个建议,在客户端存放一个cache key的集合,可以在去cache server查询之前,先在本地查看一下是否有缓存记录(比如用 Bloom filter来实现),如果有,再去cache server查询。这个集合可以和实际的cache key有出入,也许一个小时同步一次就可以。但是实际上实现起来比较困难,本身key set的总量非常大,而且Memcached最初提供获取key iterator的接口返回的是一个限定大小key set的iterator,缺乏实际意义(这个接口在后来Memcached的版本中已经被废弃)。至于stats方法,它会把所有cache对象dump出来,只能小规模调试的时候使用。
- 关于Nagle算法:Nagle的好处是可以批量处理请求,提高TCP包有效部分的大小,从而提高网络利用率,但是如果对每个请求处理时延要求很高的话请关闭。
- 一定要指定socket timeout或者get/set timeout。
最后,有人做了一个几个Memcached客户端的综合的性能试验: 链接。
文章系本人原创,转载请保持完整性并注明出自 《四火的唠叨》
分享到:
你可能也喜欢:
-
Issue record: “No thread for socket” about Memcached
-
设计缓存框架需要关注的要素
-
Ehcache详细解读
-
OSCache框架源码解析
-
Javascript Memoizer
原文地址:Memcached调优, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use php-fpm for high-performance tuning PHP is a very popular server-side scripting language that is widely used to develop web applications and dynamic websites. However, as traffic increases, the performance of your PHP application may suffer. In order to solve this problem, we can use php-fpm (FastCGIProcessManager) for high-performance tuning. This article will introduce how to use php-fpm to improve the performance of PHP applications and provide code examples. one,

1. How can you make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! 1. Activate basic rights and interests: original articles can earn profits by advertising, and videos must be original in horizontal screen mode to earn profits. 2. Activate the rights of 100 fans: if the number of fans reaches 100 fans or above, you can get profits from micro headlines, original Q&A creation and Q&A. 3. Insist on original works: Original works include articles, micro headlines, questions, etc., and are required to be more than 300 words. Please note that if illegally plagiarized works are published as original works, credit points will be deducted, and even any profits will be deducted. 4. Verticality: When writing articles in professional fields, you cannot write articles across fields at will. You will not get appropriate recommendations, you will not be able to achieve the professionalism and refinement of your work, and it will be difficult to attract fans and readers. 5. Activity: high activity,

With the development of the Internet, PHP applications have become more and more common in the field of Internet applications. However, high concurrent access by PHP applications can lead to high CPU usage on the server, thus affecting the performance of the application. In order to optimize the performance of PHP applications, Memcached caching technology has become a good choice. This article will introduce how to use Memcached caching technology to optimize the CPU usage of PHP applications. Introduction to Memcached caching technology Memcached is a

In the field of artificial intelligence, large language models (LLMs) are increasingly becoming a new hot spot in research and application. However, how to tune these behemoths efficiently and accurately has always been an important challenge faced by the industry and academia. Recently, the PyTorch official blog published an article about TorchTune, which attracted widespread attention. As a tool focused on LLMs tuning and design, TorchTune is highly praised for its scientific nature and practicality. This article will introduce in detail the functions, features and application of TorchTune in LLMs tuning, hoping to provide readers with a comprehensive and in-depth understanding. 1. The birth background and significance of TorchTune, the development of deep learning technology and the deep learning model (LLM)

Detailed explanation of tuning practices to improve Go language website access speed Abstract: In the rapidly developing Internet era, website access speed has become one of the important factors for users to choose a website. This article will introduce in detail how to use Go language to optimize website access speed, including practical experience in optimizing network requests, using cache, and concurrent processing. The article will also provide code examples to help readers better understand and apply these optimization techniques. 1. Optimize network requests In website development, network requests are an inevitable link. And optimizing network requests can

Since the advent of GPT-4, people have been amazed by its powerful emergence capabilities, including excellent language understanding capabilities, generation capabilities, logical reasoning capabilities, etc. These capabilities make GPT-4 one of the most cutting-edge models in the field of machine learning. However, OpenAI has not disclosed any technical details of GPT-4 so far. Last month, George Hotz mentioned GPT-4 in an interview with an AI technology podcast called LatentSpace, saying that GPT-4 is actually a hybrid model. Specifically, George Hotez said that GPT-4 uses an integrated system composed of 8 expert models, each of which has 220 billion parameters (slightly more than the 175 billion parameters of GPT-3

Operating system performance optimization is one of the keys to ensuring efficient system operation. In Linux systems, we can perform performance tuning and testing through various methods to ensure the best performance of the system. This article will introduce how to perform system tuning and performance testing of Linux systems, and provide corresponding specific code examples. 1. System tuning System tuning is to optimize the performance of the system by adjusting various parameters of the system. The following are some common system tuning methods: 1. Modify the kernel parameters. The kernel parameters of the Linux system control the system operation.

When it comes to gaming laptops from ASUS, the first thing that comes to mind is Republic of Gamers. But in addition to the high-end gaming laptops in the Republic of Gamers, ASUS also has mainstream gaming laptops in the Flying Fortress series. Let’s take a look at them together. How about ASUS Flying Fortress 7, which is the most popular among gamers. ASUS Flying Fortress 7 ASUS' Flying Fortress series notebooks are positioned to play large-scale games easily. They focus on sturdiness and durability. They have always been a popular choice among gamers and students. Basic configuration First, let’s take a look at some of the core configurations of this Flying Fortress 7. From the configuration table, the most noteworthy is AMD Ryzen73750H+NVIDIA GeForceGTX1660Ti
