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

Interruptible throttle; DNS Resolver support filter #495

Merged
merged 1 commit into from
May 31, 2024

Conversation

beef9999
Copy link
Collaborator

No description provided.

starving_slice_num++;
continue;
}
break_starving:
ret = sem.wait(amount, m_time_window_per_slice);
ret = sem.wait_interruptible(amount, m_time_window_per_slice);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

可打断的限流在一些场合很有用,比如做了优先级限流之后,一些低优先级的任务在后台排队(睡眠),如果这时候又来了新的相同的高优先级任务,需要打断睡眠,相当于提高优先级。

@@ -1682,7 +1682,7 @@ R"(
splock.lock();
CURRENT->semaphore_count = count;
int ret = 0;
while (!try_substract(count)) {
while (!try_subtract(count)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

substract is old English, which also appears in French and Spanish. In modern English it is subtract.

net/test/test.cpp Outdated Show resolved Hide resolved
@@ -157,7 +157,7 @@ class Resolver : public Object {
// When failed, return an Undefined IPAddr
// Normally dns servers return multiple ips in random order, choosing the first one should suffice.
virtual IPAddr resolve(std::string_view host) = 0;
virtual void resolve(std::string_view host, Delegate<void, IPAddr> func) = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why old API have to be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

等于是用上面那个resolve的结果自己再执行一遍func?

Copy link
Collaborator

@Coldwings Coldwings May 31, 2024

Choose a reason for hiding this comment

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

func(resolve(host)) is good enough (and used to be just implemented like this).

net/utils.h Outdated
@@ -157,7 +157,7 @@ class Resolver : public Object {
// When failed, return an Undefined IPAddr
// Normally dns servers return multiple ips in random order, choosing the first one should suffice.
virtual IPAddr resolve(std::string_view host) = 0;
virtual void resolve(std::string_view host, Delegate<void, IPAddr> func) = 0;
virtual IPAddr resolve(std::string_view host, Delegate<bool, IPAddr> filter) = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

原本的接口含义被改变了,可能给应用带来breaking change,这没有必要。你可以考虑新增一个接口resolve_filter()。

@@ -264,24 +264,17 @@ class DefaultResolver : public Resolver {
IPAddrNode(IPAddr addr) : addr(addr) {}
};
using IPAddrList = intrusive_list<IPAddrNode>;
public:
DefaultResolver(uint64_t cache_ttl, uint64_t resolve_timeout)
: dnscache_(cache_ttl), resolve_timeout_(resolve_timeout) {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

这些没变的话,就尽量不动

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

没动,只是把protected的函数移到了上面,就显得有变化

@beef9999 beef9999 force-pushed the beef9999/br-17 branch 3 times, most recently from 18c7a92 to e2f362d Compare May 28, 2024 11:40
#define LOG_AUDIT(...) (__LOG__((), default_audit_logger, ALOG_AUDIT, __VA_ARGS__))
#else
#define LOG_AUDIT(...)
#endif

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

跟 alog-audit.h 统一

#ifndef DISABLE_AUDIT

Copy link
Collaborator

@Coldwings Coldwings left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -157,7 +157,7 @@ class Resolver : public Object {
// When failed, return an Undefined IPAddr
// Normally dns servers return multiple ips in random order, choosing the first one should suffice.
virtual IPAddr resolve(std::string_view host) = 0;
virtual void resolve(std::string_view host, Delegate<void, IPAddr> func) = 0;
Copy link
Collaborator

@Coldwings Coldwings May 31, 2024

Choose a reason for hiding this comment

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

func(resolve(host)) is good enough (and used to be just implemented like this).

@lihuiba lihuiba merged commit 13a3401 into alibaba:main May 31, 2024
8 checks passed
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.

3 participants