-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[Enhancement] Add a cleaner for BrpcStubCache to cleanup unused connections #61417
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
base: main
Are you sure you want to change the base?
Changes from all commits
a4cd212
c766bf3
0de6839
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
#include <vector> | ||
|
||
#include "common/statusor.h" | ||
#include "exec/pipeline/schedule/pipeline_timer.h" | ||
#include "gen_cpp/Types_types.h" // TNetworkAddress | ||
#include "service/brpc.h" | ||
#include "util/internal_service_recoverable_stub.h" | ||
|
@@ -48,54 +49,105 @@ | |
|
||
namespace starrocks { | ||
|
||
class ExecEnv; | ||
class EndpointCleanupTask; | ||
class HttpEndpointCleanupTask; | ||
class LakeEndpointCleanupTask; | ||
|
||
class BrpcStubCache { | ||
public: | ||
BrpcStubCache(); | ||
BrpcStubCache(ExecEnv* exec_env); | ||
~BrpcStubCache(); | ||
|
||
std::shared_ptr<PInternalService_RecoverableStub> get_stub(const butil::EndPoint& endpoint); | ||
std::shared_ptr<PInternalService_RecoverableStub> get_stub(const TNetworkAddress& taddr); | ||
std::shared_ptr<PInternalService_RecoverableStub> get_stub(const std::string& host, int port); | ||
void cleanup_expired(const butil::EndPoint& endpoint); | ||
|
||
private: | ||
struct StubPool { | ||
StubPool(); | ||
~StubPool(); | ||
std::shared_ptr<PInternalService_RecoverableStub> get_or_create(const butil::EndPoint& endpoint); | ||
|
||
std::vector<std::shared_ptr<PInternalService_RecoverableStub>> _stubs; | ||
int64_t _idx; | ||
EndpointCleanupTask* _cleanup_task = nullptr; | ||
}; | ||
|
||
SpinLock _lock; | ||
butil::FlatMap<butil::EndPoint, StubPool*> _stub_map; | ||
butil::FlatMap<butil::EndPoint, std::shared_ptr<StubPool>> _stub_map; | ||
pipeline::PipelineTimer* _pipeline_timer; | ||
}; | ||
|
||
class HttpBrpcStubCache { | ||
public: | ||
static HttpBrpcStubCache* getInstance(); | ||
StatusOr<std::shared_ptr<PInternalService_RecoverableStub>> get_http_stub(const TNetworkAddress& taddr); | ||
void cleanup_expired(const butil::EndPoint& endpoint); | ||
|
||
private: | ||
HttpBrpcStubCache(); | ||
HttpBrpcStubCache(const HttpBrpcStubCache&) = delete; | ||
HttpBrpcStubCache& operator=(const HttpBrpcStubCache&) = delete; | ||
~HttpBrpcStubCache(); | ||
|
||
SpinLock _lock; | ||
butil::FlatMap<butil::EndPoint, std::shared_ptr<PInternalService_RecoverableStub>> _stub_map; | ||
butil::FlatMap<butil::EndPoint, std::pair<std::shared_ptr<PInternalService_RecoverableStub>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Every endpoint is registered with a TimerTask, not sure if this is feasible for a cluster with large scale of nodes, e.g. hundreds of backends/compute nodes, will this be carefully evaluated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think can. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stdpain Any suggestions master? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use it with confidence. They will be stored in the heap after being bucketed by the timer. So there's no need to worry about memory or other overhead. |
||
std::shared_ptr<HttpEndpointCleanupTask>>> | ||
_stub_map; | ||
pipeline::PipelineTimer* _pipeline_timer; | ||
}; | ||
|
||
class LakeServiceBrpcStubCache { | ||
public: | ||
static LakeServiceBrpcStubCache* getInstance(); | ||
StatusOr<std::shared_ptr<starrocks::LakeService_RecoverableStub>> get_stub(const std::string& host, int port); | ||
void cleanup_expired(const butil::EndPoint& endpoint); | ||
|
||
private: | ||
LakeServiceBrpcStubCache(); | ||
LakeServiceBrpcStubCache(const LakeServiceBrpcStubCache&) = delete; | ||
LakeServiceBrpcStubCache& operator=(const LakeServiceBrpcStubCache&) = delete; | ||
~LakeServiceBrpcStubCache(); | ||
|
||
SpinLock _lock; | ||
butil::FlatMap<butil::EndPoint, std::shared_ptr<LakeService_RecoverableStub>> _stub_map; | ||
butil::FlatMap<butil::EndPoint, | ||
std::pair<std::shared_ptr<LakeService_RecoverableStub>, std::shared_ptr<LakeEndpointCleanupTask>>> | ||
_stub_map; | ||
pipeline::PipelineTimer* _pipeline_timer; | ||
}; | ||
|
||
class EndpointCleanupTask : public starrocks::pipeline::PipelineTimerTask { | ||
public: | ||
EndpointCleanupTask(BrpcStubCache* cache, const butil::EndPoint& endpoint) : _cache(cache), _endpoint(endpoint){}; | ||
void Run() override; | ||
|
||
private: | ||
BrpcStubCache* _cache; | ||
butil::EndPoint _endpoint; | ||
}; | ||
|
||
class HttpEndpointCleanupTask : public starrocks::pipeline::PipelineTimerTask { | ||
public: | ||
HttpEndpointCleanupTask(HttpBrpcStubCache* cache, const butil::EndPoint& endpoint) | ||
: _cache(cache), _endpoint(endpoint){}; | ||
void Run() override; | ||
|
||
private: | ||
HttpBrpcStubCache* _cache; | ||
butil::EndPoint _endpoint; | ||
}; | ||
|
||
class LakeEndpointCleanupTask : public starrocks::pipeline::PipelineTimerTask { | ||
public: | ||
LakeEndpointCleanupTask(LakeServiceBrpcStubCache* cache, const butil::EndPoint& endpoint) | ||
: _cache(cache), _endpoint(endpoint){}; | ||
void Run() override; | ||
|
||
private: | ||
LakeServiceBrpcStubCache* _cache; | ||
butil::EndPoint _endpoint; | ||
}; | ||
|
||
} // namespace starrocks |
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.
_pipeline_timer is initialized in the init list, this line is redundant.