-
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
ngx_http_lua_upstream with tengine RBTREE performance optimization #1882
base: master
Are you sure you want to change the base?
Conversation
|
||
umcf = ngx_http_lua_upstream_get_upstream_main_conf(L); | ||
|
||
#if (NGX_HTTP_UPSTREAM_RBTREE) |
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.
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];
modules/ngx_http_lua_upstream/src/ngx_http_lua_upstream_module.c
Outdated
Show resolved
Hide resolved
@@ -68,6 +68,7 @@ jobs: | |||
--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 \ |
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.
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
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.
@chobits OK. ok i will try it soon
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.
@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.
Fork the ngx_http_lua_upstream
And optimize performance O(n) search to O(logn) RBT search