-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cache-locks #1402
Merged
Merged
cache-locks #1402
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ lua_shared_dict cache ${{MEM_CACHE_SIZE}}; | |
lua_shared_dict reports_locks 100k; | ||
lua_shared_dict cluster_locks 100k; | ||
lua_shared_dict cluster_autojoin_locks 100k; | ||
lua_shared_dict cache_locks 100k; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do not need so many different |
||
lua_shared_dict cassandra 1m; | ||
lua_shared_dict cassandra_prepared 5m; | ||
lua_socket_log_errors off; | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
local helpers = require "spec.helpers" | ||
local cjson = require "cjson" | ||
local meta = require "kong.meta" | ||
|
||
describe("Resolver", function() | ||
local client | ||
setup(function() | ||
|
||
assert(helpers.dao.apis:insert { | ||
request_host = "mockbin.com", | ||
upstream_url = "http://mockbin.com" | ||
}) | ||
|
||
assert(helpers.start_kong({ | ||
["custom_plugins"] = "database-cache", | ||
lua_package_path = "?/init.lua;./kong/?.lua;./spec/fixtures/?.lua" | ||
})) | ||
|
||
-- Add the plugin | ||
local admin_client = helpers.admin_client() | ||
local res = assert(admin_client:send { | ||
method = "POST", | ||
path = "/apis/mockbin.com/plugins/", | ||
body = { | ||
name = "database-cache" | ||
}, | ||
headers = { | ||
["Content-Type"] = "application/json" | ||
} | ||
}) | ||
assert.res_status(201, res) | ||
admin_client:close() | ||
end) | ||
|
||
teardown(function() | ||
helpers.stop_kong() | ||
end) | ||
|
||
it("avoids dog-pile effect", function() | ||
local function make_request(premature, sleep_time) | ||
local client = helpers.proxy_client() | ||
local res = assert(client:send { | ||
method = "GET", | ||
path = "/status/200?sleep="..sleep_time, | ||
headers = { | ||
["Host"] = "mockbin.com" | ||
} | ||
}) | ||
res:read_body() | ||
client:close() | ||
end | ||
|
||
assert(ngx.timer.at(0, make_request, 2)) | ||
assert(ngx.timer.at(0, make_request, 5)) | ||
assert(ngx.timer.at(0, make_request, 1)) | ||
|
||
helpers.wait_until(function() | ||
local admin_client = helpers.admin_client() | ||
local res = assert(admin_client:send { | ||
method = "GET", | ||
path = "/cache/invocations" | ||
}) | ||
local body = res:read_body() | ||
admin_client:close() | ||
return cjson.decode(body).message == 3 | ||
end, 10) | ||
|
||
-- Invocation are 3, but lookups should be 1 | ||
local admin_client = helpers.admin_client() | ||
local res = assert(admin_client:send { | ||
method = "GET", | ||
path = "/cache/lookups" | ||
}) | ||
local body = res:read_body() | ||
admin_client:close() | ||
assert.equal(1, cjson.decode(body).message) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
local BasePlugin = require "kong.plugins.base_plugin" | ||
local cache = require "kong.tools.database_cache" | ||
|
||
local INVOCATIONS = "invocations" | ||
local LOOKUPS = "lookups" | ||
|
||
local DatabaseCacheHandler = BasePlugin:extend() | ||
|
||
DatabaseCacheHandler.PRIORITY = 1000 | ||
|
||
function DatabaseCacheHandler:new() | ||
DatabaseCacheHandler.super.new(self, "database-cache") | ||
end | ||
|
||
function DatabaseCacheHandler:init_worker() | ||
DatabaseCacheHandler.super.init_worker(self) | ||
|
||
cache.rawset(INVOCATIONS, 0) | ||
cache.rawset(LOOKUPS, 0) | ||
end | ||
|
||
function DatabaseCacheHandler:access(conf) | ||
DatabaseCacheHandler.super.access(self) | ||
|
||
cache.get_or_set("pile_effect", function() | ||
cache.incr(LOOKUPS, 1) | ||
-- Adds some delay | ||
ngx.sleep(tonumber(ngx.req.get_uri_args().sleep)) | ||
return true | ||
end) | ||
|
||
cache.incr(INVOCATIONS, 1) | ||
end | ||
|
||
return DatabaseCacheHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
return { | ||
fields = {} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
err
variable will tell what the error is. Should be"could not create lock: "