Skip to content

Commit 88e60a2

Browse files
authored
perf(db) yield on DB-less daos methods
### Summary DBless doesn't naturally yield (not with `shared dict`, nor with `lmdb`). This may cause latency spikes when iterating over bigger lists, e.g. `kong.db.routes:each()`. This commit adds some yields so that iterating doesn't fully block the worker from doing other work too, so this is about cooperative multitasking.
1 parent 86f67e5 commit 88e60a2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

kong/db/strategies/off/init.lua

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local declarative_config = require "kong.db.schema.others.declarative_config"
22
local workspaces = require "kong.workspaces"
33
local lmdb = require("resty.lmdb")
44
local marshaller = require("kong.db.declarative.marshaller")
5-
5+
local yield = require("kong.tools.utils").yield
66

77

88
local kong = kong
@@ -61,6 +61,8 @@ local function get_entity_ids_tagged(key, tag_names, tags_cond)
6161
return nil, err
6262
end
6363

64+
yield(true)
65+
6466
list = list or {}
6567

6668
if i > 1 and tags_cond == "and" then
@@ -141,6 +143,8 @@ local function page_for_key(self, key, size, offset, options)
141143
list = list or {}
142144
end
143145

146+
yield()
147+
144148
local ret = {}
145149
local schema_name = self.schema.name
146150

@@ -152,6 +156,8 @@ local function page_for_key(self, key, size, offset, options)
152156
break
153157
end
154158

159+
yield(true)
160+
155161
-- Tags are stored in the cache entries "tags||@list" and "tags:<tagname>|@list"
156162
-- The contents of both of these entries is an array of strings
157163
-- Each of these strings has the form "<tag>|<entity_name>|<entity_id>"

0 commit comments

Comments
 (0)