You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/09/25 03:17:39 UTC

[GitHub] [apisix] agile6v commented on pull request #5028: feat(proxy-cache): support memory-based strategy

agile6v commented on pull request #5028:
URL: https://github.com/apache/apisix/pull/5028#issuecomment-927002108


   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,
   
   1. Large files (> 1MB)
   2. Lots of large files
   3. Small files (< 1MB) with hotspots
   4. Persistence
   
   
   For memory strategy,
   
   1. Small files (< 1MB)
   2. The amount of the cached data doesn't exceed the host memory
   
   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 server
   
   ##### 1. generate test files in /home/nginx/data/
   
   dd if=/dev/sda of=4k bs=4 count=1024
   dd if=/dev/sda of=64k bs=64 count=1024
   dd if=/dev/sda of=512k bs=512 count=1024
   dd if=/dev/sda of=1024k bs=1024 count=1024
   
   ##### 2. configure location in proxied server
   
   ```nginx
      server {
          listen 1996;
          server_name localhost;
   
      	location / {
      	    if ($arg_size) {
      	        rewrite .* /${arg_size} break;
      	    }
      	
      	    root /home/nginx/data/;
      	}
   
      }
   ```
   
   ### Configure the APISIX
   
   need to download master branch: https://github.com/agile6v/apisix
   
   When testing memory strategy, we need to use this configuration.
   
   ```shell
   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.
   
   ```shell
   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 configuration
   
   ```shell
   curl -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.
   
   ```lua
   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{}
   ```
   
   
   > Note: 
   Random(3) will generate 17000+ unique random url
   Random(4) will generate 456976+ unique random url


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org