ngx_http_lua_upstream with tengine RBTREE performance optimization#1882
Open
lhanjian wants to merge 10 commits intoalibaba:masterfrom
Open
ngx_http_lua_upstream with tengine RBTREE performance optimization#1882lhanjian wants to merge 10 commits intoalibaba:masterfrom
lhanjian wants to merge 10 commits intoalibaba:masterfrom
Conversation
lhanjian
commented
Nov 2, 2023
|
|
||
| umcf = ngx_http_lua_upstream_get_upstream_main_conf(L); | ||
|
|
||
| #if (NGX_HTTP_UPSTREAM_RBTREE) |
Collaborator
Author
There was a problem hiding this comment.
Optimization of mine.
diff --git a/src/ngx_http_lua_upstream_module.c b/src/ngx_http_lua_upstream_module.c
index 7b23787..c5b4c80 100644
--- a/src/ngx_http_lua_upstream_module.c
+++ b/src/ngx_http_lua_upstream_module.c
@@ -517,10 +517,41 @@ ngx_http_lua_upstream_find_upstream(lua_State *L, ngx_str_t *host)
ngx_http_upstream_main_conf_t *umcf;
umcf = ngx_http_lua_upstream_get_upstream_main_conf(L);
+
+#if (NGX_HTTP_UPSTREAM_RBTREE)
+
+ ngx_list_part_t *part;
+
+ uscf = ngx_http_upstream_rbtree_lookup(umcf, host);
+
+ if (uscf != NULL)
+ {
+ return uscf;
+ }
+
+ part = &umcf->implicit_upstreams.part;
+ uscfp = part->elts;
+
+ for (i = 0; /* void */ ; i++) {
+
+ if (i >= part->nelts) {
+ if (part->next == NULL) {
+ break;
+ }
+
+ part = part->next;
+ uscfp = part->elts;
+ i = 0;
+ }
+
+#else
+
uscfp = umcf->upstreams.elts;
for (i = 0; i < umcf->upstreams.nelts; i++) {
+#endif
+
uscf = uscfp[i];
if (uscf->host.len == host->len
@@ -542,7 +573,30 @@ ngx_http_lua_upstream_find_upstream(lua_State *L, ngx_str_t *host)
len = port - host->data - 1;
+#if (NGX_HTTP_UPSTREAM_RBTREE)
+ ngx_str_t addr;
+ addr.data = host->data;
+ addr.len = len;
+ uscf = ngx_http_upstream_rbtree_lookup(umcf, &addr);
+ if (uscf != NULL && uscf->port
+ && uscf->port == n)
+ {
+ return uscf;
+ }
+ part = &umcf->implicit_upstreams.part;
+ uscfp = part->elts;
+ for (i = 0; /* void */ ; i++) {
+ if (i >= part->nelts) {
+ if (part->next == NULL) {
+ break;
+ }
+ part = part->next;
+ uscfp = part->elts;
+ i = 0;
+ }
+#else
for (i = 0; i < umcf->upstreams.nelts; i++) {
+#endif
uscf = uscfp[i];
Collaborator
Author
chobits
reviewed
Nov 2, 2023
chobits
reviewed
Nov 14, 2023
modules/ngx_http_lua_upstream/src/ngx_http_lua_upstream_module.c
Outdated
Show resolved
Hide resolved
chobits
reviewed
Nov 14, 2023
chobits
reviewed
Nov 14, 2023
| --add-module=./modules/ngx_http_concat_module \ | ||
| --add-module=./modules/ngx_http_footer_filter_module \ | ||
| --add-module=./modules/ngx_http_lua_module \ | ||
| --add-module=./modules/ngx_http_lua_upstream \ |
Member
There was a problem hiding this comment.
hi @lhanjian I have examined the test cases introduced by this module. I believe it is easy to run and pass, it does not depend on some other module or library. Could you try to make it work in our CI/CD workflow? only for lua-upstream module
Collaborator
Author
There was a problem hiding this comment.
@chobits test case of ngx_http_lua_upstream need more dependencies, like echo-nginx-module.
and version of test-nginx is too old to run ngx_http_lua_upstream/t, so we can't run test of ngx_http_lua_upstream/t for now.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fork the ngx_http_lua_upstream
And optimize performance O(n) search to O(logn) RBT search