【问题标题】:How to increase REDIS CPU usage如何增加 REDIS CPU 使用率
【发布时间】:2016-08-18 11:59:03
【问题描述】:

您好,我在 nodejs 中使用 redis 并尝试使用 jmeter 执行 redis 命令。

cpu 使用率不超过 5%,我尝试增加负载,然后 cpu 使用率不超过 5%。 当我尝试使用默认基准测试时,cpu 使用率达到 50%。

你能帮我把redis的cpu利用率最大化吗

这是我的 jmx 文件

jmx file

这是我的 nodejs 程序 var express = require('express'); var app = express();

var redis = require("redis"),
//client = redis.createClient(6379,"10.96.82.163");
client = redis.createClient(6379,"10.96.82.175");




app.get('/', function (req, res) {


          res.send("HEY  Nodejs runnning on 10.96.82.175:4000");

});
app.put('/set/:arg1/:arg2', function (req, res) {

      client.set( req.params.arg1,req.params.arg2,function (err, reply) {
        if (reply==null)
        {
          res.send("null");
        }
        else {
          res.send(reply.toString());
        }

      });
});


app.get('/get/:arg1', function (req, res) {
      client.get( req.params.arg1,function (err, reply) {

        if (reply==null)
        {
          res.send("null");
        }
        else {
          res.send(reply.toString());
        }

      });
});






app.get('/incr/:arg1', function (req, res) {
      client.incr(req.params.arg1, function (err, reply) {
        if (reply==null)
        {
          res.send("null");
        }
        else {
          res.send(reply.toString());
        }

          //console.log(reply.toString());
      });
});





app.put('/lpush/:arg1/:arg2', function (req, res) {
  client.lpush(req.params.arg1,req.params.arg2, function (err, reply) {
    if (reply==null)
    {
      res.send("null");
    }
    else {
      res.send(reply.toString());
    }

          //console.log(reply.toString());
      });
});



app.get('/lpop/:arg1', function (req, res) {
  client.lpop(req.params.arg1, function (err, reply) {

    if (reply==null)
    {
      res.send("null");
    }
    else {
      res.send(reply.toString());
    }
      });
});



app.put('/sadd/:arg1/:arg2', function (req, res) {
  client.sadd(req.params.arg1,req.params.arg2, function (err, reply) {
    if (reply==null)
    {
      res.send("null");
    }
    else {
      res.send(reply.toString());
    }
          //console.log(reply.toString());
      });
});




app.get('/spop/:arg1', function (req, res) {
  client.spop(req.params.arg1,1, function (err, reply) {

    if (reply==null)
    {
      res.send("null");
    }
    else {
      res.send(reply.toString());
    }
          //console.log(reply.toString());
      });
});


app.put('/zadd/:arg1/:arg2/:arg3', function (req, res) {
  client.zadd(req.params.arg1,req.params.arg2,req.params.arg3,function (err, reply) {
    if (reply==null)
    {
      res.send("null");
    }
    else {
      res.send(reply.toString());
    }
          //console.log(reply.toString());
      });
});


app.put('/hset/:arg1/:arg2/:arg3', function (req, res) {
      client.hset(req.params.arg1,req.params.arg2,req.params.arg3,function (err, reply) {
        if (reply==null)
        {
          res.send("null");
        }
        else {
          res.send(reply.toString());
        }
          //console.log(reply.toString());
      });
});




app.get('/hget/:arg1/:arg2', function (req, res) {

      client.hget(req.params.arg1,req.params.arg2,function (err, reply) {

        if (reply==null)
        {
          res.send("null");
        }
        else {
          res.send(reply.toString());
        }
          //console.log(reply);
      });
});


app.listen(4000, function () {

  console.log('Example app listening on port 4000!');
});

【问题讨论】:

  • 只是用无限的插入和读取向它发送垃圾邮件?你也可以试试这个:redis.io/topics/benchmarks
  • 我正在使用 redis-stat 进行监控,而对于负载测试,我正在使用 jmeter
  • 你能给你看看 JMeter 测试计划吗?澄清你是如何进行负载测试的?多少线程? GUI / 非 GUI ....

标签: node.js performance redis jmeter load-testing


【解决方案1】:

您可以使用默认的 redis 查询来了解 CPU 使用率

试试这个查询来检查你redis的cpu使用情况

         redis-cli INFO


redis> INFO
# Server
redis_version:999.999.999
redis_git_sha1:ceaf58df
redis_git_dirty:1
redis_build_id:a5eeeb464ee54856
redis_mode:standalone
os:Linux 4.1.5-x86_64-linode61 x86_64
arch_bits:32
multiplexing_api:epoll
gcc_version:4.4.1
process_id:21798
run_id:2569bb7433bfe013c2627edf62d9bf21eaf8a010
tcp_port:6379
uptime_in_seconds:14657590
uptime_in_days:169
hz:10
lru_clock:11800083
config_file:/etc/redis/6379.conf

# Clients
connected_clients:8
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:7452400
used_memory_human:7.11M
used_memory_rss:10383360
used_memory_rss_human:9.90M
used_memory_peak:8370272
used_memory_peak_human:7.98M
total_system_memory:4142215168
total_system_memory_human:3.86G
used_memory_lua:24576
used_memory_lua_human:24.00K
maxmemory:3221225472
maxmemory_human:3.00G
maxmemory_policy:unknown
mem_fragmentation_ratio:1.39
mem_allocator:jemalloc-3.6.0
lazyfree_pending_objects:0

# Persistence
loading:0
rdb_changes_since_last_save:523
rdb_bgsave_in_progress:0
rdb_last_save_time:1471417783
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok

# Stats
total_connections_received:5182
total_commands_processed:88168233
instantaneous_ops_per_sec:14
total_net_input_bytes:6664442907
total_net_output_bytes:8760305877
instantaneous_input_kbps:1.12
instantaneous_output_kbps:0.07
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:96738
evicted_keys:0
keyspace_hits:22092056
keyspace_misses:6172004
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:536
migrate_cached_sockets:0

# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

# CPU
used_cpu_sys:11952.80
used_cpu_user:10508.02
used_cpu_sys_children:247.59
used_cpu_user_children:5335.29

# Cluster
cluster_enabled:0

# Keyspace
db0:keys=2917,expires=3,avg_ttl=84137679668
redis> 

从这里你可以得到准确的 redis CPU 使用率。即使你的 CPU 使用率较低,我们也可以从 redis 配置文件中修改它。

【讨论】:

  • 试试这个,让我知道实际的CPU使用率。之后我们可以修改redis配置文件
猜你喜欢
  • 1970-01-01
  • 2010-09-21
  • 1970-01-01
  • 2021-06-23
  • 2011-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-27
相关资源
最近更新 更多