如何在Ubuntu 18.04上对Redis服务器的性能进行基准测试

介绍 (Introduction)

Benchmarking is an important practice when it comes to analyzing the overall performance of database servers. It’s helpful for identifying bottlenecks as well as opportunities for improvement within those systems.

在分析数据库服务器的整体性能时,基准测试是一项重要的实践。 这对于识别瓶颈以及这些系统中的改进机会很有帮助。

Redis is an in-memory data store that can be used as database, cache and message broker. It supports from simple to complex data structures including hashes, strings, sorted sets, bitmaps, geospatial data, among other types. In this guide, we’ll demonstrate how to benchmark the performance of a Redis server running on Ubuntu 18.04, using a few different tools and methods.

Redis是一种内存数据存储,可用作数据库,缓存和消息代理。 它支持从简单到复杂的数据结构,包括哈希,字符串,排序集,位图,地理空间数据等。 在本指南中,我们将演示如何使用一些不同的工具和方法对在Ubuntu 18.04上运行的Redis服务器的性能进行基准测试。

先决条件 (Prerequisites)

To follow this guide, you’ll need:

要遵循本指南,您需要:

Note: The commands demonstrated in this tutorial were executed on a dedicated Redis server running on a 4GB DigitalOcean Droplet.

注意:本教程中演示的命令是在运行于4GB DigitalOcean Droplet上的专用Redis服务器上执行的。

使用随附的redis-benchmark工具 (Using the Included redis-benchmark Tool)

Redis comes with a benchmark tool called redis-benchmark. This program can be used to simulate an arbitrary number of clients connecting at the same time and performing actions on the server, measuring how long it takes for the requests to be completed. The resulting data will give you an idea of the average number of requests that your Redis server is able to handle per second.

Redis带有一个称为redis-benchmark的基准测试工具。 此程序可用于模拟同时连接的任意数量的客户端并在服务器上执行操作,从而测量完成请求所花费的时间。 结果数据将使您大致了解Redis服务器每秒能够处理的平均请求数。

The following list details some of the common command options used with redis-benchmark:

以下列表详细介绍了与redis-benchmark一起使用的一些常用命令选项:

  • -h: Redis host. Default is 127.0.0.1.

    -h :Redis主机。 默认值为127.0.0.1

  • -p: Redis port. Default is 6379.

    -p :Redis端口。 默认值为6379

  • -a: If your server requires authentication, you can use this option to provide the password.

    -a :如果服务器需要身份验证,则可以使用此选项来提供密码。

  • -c: Number of clients (parallel connections) to simulate. Default value is 50.

    -c :要模拟的客户端数量(并行连接)。 预设值为50。

  • -n: How many requests to make. Default is 100000.

    -n :发出多少个请求。 默认值为100000。

  • -d: Data size for SET and GET values, measured in bytes. Default is 3.

    -dSETGET值的数据大小,以字节为单位。 默认值为3。

  • -t: Run only a subset of tests. For instance, you can use -t get,set to benchmark the performance of GET and SET commands.

    -t :仅运行测试的子集。 例如,您可以使用-t get,set基准测试GETSET命令的性能。

  • -P: Use pipelining for performance improvements.

    -P :使用流水线来提高性能。

  • -q: Quiet mode, shows only the average requests per second information.

    -q :安静模式,仅显示每秒平均请求数的信息。

For instance, if you want to check the average number of requests per second that your local Redis server can handle, you can use:

例如,如果要检查本地Redis服务器每秒可以处理的平均请求数,则可以使用:

  • redis-benchmark -q

    redis基准-q

You will get output similar to this, but with different numbers:

您将获得与此类似的输出,但具有不同的数字:


   
   
