Comments (7)
@Tieske What real problem are you trying to solve here? Optimizations by saving a Lua table's creation and collection? Your use case limits the concurrency level of DNS resolving to 1 per nginx worker. Are you aware of that? If that's indeed what you're trying to do, then you can just create a background light thead (via ngx.timer.at
in init_worker_by_lua*
, for example) that is delegated by all the requests to do the DNS resolving work (serially).
from lua-resty-dns.
@Tieske I suggest you only do optimizations based on real profiling results :)
from lua-resty-dns.
@Tieske If you are worried about the extra socket
and close
syscalls upon udp cosocket creation and collection, then we should implement the socket pool instead. Will you be interested in contributing a setkeepalive
method just like that of the tcp cosockets? Thanks!
from lua-resty-dns.
Your use case limits the concurrency level of DNS resolving to 1 per nginx worker. Are you aware of that?
I'm sorry, but I don't see what you mean. The intent is to create a module level table (in the init_worker phase), holding multiple resolver objects. Upon resolving, grab one from the table (remove it) resolve the query, and put it back.
I don't see how this would limit concurrency? I think it would actually improve on it.
And instead of creating the resolver object on each request (not just the tables, but the input validation, creating and setting up sockets, etc) it can be reused.
What am I missing here?
you can just create a background light thread (via
ngx.timer.at
ininit_worker_by_lua*
, for example) that is delegated by all the requests to do the DNS resolving work (serially)
How would such delegation work? There is no way to yield the light thread (the incoming request) to wait for the resolving results (of the timer thread) other than using sleep
right? or am I missing something obvious here as well?
from lua-resty-dns.
The intent is to create a module level table (in the init_worker phase), holding multiple resolver objects. Upon resolving, grab one from the table (remove it) resolve the query, and put it back.
Seems like you are trying to emulate a socket pool on the Lua land yourself. No, cosockets' lifetime and scope are bound to the Lua handler context that creates them. This is an important design decision made for OpenResty to ensure
- Socket leaks can never happen.
- Bad simultaneous uses of the same cosocket object can never happen (unless by different light threads created in the same Lua handler context).
As I've already suggested above:
If you are worried about the extra socket and close syscalls upon udp cosocket creation and collection, then we should implement the socket pool instead. Will you be interested in contributing a setkeepalive method just like that of the tcp cosockets?
This is the right way to go.
How would such delegation work? There is no way to yield the light thread (the incoming request) to wait for the resolving results (of the timer thread) other than using sleep right? or am I missing something obvious here as well?
Seems like you haven't looked at the ngx.semaphore module?
https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/semaphore.md
It's way more efficient than manual polling via ngx.sleep
.
from lua-resty-dns.
Seems like you are trying to emulate a socket pool on the Lua land yourself.
yes (due to absence of a pool)
cosockets' lifetime and scope are bound to the Lua handler context that creates them
I understand the decision, but think it's a pity, it's easy to work around the problems (if you know what you're doing)
If you are worried about the extra socket and close syscalls upon udp cosocket creation and collection, then we should implement the socket pool instead. Will you be interested in contributing a setkeepalive method just like that of the tcp cosockets?
This is the right way to go.
yes (but unfortunately not in my skill set)
Seems like you haven't looked at the ngx.semaphore module?
thx for pointing that out
from lua-resty-dns.
I understand the decision, but think it's a pity, it's easy to work around the problems (if you know what you're doing)
Not really. Such things are notoriously hard to debug so we decide to provide the one true way of doing things here.
from lua-resty-dns.
Related Issues (20)
- /etc/hosts support? HOT 3
- Getting "failed to set peer name: resource temporarily unavailable" when using the module
- How does the module process for cache? HOT 2
- add "nameservers" to docs HOT 1
- the TCP client does not do any retries ('retrans' option) HOT 3
- dead resolver raises exception HOT 2
- how does the r:query parameter option:qtype? HOT 4
- is it possible to cache the answers for 15 secs? HOT 2
- Test case failing on rhel 7.6 ppc64le platform HOT 1
- how to return ipv4 address only.... HOT 6
- domain name resolution on pure ipv6 kubernetes HOT 1
- 域名解析报错 code=3
- How to get the fixed TTL?
- wire format HOT 5
- Return domain name by ip address HOT 1
- Error doing NS query
- tcp_sock is closed after tcp_query
- Use EDNS
- Does it support access via proxy?
- DNS ERROR HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lua-resty-dns.