-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Wait for fd API #450
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
Wait for fd API #450
Conversation
793382b
to
700e962
Compare
it did not address the problem i pointed out earlier :) |
Regarding your offline comments, this is not a premature optimization because system calls are almost always expensive, not to mention the frequency of the wait() calls in reality. Besides, we are designing an API here and this API should make room for important optimizations (even in the future) because once we add an API, we have to maintain backward compatibility. |
I feel like that would be premature optimisation. This is a first step to make a new style of programming possible (i.e. use cqueues). |
If everything works out, this API would be kept for one-shots, where the stateful abstraction would not be helpful. One-shots are quite common, and enough as in a applications an RPC call will be retrieved in a single packet. |
BTW, I'm against merging quick hacks just to make certain things possible because we have to eventually do it right and we'll almost always pay a bigger price when fixing hacks. Also, I'm very serious about adding new APIs to the ngx_lua core because I'd like to keep the core minimal :) |
Having said that, I'd love to see this pull request evolves (here or somewhere else) to a state where it is good to merge. |
An extra function useful in some (uncommon) circumstances isn't a quick hack IMO.
One of the reasons I would like this to be added in this state is that the functionality provided cannot be done in an external module.
Would you like me to rebase onto master as you work on other things?
Could you define what that entails? |
Pass my review :) |
@daurnimator Instead of making it a stateless function, I suggest you turn it into something stateful, like the standard Lua io module's file objects. We need at least some kind of (thin) encapsulation here (but no more). |
@daurnimator In addition, we may want to make room for the support of waiting on multiple fds at the same time. |
@daurnimator Also, please strictly follow the nginx coding style in your patch. For example, 2 blank lines are used to separate function definitions. |
src/ngx_http_lua_fd.c
Outdated
static void ngx_http_lua_fd_rev_handler(ngx_event_t *ev) { | ||
ngx_connection_t *conn = ev->data; | ||
ngx_http_lua_udata_t *u = conn->data; | ||
ngx_http_request_t *r = u->request; |
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.
Please avoid using such complicated initializers becuse it's against the nginx coding style.
Also, please always align up the variables in their definitions.
This seems like a much more complex api that I don't expect to get right on the first go.... What bits of state would you like to keep? the connection object seems to be the only thing possible?
This is the end goal: but I was going to provide it via
I don't suppose there is an 'astyle' incarnation that will make it suit your style? |
src/ngx_http_lua_fd.c
Outdated
return luaL_error(L, "no mem"); | ||
} | ||
/* always create a connection object (even if fd is < 0) */ | ||
if ((u->conn = ngx_get_connection(fd, r->connection->log)) == NULL) { |
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.
Calling ngx_get_connection
and ngx_free_connection
upon every wait()
is also too expensive IMHO.
Also, among other things, please add corresponding unit tests to the test suite (but I'm afraid the current API deserves a redesign, so better get the API straight first). |
Hey @agentzh, how can we proceed with an API for waiting for a file descriptor? |
@daurnimator Me either. I need some time to recap. Will look into this as soon as I can manage. |
@daurnimator |
This pull request is now in conflict :( |
f924579
to
fef2581
Compare
Did this PR ever get anywhere? |
@lePereT, this PR has never got merged, but there is something: |
This pull request is now in conflict :( |
This pull request is now in conflict :( |
This pull request is now in conflict :( |
This pull request is now in conflict :( |
This pull request is now in conflict :( |
This PR hasn't been updated in a long time, and based on previous discussions, I'm definitely closing this PR. |
Following on from https://groups.google.com/d/msg/openresty-en/T81159uj0y4/ZDckUrpUH30J
The short term goal here is a simple API that allows an advanced user to yield their request until an fd polls ready, or a timeout elapses. An fd polling ready is a primitive used across the majority of unix APIs, and is commonly exposed by (e.g.) database client libraries.
The single function added is:
ngx.wait(fd, events, timeout)
fd
is the numeric file descriptor to wait onevents
is a string containing "r" and/or "w" indicating to wait for readability vs writabilitytimeout
is the maximum amount of time (in seconds) to wait.