Skip to content

Commit

Permalink
perf(db) yield on DB-less daos methods
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
bungle authored May 17, 2022
1 parent 86f67e5 commit 88e60a2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion kong/db/strategies/off/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local declarative_config = require "kong.db.schema.others.declarative_config"
local workspaces = require "kong.workspaces"
local lmdb = require("resty.lmdb")
local marshaller = require("kong.db.declarative.marshaller")

local yield = require("kong.tools.utils").yield


local kong = kong
Expand Down Expand Up @@ -61,6 +61,8 @@ local function get_entity_ids_tagged(key, tag_names, tags_cond)
return nil, err
end

yield(true)

list = list or {}

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

yield()

local ret = {}
local schema_name = self.schema.name

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

yield(true)

-- Tags are stored in the cache entries "tags||@list" and "tags:<tagname>|@list"
-- The contents of both of these entries is an array of strings
-- Each of these strings has the form "<tag>|<entity_name>|<entity_id>"
Expand Down

0 comments on commit 88e60a2

Please sign in to comment.