Output
PING_INLINE: 85178.88 requests per second PING_BULK: 83056.48 requests per second SET: 72202.16 requests per second GET: 94607.38 requests per second INCR: 84961.77 requests per second LPUSH: 78988.94 requests per second RPUSH: 88652.48 requests per second LPOP: 87950.75 requests per second RPOP: 80971.66 requests per second SADD: 80192.46 requests per second HSET: 84317.03 requests per second SPOP: 78125.00 requests per second LPUSH (needed to benchmark LRANGE): 84175.09 requests per second LRANGE_100 (first 100 elements): 52383.45 requests per second LRANGE_300 (first 300 elements): 21547.08 requests per second LRANGE_500 (first 450 elements): 14471.78 requests per second LRANGE_600 (first 600 elements): 9383.50 requests per second MSET (10 keys): 71225.07 requests per second

You can also limit the tests to a subset of commands of your choice using the -t parameter. The following command shows the averages for the GET and SET commands only:

您还可以使用-t参数将测试限制为所选命令的子集。 以下命令仅显示GETSET命令的平均值:

  • redis-benchmark -t set,get -q

    redis-benchmark -t设置,获取 -q


   
   
Output
SET: 76687.12 requests per second GET: 82576.38 requests per second

The default options will use 50 parallel connections to create 100000 requests to the Redis server. If you want to increase the number of parallel connections to simulate a peak in usage, you can use the -c option for that:

默认选项将使用50个并行连接来创建对Redis服务器的100000个请求。 如果要增加并行连接的数量以模拟使用高峰,则可以使用-c选项:

  • redis-benchmark -t set,get -q -c 1000

    redis-benchmark -t set,得到-q -c 1000

Because this will use 1000 concurrent connections instead of the default 50, you should expect a decrease in performance:

因为这将使用1000个并发连接,而​​不是默认的50个,所以您应该期望性能下降:


   
   
Output
SET: 69444.45 requests per second GET: 70821.53 requests per second

If you want detailed information in the output, you can remove the -q option. The following command will use 100 parallel connections to run 1000000 SET requests on the server:

如果要在输出中提供详细信息,可以除去-q选项。 以下命令将使用100个并行连接在服务器上运行1000000 SET请求:

  • redis-benchmark -t set -c 100 -n 1000000

    redis基准-t设置-c 100 -n 1000000

You will get output similar to this:

您将获得类似于以下的输出:


   
   
Output
====== SET ====== 1000000 requests completed in 11.29 seconds 100 parallel clients 3 bytes payload keep alive: 1 95.22% <= 1 milliseconds 98.97% <= 2 milliseconds 99.86% <= 3 milliseconds 99.95% <= 4 milliseconds 99.99% <= 5 milliseconds 99.99% <= 6 milliseconds 100.00% <= 7 milliseconds 100.00% <= 8 milliseconds 100.00% <= 8 milliseconds 88605.35 requests per second

The default settings use 3 bytes for key values. You can change this with the option -d. The following command will benchmark GET and SET commands using 1MB key values:

默认设置使用3个字节作为键值。 您可以使用选项-d更改它。 以下命令将使用1MB键值对GETSET命令进行基准测试:

  • redis-benchmark -t set,get -d 1000000 -n 1000 -q

    redis-benchmark -t set,得到-d 1000000 -n 1000 -q

Because the server is working with a much bigger payload this time, a significant decrease of performance is expected:

由于这次服务器使用的负载要大得多,因此预期性能会大大降低:


   
   
Output
SET: 1642.04 requests per second GET: 822.37 requests per second

It is important to realize that even though these numbers are useful as a quick way to evaluate the performance of a Redis instance, they don’t represent the maximum throughput a Redis instance can sustain. By using pipelining, applications can send multiple commands at once in order to improve the number of requests per second the server can handle. With redis-benchmark, you can use the -P option to simulate real world applications that make use of this Redis feature.

重要的是要认识到,即使这些数字可用作评估Redis实例性能的快速方法,但它们并不代表Redis实例可以维持的最大吞吐量。 通过使用流水线 ,应用程序可以一次发送多个命令,以提高服务器每秒可以处理的请求数。 使用redis-benchmark ,您可以使用-P选项来模拟使用此Redis功能的实际应用程序。

To compare the difference, first run the redis-benchmark command with default values and no pipelining, for the GET and SET tests:

为了比较差异,首先对GETSET测试运行带有默认值且没有流水线的redis-benchmark命令:

  • redis-benchmark -t get,set -q

    redis基准-t get,set -q

   
   
Output
SET: 86281.27 requests per second GET: 89847.26 requests per second

The next command will run the same tests, but will pipeline 8 commands together:

下一条命令将运行相同的测试,但会将8条命令一起传送:

  • redis-benchmark -t get,set -q -P 8

    redis基准-t get,set -q -P 8


   
   
Output
SET: 653594.81 requests per second GET: 793650.75 requests per second

As you can see from the output, there is a substantial performance improvement with the use of pipelining.

从输出中可以看到,使用流水线可以显着提高性能。

使用redis-cli检查延迟 (Checking Latency with redis-cli)

If you’d like a simple measurement of the average time a request takes to receive a response, you can use the Redis client to check for the average server latency. In the context of Redis, latency is a measure of how long does a ping command take to receive a response from the server.

如果您想简单地衡量请求接收响应所花费的平均时间,则可以使用Redis客户端检查平均服务器延迟。 在Redis的上下文中,延迟是ping命令从服务器接收响应所花费的时间的度量。

The following command will show real-time latency stats for your Redis server:

以下命令将显示您的Redis服务器的实时延迟状态:

  • redis-cli --latency

    redis-cli-延迟

You’ll get output similar to this, showing an increasing number of samples and a variable average latency:

您将获得与此类似的输出,显示出越来越多的样本和可变的平均延迟:


   
   
Output
min: 0, max: 1, avg: 0.18 (970 samples)

This command will keep running indefinitely. You can stop it with a CTRL+C.

此命令将无限期运行。 您可以使用CTRL+C停止它。

To monitor latency over a certain period of time, you can use:

要监视特定时间段内的延迟,可以使用:

  • redis-cli --latency-history

    redis-cli-延迟历史

This will track latency averages over time, with a configurable interval that is set to 15 seconds by default. You will get output similar to this:

这将跟踪一段时间内的平均延迟,默认情况下可配置的间隔设置为15秒。 您将获得类似于以下的输出:


   
   
Output
min: 0, max: 1, avg: 0.18 (1449 samples) -- 15.01 seconds range min: 0, max: 1, avg: 0.16 (1449 samples) -- 15.00 seconds range min: 0, max: 1, avg: 0.17 (1449 samples) -- 15.00 seconds range min: 0, max: 1, avg: 0.17 (1444 samples) -- 15.01 seconds range min: 0, max: 1, avg: 0.17 (1446 samples) -- 15.01 seconds range min: 0, max: 1, avg: 0.17 (1449 samples) -- 15.00 seconds range min: 0, max: 1, avg: 0.16 (1444 samples) -- 15.00 seconds range min: 0, max: 1, avg: 0.17 (1445 samples) -- 15.01 seconds range min: 0, max: 1, avg: 0.16 (1445 samples) -- 15.01 seconds range ...

Because the Redis server on our example is idle, there’s not much variation between latency samples. If you have a peak in usage, however, this should be reflected as an increase in latency within the results.

由于本例中的Redis服务器处于空闲状态,因此延迟样本之间的差异不大。 但是,如果使用高峰,则应反映为结果延迟增加。

If you’d like to measure the system latency only, you can use --intrinsic-latency for that. The intrinsic latency is inherent to the environment, depending on factors such as hardware, kernel, server neighbors and other factors that aren’t controlled by Redis.

如果您只想测量系统延迟,则可以使用--intrinsic-latency 。 固有延迟是环境固有的,具体取决于硬件,内核,服务器邻居等因素以及不受Redis控制的其他因素。

You can see the intrinsic latency as a baseline for your overall Redis performance. The following command will check for the intrinsic system latency, running a test for 30 seconds:

您可以将固有延迟视为整体Redis性能的基准。 以下命令将检查内部系统延迟,并运行30秒的测试:

  • redis-cli --intrinsic-latency 30

    redis-cli-固有延迟30

You should get output similar to this:

您应该获得类似于以下的输出:


   
   
Output
… 498723744 total runs (avg latency: 0.0602 microseconds / 60.15 nanoseconds per run). Worst run took 22975x longer than the average latency.

Comparing both latency tests can be helpful for identifying hardware or system bottlenecks that could affect the performance of your Redis server. Considering the total latency for a request to our example server has an average of 0.18 microseconds to complete, an intrinsic latency of 0.06 microseconds means that one third of the total request time is spent by the system in processes that aren’t controlled by Redis.

比较这两个延迟测试有助于确定可能影响Redis服务器性能的硬件或系统瓶颈。 考虑到对我们的示例服务器的请求的总等待时间平均为0.18微秒,因此0.06微秒的固有等待时间意味着,总请求时间的三分之一由系统花费在不受Redis控制的进程中。

使用Memtier基准工具 (Using the Memtier Benchmark Tool)

Memtier is a high-throughput benchmark tool for Redis and Memcached created by Redis Labs. Although very similar to redis-benchmark in various aspects, Memtier has several configuration options that can be tuned to better emulate the kind of load you might expect on your Redis server, in addition to offering cluster support.

Memtier是Redis Labs创建的Redis和Memcached的高吞吐量基准测试工具。 尽管Memtier在各个方面与redis-benchmark非常相似,但除了提供集群支持之外,Memtier还可以调整几个配置选项以更好地模拟您在Redis服务器上可能期望的负载类型。

To get Memtier installed on your server, you’ll need to compile the software from source. First, install the dependencies necessary to compile the code:

要在服务器上安装Memtier,您需要从源代码编译软件。 首先,安装编译代码所需的依赖项:

  • sudo apt-get install build-essential autoconf automake libpcre3-dev libevent-dev pkg-config zlib1g-dev

    sudo apt-get install build-essential autoconf automake libpcre3-dev libevent-dev pkg-config zlib1g-dev

Next, go to your home directory and clone the memtier_benchmark project from its Github repository:

接下来,转到您的主目录,并从其Github存储库中克隆memtier_benchmark项目:

  • cd

    光盘
  • git clone https://github.com/RedisLabs/memtier_benchmark.git

    git clone https://github.com/RedisLabs/memtier_benchmark.git

Navigate to the project directory and run the autoreconf command to generate the application configuration scripts:

导航到项目目录并运行autoreconf命令以生成应用程序配置脚本:

  • cd memtier_benchmark

    cd memtier_benchmark
  • autoreconf -ivf

    autoreconf -ivf

Run the configure script in order to generate the application artifacts required for compiling:

运行configure脚本以生成编译所需的应用程序工件:

  • ./configure

    。/配置

Now run make to compile the application:

现在运行make来编译应用程序:

  • make

    使

Once the build is finished, you can test the executable with:

构建完成后,您可以使用以下命令测试可执行文件:

  • ./memtier_benchmark --version

    ./memtier_benchmark --version

This will give you the following output:

这将为您提供以下输出:


   
   
Output
memtier_benchmark 1.2.17 Copyright (C) 2011-2017 Redis Labs Ltd. This is free software. You may redistribute copies of it under the terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law.

The following list contains some of the most common options used with the memtier_benchmark command:

以下列表包含与memtier_benchmark命令一起使用的一些最常见的选项:

  • -s: Server host. Default is localhost.

    -s :服务器主机。 默认值为localhost

  • -p: Server port. Default is 6379.

    -p :服务器端口。 默认值为6379

  • -a: Authenticate requests using the provided password.

    -a :使用提供的密码对请求进行身份验证。

  • -n: Number of requests per client (default is 10000).

    -n :每个客户端的请求数(默认为10000)。

  • -c: Number of clients (default is 50).

    -c :客户端数量(默认为50)。

  • -t: Number of threads (default is 4).

    -t :线程数(默认为4)。

  • --pipeline: Enable pipelining.

    --pipeline :启用流水线。

  • --ratio: Ratio between SET and GET commands, default is 1:10.

    --ratioSETGET命令之间的比率,默认为1:10。

  • --hide-histogram: Hides detailed output information.

    --hide-histogram :隐藏详细的输出信息。

Most of these options are very similar to the options present in redis-benchmark, but Memtier tests performance in a different way. To simulate common real-world environments better, the default benchmark performed by memtier_benchmark will test for GET and SET requests only, on a ratio of 1 to 10. With 10 GET operations for each SET operation in the test, this arrangement is more representative of a common web application using Redis as a database or cache. You can adjust the ratio value with the option --ratio.

这些选项中的大多数与redis-benchmark提供的选项非常相似,但是Memtier以不同的方式测试性能。 为了更好地模拟常见的现实环境,由memtier_benchmark执行的默认基准将memtier_benchmark测试GETSET请求,比例为1到10。测试中每个SET操作使用10个GET操作,这种安排更能代表使用Redis作为数据库或缓存的常见Web应用程序。 您可以使用选项--ratio来调整比率值。

The following command runs memtier_benchmark with default settings, while providing only high-level output information:

以下命令以默认设置运行memtier_benchmark ,同时仅提供高级输出信息:

  • ./memtier_benchmark --hide-histogram

    ./memtier_benchmark-隐藏直方图

Note: if you have configured your Redis server to require authentication, you should provide the -a option along with your Redis password to the memtier_benchmark command:

注意 :如果已将Redis服务器配置为需要身份验证,则应将-a选项和Redis密码一起提供给memtier_benchmark命令:

  • ./memtier_benchmark --hide-histogram -a your_redis_password

    ./memtier_benchmark-隐藏直方图-a your_redis_password

You’ll see output similar to this:

您将看到类似于以下的输出:


   
   
Output
... 4 Threads 50 Connections per thread 10000 Requests per client ALL STATS ========================================================================= Type Ops/sec Hits/sec Misses/sec Latency KB/sec ------------------------------------------------------------------------- Sets 8258.50 --- --- 2.19800 636.05 Gets 82494.28 41483.10 41011.18 2.19800 4590.88 Waits 0.00 --- --- 0.00000 --- Totals 90752.78 41483.10 41011.18 2.19800 5226.93

According to this run of memtier_benchmark, our Redis server can execute about 90 thousand operations per second in a 1:10 SET/GET ratio.

根据这次的memtier_benchmark运行,我们的Redis服务器可以以1:10的SET / GET比率每秒执行约9万次操作。

It’s important to note that each benchmark tool has its own algorithm for performance testing and data presentation. For that reason, it’s normal to have slightly different results on the same server, even when using similar settings.

重要的是要注意,每个基准测试工具都有其自己的性能测试和数据表示算法。 因此,即使在使用相似设置的情况下,在同一台服务器上获得略有不同的结果也是正常的。

结论 (Conclusion)

In this guide, we demonstrated how to perform benchmark tests on a Redis server using two distinct tools: the included redis-benchmark, and the memtier_benchmark tool developed by Redis Labs. We also saw how to check for the server latency using redis-cli. Based on the data obtained from these tests, you’ll have a better understanding of what to expect from your Redis server in terms of performance, and what are the bottlenecks of your current setup.

在本指南中,我们演示了如何使用两个不同的工具在Redis服务器上执行基准测试:包括的redis-benchmark和Redis Labs开发的memtier_benchmark工具。 我们还看到了如何使用redis-cli检查服务器延迟。 根据从这些测试获得的数据,您将更好地了解Redis服务器在性能方面的期望以及当前设置的瓶颈。

翻译自: https://www.digitalocean.com/community/tutorials/how-to-perform-redis-benchmark-tests

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值