Skip to content
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

Balancer by lua stream #25

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

splitice
Copy link

@splitice splitice commented Feb 4, 2016

Commits in this branch correspond to the changes for Balancer by LUA in the Stream Subsystem (
openresty/stream-lua-nginx-module#7).

I have renambe the balancer.lua to balancer_http, and created the new implementation as balancer_stream.lua.

I will create a balancer.lua compatibility wrapper once the subsystem check is implemented.

Feel free to adjust the API to match your desired layout.

@@ -0,0 +1,82 @@
-- Copyright (C) Yichun Zhang (agentzh)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ngx.balancer.stream is a better module name than ngx.balancer_stream :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps ngx.stream.balancer and ngx.http.balancer ?

That way the namespace expands with other APIs ported.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I hope we can still use the ngx.balancer module in the stream context. We could do a dynamic dispatch to ngx.balancer.stream in the top-level scope of ngx.balancer. My hunch is that we need the ngx.config.subsystem field in both ngx_http_lua and ngx_stream_lua first ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thats my intention. Once you, I or someone else implements the subsystem check.

Specifically I was planning on just:

if subsystem == "stream" then
return require("...")
else if ...
...

That way any overhead is limited to the initial loading.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@splitice It's already too late to introduce the ngx.http and ngx.stream namespaces. Also it fragments the API namespace unnecessarily. The hope is that most Lua modules can work automatically in both contexts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I'll let you lay this out this however you like. I'll defer to your experience.

@agentzh
Copy link
Member

agentzh commented Feb 4, 2016

@splitice Just a side note: I think the ngx.semaphore API can be ported over to the stream subsystem in a similar way :)

@splitice
Copy link
Author

splitice commented Feb 4, 2016

Currently I have no use for the semaphore module so wont be doing it myself at this stage.

I ported this because of the lack of variable support in the stream subsystem preventing me from doing something as simple as proxy_pass $map_variable;.

If you have any comments on any of the PR's I've made feel free to let me know today. I am spending the day porting over a couple more of our small patches to the stream subsystem so its not out of my way.

@@ -26,7 +26,7 @@ ffi.cdef[[
int get_stale, int *is_stale);

int ngx_http_lua_ffi_shdict_incr(void *zone, const unsigned char *key,
size_t key_len, double *value, char **err);
size_t key_len, double *value, int exptime, char **err);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid these changes are irrelevant and should be removed out of this PR.

@agentzh
Copy link
Member

agentzh commented Feb 4, 2016

@splitice Will you add a test file for using ngx.balancer in the stream subsystem here? (By porting the existing t/balancer.t file to t/balancer-stream.t, for example.)

@splitice
Copy link
Author

splitice commented Feb 4, 2016

Probably best you do. I can do a theoretical port but dont have the time to get the environment passing.

@splitice
Copy link
Author

splitice commented Feb 4, 2016

Also might be best to check if the balancer_by_lua_* tests all pass first :)

@agentzh
Copy link
Member

agentzh commented Feb 5, 2016

@splitice Please check out this tutorial for how to run the tests on your side:

https://openresty.gitbooks.io/programming-openresty/content/testing/

It should be easy :)

@agentzh
Copy link
Member

agentzh commented Jul 20, 2016

This branch needs to rebase to the latest git master before it can be merged.




=== TEST 27: incr key expire
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unrelated to this PR, I'm afraid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants