-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat(proxy-cache): support memory-based strategy #5028
Conversation
Could you provide a benchmark between the disk & the memory cache? |
Hi @spacewander I think these two strategies are suitable for different scenarios. It may be difficult to get a reasonable test result. For example: These are suitable for disk strategy,
For memory strategy,
As a result, these two scenarios can compare is small files with hotspots. But Nginx's proxy-cache send cache file requires 2 disk io (One for header part, another for body part), here ignores pagecache because it's uncertain. Maybe the result is already known. In addition, sorry for the limited environment, I cannot finish the benchmark. If someone can help to accomplish this test, I can provide the test steps. Configure proxied server1. generate test files in /home/nginx/data/dd if=/dev/sda of=4k bs=4 count=1024 2. configure location in proxied server server {
listen 1996;
server_name localhost;
location / {
if ($arg_size) {
rewrite .* /${arg_size} break;
}
root /home/nginx/data/;
}
} Configure the APISIXneed to download master branch: https://github.com/agile6v/apisix When testing memory strategy, we need to use this configuration. curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"plugins": {
"proxy-cache": {
"cache_strategy": "memory",
"cache_key": ["$uri", "-cache-id"],
"cache_bypass": ["$arg_bypass"],
"cache_zone": "memory_cache",
"cache_method": ["GET"],
"cache_http_status": [200],
"hide_cache_headers": true,
"no_cache": ["$arg_nocache"]
}
},
"upstream": {
"nodes": {
"127.0.0.1:1996": 1
},
"type": "roundrobin"
},
"uri": "/*"
}' This for disk strategy. curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"plugins": {
"proxy-cache": {
"cache_strategy": "disk",
"cache_key": ["$uri", "-cache-id"],
"cache_bypass": ["$arg_bypass"],
"cache_zone": "disk_cache_one",
"cache_method": ["GET"],
"cache_http_status": [200],
"hide_cache_headers": true,
"no_cache": ["$arg_nocache"]
}
},
"upstream": {
"nodes": {
"127.0.0.1:1996": 1
},
"type": "roundrobin"
},
"uri": "/*"
}' Verify the configurationcurl -v -o /dev/null http://127.0.0.1:9080/hello?size=4k Benckmark tool use wrk./wrk http://127.0.0.1:9080 -s scripts/random_url.lua random_url.lua contains the following code. math.randomseed(os.time())
function Random(n)
local t = {
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
}
local s = ""
for i =1, n do
s = s .. t[math.random(#t)]
end;
return s
end
local arg_size = "?size=4k"
request = function()
return wrk.format("GET", "/" .. Random(3) .. arg_size)
end{}
|
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.
Please merge master to make Chaos test pass
There is still CI failure: https://github.com/apache/apisix/runs/3719358180 |
@shuaijinchao |
good feature. I benchmarked this PR. In most scenarios, disk cache is better than shared memory cache. |
Good work. Is WRK and APISIX on the same machine? If the machine memory is too small, SWAP will be used and pls take a look at the MISS ratio. Could you use the larger memory machine to test? Thanks. |
Would you provide your own benchmark? It would satisfy your idea better. |
Hi @spacewander Sorry for the limited environment reason, there is no resources to do this test now. |
OK, let me look at the implementation first. |
Look like some tests are not passed? |
What this PR does / why we need it:
Fix #1304
Pre-submission checklist: