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 2022/02/10 05:54:23 UTC

[GitHub] [apisix] leslie-tsang opened a new pull request #6281: chore: compresses the redis lua script in limit-count

leslie-tsang opened a new pull request #6281:
URL: https://github.com/apache/apisix/pull/6281


   ### What this PR does / why we need it:
   <!--- Why is this change required? What problem does it solve? -->
   <!--- If it fixes an open issue, please link to the issue here. -->
   This PR compresses the `limit-count` plugin's redis lua script.
   This will cut the cost of network traffic by about 15%.
   
   ### Pre-submission checklist:
   
   <!--
   Please follow the PR manners:
   1. Use Draft if the PR is not ready to be reviewed
   2. Test is required for the feat/fix PR, unless you have a good reason
   3. Doc is required for the feat PR
   4. Use a new commit to resolve review instead of `push -f`
   5. If you need to resolve merge conflicts after the PR is reviewed, please merge master but do not rebase
   6. Use "request review" to notify the reviewer once you have resolved the review
   7. Only reviewer can click "Resolve conversation" to mark the reviewer's review resolved
   -->
   
   * [x] Did you explain what problem does this PR solve? Or what new features have been added?
   * [ ] Have you added corresponding test cases?
   * [ ] Have you modified the corresponding document?
   * [x] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix/tree/master#community) first**
   


-- 
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



[GitHub] [apisix] tokers commented on a change in pull request #6281: chore: compresses the redis lua script in limit-count

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #6281:
URL: https://github.com/apache/apisix/pull/6281#discussion_r806380660



##########
File path: apisix/core/string.lua
##########
@@ -78,4 +78,12 @@ function _M.rfind_char(s, ch, idx)
 end
 
 
+-- reduce network consumption by compressing string indentation

Review comment:
       I think the compress way is not ideal as it might also change the literal string (spaces after `,`), so it should be used carefully, add some comments to give a hint will be better.




-- 
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



[GitHub] [apisix] leslie-tsang commented on a change in pull request #6281: chore: compresses the redis lua script in limit-count

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #6281:
URL: https://github.com/apache/apisix/pull/6281#discussion_r806376644



##########
File path: apisix/plugins/limit-count/limit-count-redis-cluster.lua
##########
@@ -37,6 +38,10 @@ local script = [=[
     return redis.call('incrby', KEYS[1], -1)
 ]=]
 
+--- compact the redis lua script
+script = string.gsub(script, "    ", "")

Review comment:
       @token ping




-- 
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



[GitHub] [apisix] spacewander commented on a change in pull request #6281: chore: compresses the redis lua script in limit-count

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #6281:
URL: https://github.com/apache/apisix/pull/6281#discussion_r804339102



##########
File path: apisix/plugins/limit-count/limit-count-redis-cluster.lua
##########
@@ -37,6 +38,10 @@ local script = [=[
     return redis.call('incrby', KEYS[1], -1)
 ]=]
 
+--- compact the redis lua script
+script = string.gsub(script, "    ", "")

Review comment:
       Better to put it in `core.string`. And the `ngx.re` version will be faster?




-- 
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



[GitHub] [apisix] spacewander merged pull request #6281: feat: compresses the redis lua script in limit-count

Posted by GitBox <gi...@apache.org>.
spacewander merged pull request #6281:
URL: https://github.com/apache/apisix/pull/6281


   


-- 
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



[GitHub] [apisix] tokers commented on a change in pull request #6281: chore: compresses the redis lua script in limit-count

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #6281:
URL: https://github.com/apache/apisix/pull/6281#discussion_r803474092



##########
File path: apisix/plugins/limit-count/limit-count-redis-cluster.lua
##########
@@ -37,6 +38,10 @@ local script = [=[
     return redis.call('incrby', KEYS[1], -1)
 ]=]
 
+--- compact the redis lua script
+script = string.gsub(script, "    ", "")

Review comment:
       Can we prepare a method/function to do this?




-- 
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



