如何确定Redis中Lua脚本的执行时间? [英] How to determine the execution time of a Lua script in Redis?

查看:507
本文介绍了如何确定Redis中Lua脚本的执行时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的Lua脚本要在Redis中运行,我有兴趣获取执行时间.

I have a small Lua script to run in Redis, and I'm interested in getting the execution time.

由于Redis的本质及其Lua实现的原因,我无法在脚本的开始/返回点使用TIME函数,而在返回中包含此信息以进行处理(请参见

Due to the nature of Redis and it's Lua implementation, I cannot use the TIME function at the start/return points of the script, and include this information in the return for processing (See http://redis.io/commands/eval - Scripts as pure functions). This results in an error: (error) ERR Error running script (call to f_a49ed2fea72f1f529843d6024d1515e76e69bcbd): Write commands not allowed after non deterministic commands

我已经搜索了一个我可以进行的函数/调用,该函数/调用将返回上次运行脚本的执行时间,但尚未找到任何内容.

I have searched around for a function/call I could make which will return the execution time of the last run script, but have not found anything yet.

我正在使用PHP和Predis库.虽然我可以从PHP端检查执行时间,但我希望减少传输开销,并找出Lua脚本将阻止访问数据库的时间.如果不需要更改Redis中存储的任何数据,我已经成功地返回了时间,而这些时间大约是PHP报告时间的1/10.

I am using PHP and the Predis Library. While I can check the execution time from PHP side, I wish to remove the transmission overhead and find out how long the Lua script will block access to the database. I have successfully had times returned if I do not need to alter any of the data stored in Redis, and these have been about 1/10th the time PHP reports.

如何确定Redis中Lua脚本的执行时间,而不是通过PHP?

How can I determine the execution time of the Lua script in Redis, and not via PHP?

推荐答案

您可以通过将slowlog-log-slower-than参数更改为0来激活Redis慢日志功能.它将记录所有命令(包括Lua)的执行时间脚本,以及执行时间如何.

You can activate Redis slow log feature, by changing the slowlog-log-slower-than parameter to 0. It will record execution time of ALL commands (including Lua scripts, and whatever the execution time).

慢速日志保存在内存队列中,您必须定期将其转储以收集数据.根据通信量,您可能必须增加slowlog-max-len,以确保赶上您感兴趣的执行时间.

The slow log is kept in an in-memory queue you have to dump on a regular basis to collect data. Depending on the volume of traffic, you may have to increase slowlog-max-len to be sure to catch the execution times you are interested in.

您可以使用 slowlog get命令来转储慢日志.由您自行过滤掉不需要的结果. AFAIK,无法在数据收集时进行过滤(仅保留Lua统计信息).

You can use the slowlog get command to dump the slow log. Up to you to filter out the results you don't need. AFAIK, there is no possibility to filter at data collection time (to keep only Lua statistics).

这篇关于如何确定Redis中Lua脚本的执行时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