Skip to content

Wait for fd API - #450

Closed
daurnimator wants to merge 15 commits into
openresty:masterfrom
daurnimator:fd-api
Closed

Wait for fd API#450
daurnimator wants to merge 15 commits into
openresty:masterfrom
daurnimator:fd-api

Conversation

@daurnimator

Copy link
Copy Markdown

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 on
  • events is a string containing "r" and/or "w" indicating to wait for readability vs writability
  • timeout is the maximum amount of time (in seconds) to wait.

@daurnimator
daurnimator force-pushed the fd-api branch 4 times, most recently from 793382b to 700e962 Compare January 15, 2015 19:23
@agentzh

agentzh commented Feb 3, 2015

Copy link
Copy Markdown
Member

it did not address the problem i pointed out earlier :)
that is, it requires unnecessary epoll_ctl syscalls when ET is used.
better make it stateful rather than stateless.

@agentzh

agentzh commented Feb 3, 2015

Copy link
Copy Markdown
Member

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.

@daurnimator

Copy link
Copy Markdown
Author

it requires unnecessary epoll_ctl syscalls when ET is used.

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 it works out well, I hope that a cqueues-like object can provide that stateful api you're talking about
(a cqueues object is essentially an object that contains an epoll fd and a self-pipe to wake itself up)

@daurnimator

Copy link
Copy Markdown
Author

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 one we add an API, we have to maintain backward compatibility.

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.
A new api that is stateful would be added in parallel.

@agentzh

agentzh commented Feb 3, 2015

Copy link
Copy Markdown
Member

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

@agentzh

agentzh commented Feb 3, 2015

Copy link
Copy Markdown
Member

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.

@daurnimator

Copy link
Copy Markdown
Author

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.

An extra function useful in some (uncommon) circumstances isn't a quick hack IMO.

Also, I'm very serious about adding new APIs to the ngx_lua core because I'd like to keep the core minimal :)

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.
If you could provide a way to have this code outside the core lua-nginx-module I'd be happy to keep things seperate and maintain it myself.
I'd love to start writing+distributing modules that can rely on this type of function.

I'd love to see this pull request evolves

Would you like me to rebase onto master as you work on other things?

a state where it is good to merge.

Could you define what that entails?

@agentzh

agentzh commented Feb 3, 2015

Copy link
Copy Markdown
Member

Could you define what that entails?

Pass my review :)

@agentzh

agentzh commented Feb 3, 2015

Copy link
Copy Markdown
Member

@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).

@agentzh

agentzh commented Feb 3, 2015

Copy link
Copy Markdown
Member

@daurnimator In addition, we may want to make room for the support of waiting on multiple fds at the same time.

@agentzh

agentzh commented Feb 3, 2015

Copy link
Copy Markdown
Member

@daurnimator Also, please strictly follow the nginx coding style in your patch. For example, 2 blank lines are used to separate function definitions.

Comment thread src/ngx_http_lua_fd.c Outdated

Copy link
Copy Markdown
Member

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.

@daurnimator

Copy link
Copy Markdown
Author

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

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?
And it comes out of an nginx internal pool anyway....

@daurnimator In addition, we may want to make room for the support of waiting on multiple fds at the same time.

This is the end goal: but I was going to provide it via epoll, kqueue, ports, etc. in a library.
These allow for a single file descriptor to represent/poll many.

@daurnimator Also, please strictly follow the nginx coding style in your patch. For example, 2 blank lines are used to separate function definitions.

I don't suppose there is an 'astyle' incarnation that will make it suit your style?

Comment thread src/ngx_http_lua_fd.c Outdated

Copy link
Copy Markdown
Member

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.

@agentzh

agentzh commented Feb 3, 2015

Copy link
Copy Markdown
Member

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

@daurnimator

Copy link
Copy Markdown
Author

Hey @agentzh, how can we proceed with an API for waiting for a file descriptor?
Forgive me, but I can't remember the next steps we laid out.

@agentzh

agentzh commented Sep 20, 2017

Copy link
Copy Markdown
Member

@daurnimator Me either. I need some time to recap. Will look into this as soon as I can manage.

@guanlan

guanlan commented Jan 31, 2018

Copy link
Copy Markdown

@mergify

mergify Bot commented Jun 26, 2020

Copy link
Copy Markdown

This pull request is now in conflict :(

@lePereT

lePereT commented Oct 9, 2022

Copy link
Copy Markdown

Did this PR ever get anywhere?

@bungle

bungle commented Jan 17, 2023

Copy link
Copy Markdown
Member

@lePereT, this PR has never got merged, but there is something:
https://github.com/openresty/lua-nginx-module#ngxrun_worker_thread

@mergify mergify Bot removed the conflict label Mar 20, 2023
@mergify

mergify Bot commented Mar 20, 2023

Copy link
Copy Markdown

This pull request is now in conflict :(

@mergify mergify Bot added the conflict label Mar 20, 2023
@mergify mergify Bot removed the conflict label May 10, 2023
@mergify

mergify Bot commented May 10, 2023

Copy link
Copy Markdown

This pull request is now in conflict :(

@mergify mergify Bot added the conflict label May 10, 2023
@mergify mergify Bot removed the conflict label Sep 23, 2023
@mergify

mergify Bot commented Sep 23, 2023

Copy link
Copy Markdown

This pull request is now in conflict :(

@mergify mergify Bot added the conflict label Sep 23, 2023
@mergify mergify Bot removed the conflict label Mar 6, 2024
@mergify

mergify Bot commented Mar 6, 2024

Copy link
Copy Markdown

This pull request is now in conflict :(

@mergify mergify Bot added the conflict label Mar 6, 2024
@mergify mergify Bot removed the conflict label May 27, 2024
@mergify

mergify Bot commented May 27, 2024

Copy link
Copy Markdown

This pull request is now in conflict :(

@mergify mergify Bot added the conflict label May 27, 2024
@mergify mergify Bot removed the conflict label Sep 19, 2024
@zhuizhuhaomeng

Copy link
Copy Markdown
Contributor

This PR hasn't been updated in a long time, and based on previous discussions, I'm definitely closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants