- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不太熟悉 Redis
.目前我正在设计一些实时服务,我想依赖它。我预计每分钟 ~10000-50000 个 key 是 SET
有一些合理的EX
并使用 SCAN
匹配它们很少足以不打扰性能瓶颈。
我怀疑的是“输入/输出速率”以及可能与某些匹配的键的溢出 SCAN
查询,因此它永远不会终止(即总是用最新的光标位置回复并强制您继续;如果使用 x items per second
并且有 x + y items per second coming in
和 y > 0
,这很容易发生)。
显然,我可以设置所需的 SCAN
尺寸足够长;但我想知道是否存在更好的解决方案或Redis
本身保证SCAN
在这种情况下会自动增加大小吗?
最佳答案
首先是一些上下文,最后是 解决方案 :
来自 SCAN command > Guarantee of termination
The SCAN algorithm is guaranteed to terminate only if the size of the iterated collection remains bounded to a given maximum size, otherwise iterating a collection that always grows may result into SCAN to never terminate a full iteration.
This is easy to see intuitively: if the collection grows there is more and more work to do in order to visit all the possible elements, and the ability to terminate the iteration depends on the number of calls to SCAN and its COUNT option value compared with the rate at which the collection grows.
Important: there is no need to use the same COUNT value for every iteration. The caller is free to change the count from one iteration to the other as required, as long as the cursor passed in the next call is the one obtained in the previous call to the command.
- A given element may be returned multiple times. It is up to the application to handle the case of duplicated elements, for example only using the returned elements in order to perform operations that are safe when re-applied multiple times.
- Elements that were not constantly present in the collection during a full iteration, may be returned or not: it is undefined.
DBSIZE
或
INFO keyspace
命令,您可以随时获取您拥有的 key 数量:
> DBSIZE
(integer) 200032
> info keyspace
# Keyspace
db0:keys=200032,expires=0,avg_ttl=0
DEBUG htstats index
,只是为了感受一下:
> DEBUG htstats 0
[Dictionary HT]
Hash table 0 stats (main hash table):
table size: 262144
number of elements: 200032
different slots: 139805
max chain length: 8
avg chain length (counted): 1.43
avg chain length (computed): 1.43
Chain length distribution:
0: 122339 (46.67%)
1: 93163 (35.54%)
2: 35502 (13.54%)
3: 9071 (3.46%)
4: 1754 (0.67%)
5: 264 (0.10%)
6: 43 (0.02%)
7: 6 (0.00%)
8: 2 (0.00%)
[Expires HT]
No stats available for empty dictionaries
COUNT
参数。
F
单位为 Hz)调用 SCAN,并且您希望在 5 秒内完成(
T
单位为 s)。因此,您希望在
N = F*T
调用中完成此操作,在此示例中为
N = 50
。
RP = 1
(100%)。
SCAN
调用之前(或者,如果您想保存
DBSIZE
调用的往返时间 (RTT),那么您想要调整 COUNT 的每个给定调用次数),您调用
DBSIZE
以获取
K
键的数量。
COUNT = K*RP/N
COUNT = 200032*1/50 = 4000
。
RP = 1 - ReversedCursor/NextPowerOfTwo(K)
。
N = 30
(剩余调用次数)。你调用
DBSIZE
并得到
K = 281569
。这意味着
NextPowerOfTwo(K) = 524288
,这是 2^19。
000011100010101101
。由于表大小为 2^19,我们用 18 位表示。
101101010001110000
= 185456 的十进制。这意味着我们已经涵盖了 524288 个中的 185456 个。并且:
RP = 1 - ReversedCursor/NextPowerOfTwo(K) = 1 - 185456 / 524288 = 0.65 or 65%
COUNT = K*RP/N = 281569 * 0.65 / 30 = 6100
SCAN
调用中,您使用
6100
。它增加是有道理的,因为:
PM
(匹配百分比)作为因子添加到
COUNT
计算中。
COUNT = PM * K*RP/N
PM = keysFound / ( K * ReversedCursor/NextPowerOfTwo(K))
keysFound = 2000
键,则:
PM = 2000 / ( 281569 * 185456 / 524288) = 0.02
COUNT = PM * K*RP/N = 0.02 * 6100 = 122
COUNT
编号上运行一些基准测试,以测量您的
SCAN
占用了多少毫秒,因为您可能需要降低对需要多少调用 (
N
) 的期望合理的时间而不阻塞服务器,并相应地调整您的
F
和
T
。
关于Redis `SCAN` : how to maintain a balance between newcomming keys that might match and ensure eventual result in a reasonable time?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59564896/
我正在使用扫描仪检测设备。目前,我的条形码的值为 2345345 A1。因此,当我扫描到记事本或文本编辑器时,输出将类似于 2345345 A1,这是正确的条形码值。 问题是: 当我第一次将条形码扫描
我正在尝试在 Jenkins 的构建后部分运行 Checkmarx Scan。 在我的 Jenkins 工作步骤是--> 1st) 从 SVN Connection 获取源代码到 Checkmarx
我有以下表架构 - CREATE TABLE [dbo].[TEST_TABLE] ( [TEST_TABLE_ID] [int] IDENTITY(1,1) NOT NULL, [N
我有一个关于 postgres 表上的选择的有趣案例: advert (~2.5 million records) id serial, user_id integer (foreig
据我所知,context:component-scan 需要指定 base-package 属性。我如何配置它以扫描类路径中的所有类? 最佳答案 你不知道。那将是一场噩梦。 例如,这意味着加载所有库的
我正在测试不同的查询,我很好奇数据库如何决定使用位图堆扫描和索引扫描。 create index customers_email_idx on customers(email varchar_patt
我在使用中 Swing 不定 import java.util.Scanner; . . . Scanner scan = new Scanner(System.in); . . . Integer.
我有下表 create table log ( id bigint default nextval('log_id_seq'::regclass) not null const
所以我有一个文件要读入,我知道数据将如何列出。例如,我知道每个新行的第一个标记将是 double 。 我一直在使用 Scanner 并且只是使用 scan.nextDouble() 来读取 doubl
在这种情况下,该表有很多文本列,我需要对每一列执行(相似)搜索。我继续为这些列中的每一列创建一个 gin 索引(扩展 pg_trgm 中的 gin_trgm_ops)以加快搜索速度,实际上 yie
我有两个针对 Go 中特定表的查询 - 一个用于检索单个项目,另一个用于返回列表。第一个使用 sql.DB.QueryRow 因为它只需要检索一行,第二个使用 sql.DB.Query 返回几个不同的
添加 StructureMap-MVC3 时打包到 ASP.NET MVC 应用程序, 一个 IoC包含 Initialize 的类添加了包含以下内容的方法(由 App_Start 文件夹中的某些代码
我有以下索引: CREATE INDEX index_c_profiles_on_city_state_name_domain ON c_profiles ((data->>'state'), (da
我在 Postgres 10 中有一个包含 1700 万行和 102 列的表 union_events。我运行命令: CREATE INDEX union_events_index ON temp_s
我以为我知道 Ruby 中的 scan:就好像它在做一个单一的匹配,但对所有结果重复它并放入数组? ruby-1.9.2-p0 > "hello world".scan(/\w{2}/) => ["
我收到此错误并尝试了互联网和 stackoverlow 中可用的所有方法来解决此问题。我试图在使用 sqlx 包连接 MySQL 数据库并扫描结果后运行查询。我已经尝试过针对类似问题共享的解决方案,但
我是 spring 和 Maven 的新手。最近我构建了 spring MVC 项目并使用 maven 来管理项目结构和依赖项。 当我编写单元测试时,我遇到了一个问题,即我无法从“src/main/j
我现在正在尝试 restful api,其中列 SequenceID 不是自动增量,因为故意的,当我像这样计数时,我的问题是库 gorm countSequenceId := db.Debug().T
Scans 当客户端针对表发出扫描时,HBase会为每个区域生成一个RegionScanner对象来提供扫描请求。 该RegionScanner对象包含一个StoreScanner对象列表
我正在构建一个基于浏览器的文档扫描应用程序。我看过多家供应商提供的产品,如 dynamosoft、asprise、atalasoft 等。我对基于浏览器的文档扫描的基本问题是,这些产品中的任何一个都可
我是一名优秀的程序员,十分优秀!