[GitHub] [apisix] leslie-tsang commented on a change in pull request #6281: chore: compresses the redis lua script in limit-count

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #6281:
URL: https://github.com/apache/apisix/pull/6281#discussion_r805453757



##########
File path: apisix/plugins/limit-count/limit-count-redis-cluster.lua
##########
@@ -37,6 +38,10 @@ local script = [=[
     return redis.call('incrby', KEYS[1], -1)
 ]=]
 
+--- compact the redis lua script
+script = string.gsub(script, "    ", "")

Review comment:
       Done




-- 
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



[GitHub] [apisix] tokers commented on a change in pull request #6281: chore: compresses the redis lua script in limit-count

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #6281:
URL: https://github.com/apache/apisix/pull/6281#discussion_r804288230



##########
File path: apisix/plugins/limit-count/limit-count-redis-cluster.lua
##########
@@ -37,6 +38,10 @@ local script = [=[
     return redis.call('incrby', KEYS[1], -1)
 ]=]
 
+--- compact the redis lua script
+script = string.gsub(script, "    ", "")

Review comment:
       Maybe `core.utils`?




-- 
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



[GitHub] [apisix] tokers commented on a change in pull request #6281: chore: compresses the redis lua script in limit-count

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #6281:
URL: https://github.com/apache/apisix/pull/6281#discussion_r806380660



##########
File path: apisix/core/string.lua
##########
@@ -78,4 +78,12 @@ function _M.rfind_char(s, ch, idx)
 end
 
 
+-- reduce network consumption by compressing string indentation

Review comment:
       I think the compress way is not ideal as it might also change the literal string (spaces after `,`), so it should be used carefully, add some comments to give a hint will be better.




-- 
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



[GitHub] [apisix] leslie-tsang commented on a change in pull request #6281: chore: compresses the redis lua script in limit-count

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #6281:
URL: https://github.com/apache/apisix/pull/6281#discussion_r805453757



##########
File path: apisix/plugins/limit-count/limit-count-redis-cluster.lua
##########
@@ -37,6 +38,10 @@ local script = [=[
     return redis.call('incrby', KEYS[1], -1)
 ]=]
 
+--- compact the redis lua script
+script = string.gsub(script, "    ", "")

Review comment:
       Done




-- 
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



[GitHub] [apisix] leslie-tsang commented on a change in pull request #6281: chore: compresses the redis lua script in limit-count

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #6281:
URL: https://github.com/apache/apisix/pull/6281#discussion_r803482495



##########
File path: apisix/plugins/limit-count/limit-count-redis-cluster.lua
##########
@@ -37,6 +38,10 @@ local script = [=[
     return redis.call('incrby', KEYS[1], -1)
 ]=]
 
+--- compact the redis lua script
+script = string.gsub(script, "    ", "")

Review comment:
       Yes for sure, I'm wondering where it would be more appropriate to put it. 




-- 
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



[GitHub] [apisix] leslie-tsang commented on a change in pull request #6281: chore: compresses the redis lua script in limit-count

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #6281:
URL: https://github.com/apache/apisix/pull/6281#discussion_r806376644



##########
File path: apisix/plugins/limit-count/limit-count-redis-cluster.lua
##########
@@ -37,6 +38,10 @@ local script = [=[
     return redis.call('incrby', KEYS[1], -1)
 ]=]
 
+--- compact the redis lua script
+script = string.gsub(script, "    ", "")

Review comment:
       @token ping




-- 
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



[GitHub] [apisix] spacewander commented on a change in pull request #6281: chore: compresses the redis lua script in limit-count

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #6281:
URL: https://github.com/apache/apisix/pull/6281#discussion_r807475414



##########
File path: apisix/core/string.lua
##########
@@ -78,4 +79,15 @@ function _M.rfind_char(s, ch, idx)
 end
 
 
+-- reduce network consumption by compressing string indentation
+-- this method should be used with caution
+-- it will remove the spaces at the beginning of each line
+-- remove the spaces after `,` character

Review comment:
       ```suggestion
   -- and remove the spaces after `,` character
   ```




-- 
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