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

dnsdist: Add per-thread Lua FFI load-balancing policies #9175

Merged
merged 2 commits into from
Sep 2, 2020

Conversation

rgacogne
Copy link
Member

Short description

This allows Lua FFI load-balancing policies that don't need access to the global, shared Lua state to be lock-less, avoiding lock contention.

Checklist

I have:

  • read the CONTRIBUTING.md document
  • compiled this code
  • tested this code
  • included documentation (including possible behaviour changes)
  • documented the code
  • added or modified regression test(s)
  • added or modified unit test(s)

@wojas
Copy link
Member

wojas commented Jun 4, 2020

Do I understand correctly that this injects all dnsdist globals into every per-thread Lua context? Is it safe and useful to call those? If not, it's perhaps best to keep those Lua states as clean as possible to avoid confusion and mistakes.

I was originally thinking about requiring those per-thread functions to be pure Lua functions without access to the dnsdist Lua API, but perhaps that was naive for real world load balancing functions. Do you have an example of a policy that would require more than this?

@rgacogne
Copy link
Member Author

rgacogne commented Jun 4, 2020

Do I understand correctly that this injects all dnsdist globals into every per-thread Lua context? Is it safe and useful to call those? If not, it's perhaps best to keep those Lua states as clean as possible to avoid confusion and mistakes.

Not all of them, no, it injects bindings and constants, mostly. Most of these should be safe to use, a few of them might not be and should be of very little use for a load-balancing policy, but reviewing every single bindings and constants and separating the safe ones from the unsafe would be a huge task.

I was originally thinking about requiring those per-thread functions to be pure Lua functions without access to the dnsdist Lua API, but perhaps that was naive for real world load balancing functions. Do you have an example of a policy that would require more than this?

I don't understand, how do you access the content of the cdata objects passed to the load-balancing function without access to the dnsdist bindings?

@rgacogne rgacogne force-pushed the ddist-per-thread-lb-pol branch from 041516e to 9fdb4f7 Compare July 31, 2020 13:16
@rgacogne
Copy link
Member Author

Rebased on master.

@rgacogne rgacogne force-pushed the ddist-per-thread-lb-pol branch from 9fdb4f7 to cbad2c5 Compare August 10, 2020 09:38
@rgacogne rgacogne force-pushed the ddist-per-thread-lb-pol branch from cbad2c5 to a3a1fb3 Compare August 27, 2020 09:01
@rgacogne
Copy link
Member Author

Rebased to fix a conflict.

This allows Lua FFI load-balancing policies that don't need access
to the global, shared Lua state to be lock-less, avoiding lock contention.
@rgacogne rgacogne force-pushed the ddist-per-thread-lb-pol branch from a3a1fb3 to b613493 Compare September 1, 2020 12:38
@rgacogne rgacogne merged commit 4af4367 into PowerDNS:master Sep 2, 2020
@rgacogne rgacogne deleted the ddist-per-thread-lb-pol branch September 2, 2020 08:09
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.

2 participants