diff options
author | andrew-rykov <[email protected]> | 2023-06-05 13:17:53 +0300 |
---|---|---|
committer | andrew-rykov <[email protected]> | 2023-06-05 13:17:53 +0300 |
commit | 24671180cce660aab222c990f4aa430eb5b02a61 (patch) | |
tree | e3ff85f41fc54a55b94924721f9f69cacf64688e | |
parent | 429ef6c87363f46364978b6f15b4c49eaf056688 (diff) |
cluster tablets test
make cluster handler faster
-rw-r--r-- | ydb/core/testlib/test_client.cpp | 11 | ||||
-rw-r--r-- | ydb/core/testlib/test_client.h | 3 | ||||
-rw-r--r-- | ydb/core/viewer/viewer_ut.cpp | 170 |
3 files changed, 184 insertions, 0 deletions
diff --git a/ydb/core/testlib/test_client.cpp b/ydb/core/testlib/test_client.cpp index fd070a1681e..3bcecec7be8 100644 --- a/ydb/core/testlib/test_client.cpp +++ b/ydb/core/testlib/test_client.cpp @@ -4,6 +4,7 @@ #include <ydb/core/base/path.h> #include <ydb/core/base/appdata.h> #include <ydb/core/base/hive.h> +#include <ydb/core/viewer/viewer.h> #include <ydb/public/lib/base/msgbus.h> #include <ydb/core/grpc_services/grpc_request_proxy.h> #include <ydb/services/auth/grpc_service.h> @@ -1002,6 +1003,16 @@ namespace Tests { ); NFq::InitTest(Runtime.Get(), port, Settings->GrpcPort, YqSharedResources); } + { + using namespace NViewer; + if (Settings->KikimrRunConfig) { + IActor* viewer = CreateViewer(*Settings->KikimrRunConfig); + SetupPQVirtualHandlers(dynamic_cast<IViewer*>(viewer)); + SetupDBVirtualHandlers(dynamic_cast<IViewer*>(viewer)); + TActorId viewerId = Runtime->Register(viewer, nodeIdx); + Runtime->RegisterService(MakeViewerID(nodeIdx), viewerId, nodeIdx); + } + } } void TServer::SetupLogging() { diff --git a/ydb/core/testlib/test_client.h b/ydb/core/testlib/test_client.h index 91862d263a0..2c4def02ad0 100644 --- a/ydb/core/testlib/test_client.h +++ b/ydb/core/testlib/test_client.h @@ -5,6 +5,7 @@ #include <ydb/core/base/subdomain.h> #include <ydb/core/base/tablet_types.h> #include <ydb/core/base/domain.h> +#include <ydb/core/driver_lib/run/config.h> #include <ydb/public/sdk/cpp/client/ydb_driver/driver.h> #include <ydb/public/lib/deprecated/client/msgbus_client.h> #include <ydb/core/client/server/grpc_server.h> @@ -124,6 +125,7 @@ namespace Tests { ui64 ChangesQueueItemsLimit = 0; ui64 ChangesQueueBytesLimit = 0; NKikimrConfig::TAppConfig AppConfig; + std::shared_ptr<TKikimrRunConfig> KikimrRunConfig; NKikimrConfig::TCompactionConfig CompactionConfig; TMap<ui32, TString> NodeKeys; ui64 DomainPlanResolution = 0; @@ -159,6 +161,7 @@ namespace Tests { TServerSettings& SetEnableConfigsDispatcher(bool value) { EnableConfigsDispatcher = value; return *this; } TServerSettings& SetUseRealThreads(bool value) { UseRealThreads = value; return *this; } TServerSettings& SetAppConfig(const NKikimrConfig::TAppConfig value) { AppConfig = value; return *this; } + TServerSettings& InitKikimrRunConfig() { KikimrRunConfig = std::make_shared<TKikimrRunConfig>(AppConfig); return *this; } TServerSettings& SetKeyFor(ui32 nodeId, TString keyValue) { NodeKeys[nodeId] = keyValue; return *this; } TServerSettings& SetEnableKqpSpilling(bool value) { EnableKqpSpilling = value; return *this; } TServerSettings& SetDomainPlanResolution(ui64 resolution) { DomainPlanResolution = resolution; return *this; } diff --git a/ydb/core/viewer/viewer_ut.cpp b/ydb/core/viewer/viewer_ut.cpp index 322ffec3021..a5807c74f4a 100644 --- a/ydb/core/viewer/viewer_ut.cpp +++ b/ydb/core/viewer/viewer_ut.cpp @@ -10,10 +10,22 @@ #include "json_vdiskinfo.h" #include "json_pdiskinfo.h" +#include <library/cpp/testing/unittest/registar.h> +#include <library/cpp/testing/unittest/tests_data.h> +#include <ydb/core/testlib/test_client.h> +#include <ydb/public/lib/deprecated/kicli/kicli.h> + +#include <ydb/core/node_whiteboard/node_whiteboard.h> +#include <library/cpp/actors/core/interconnect.h> + using namespace NKikimr; using namespace NViewer; using namespace NKikimrWhiteboard; +using namespace NSchemeShard; +using namespace Tests; +using namespace NMonitoring; + #ifdef NDEBUG #define Ctest Cnull #else @@ -182,4 +194,162 @@ Y_UNIT_TEST_SUITE(Viewer) { TestSwagger<TViewerJsonHandlers>(); TestSwagger<TVDiskJsonHandlers>(); } + + struct THttpRequest : NMonitoring::IHttpRequest { + HTTP_METHOD Method; + TCgiParameters CgiParameters; + THttpHeaders HttpHeaders; + + THttpRequest(HTTP_METHOD method) + : Method(method) + {} + + ~THttpRequest() {} + + const char* GetURI() const override { + return ""; + } + + const char* GetPath() const override { + return ""; + } + + const TCgiParameters& GetParams() const override { + return CgiParameters; + } + + const TCgiParameters& GetPostParams() const override { + return CgiParameters; + } + + TStringBuf GetPostContent() const override { + return TString(); + } + + HTTP_METHOD GetMethod() const override { + return Method; + } + + const THttpHeaders& GetHeaders() const override { + return HttpHeaders; + } + + TString GetRemoteAddr() const override { + return TString(); + } + }; + + class TMonPage: public IMonPage { + public: + TMonPage(const TString &path, const TString &title) + : IMonPage(path, title) + { + } + + void Output(IMonHttpRequest&) override { + } + }; + + void ChangeListNodes(TEvInterconnect::TEvNodesInfo::TPtr* ev, int nodesTotal) { + auto& nodes = (*ev)->Get()->Nodes; + + auto sample = nodes[0]; + nodes.clear(); + + for (int nodeId = 0; nodeId < nodesTotal; nodeId++) { + nodes.emplace_back(sample); + } + } + + void ChangeTabletStateResponse(TEvWhiteboard::TEvTabletStateResponse::TPtr* ev, int tabletsTotal, int& tabletId, int& nodeId) { + ui64* cookie = const_cast<ui64*>(&(ev->Get()->Cookie)); + *cookie = nodeId; + + auto& record = (*ev)->Get()->Record; + auto sample = record.tabletstateinfo(0); + record.clear_tabletstateinfo(); + + for (int i = 0; i < tabletsTotal; i++) { + auto tablet = record.add_tabletstateinfo(); + tablet->CopyFrom(sample); + tablet->set_tabletid(tabletId++); + tablet->set_type(NKikimrTabletBase::TTabletTypes::Mediator); + tablet->set_nodeid(nodeId); + } + + nodeId++; + } + + void ChangeDescribeSchemeResult(TEvSchemeShard::TEvDescribeSchemeResult::TPtr* ev, int tabletsTotal) { + auto record = (*ev)->Get()->MutableRecord(); + auto params = record->mutable_pathdescription()->mutable_domaindescription()->mutable_processingparams(); + + params->clear_mediators(); + for (int tabletId = 0; tabletId < tabletsTotal; tabletId++) { + params->add_mediators(tabletId); + } + } + + Y_UNIT_TEST(Cluster10000Tablets) + { + TPortManager tp; + ui16 port = tp.GetPort(2134); + ui16 grpcPort = tp.GetPort(2135); + auto settings = TServerSettings(port) + .SetNodeCount(2) + .SetUseRealThreads(false) + .SetDomainName("Root") + .InitKikimrRunConfig(); + TServer server(settings); + server.EnableGRpc(grpcPort); + TClient client(settings); + TTestActorRuntime& runtime = *server.GetRuntime(); + + TActorId sender = runtime.AllocateEdgeActor(); + TAutoPtr<IEventHandle> handle; + + THttpRequest httpReq(HTTP_METHOD_GET); + httpReq.CgiParameters.emplace("tablets", "true"); + auto page = MakeHolder<TMonPage>("viewer", "title"); + TMonService2HttpRequest monReq(nullptr, &httpReq, nullptr, page.Get(), "/json/cluster", nullptr); + auto request = MakeHolder<NMon::TEvHttpInfo>(monReq); + + int tabletIdCount = 1; + int nodeIdCount = 1; + const int nodesTotal = 100; + const int tabletsTotal = 100; + auto observerFunc = [&](TTestActorRuntimeBase&, TAutoPtr<IEventHandle>& ev) { + Y_UNUSED(ev); + switch (ev->GetTypeRewrite()) { + case TEvInterconnect::EvNodesInfo: { + auto *x = reinterpret_cast<TEvInterconnect::TEvNodesInfo::TPtr*>(&ev); + ChangeListNodes(x, nodesTotal); + break; + } + case TEvWhiteboard::EvTabletStateResponse: { + auto *x = reinterpret_cast<TEvWhiteboard::TEvTabletStateResponse::TPtr*>(&ev); + ChangeTabletStateResponse(x, tabletsTotal, tabletIdCount, nodeIdCount); + break; + } + case NSchemeShard::TEvSchemeShard::EvDescribeSchemeResult: { + auto *x = reinterpret_cast<NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult::TPtr*>(&ev); + ChangeDescribeSchemeResult(x, nodesTotal * tabletsTotal); + break; + } + } + + return TTestActorRuntime::EEventAction::PROCESS; + }; + runtime.SetObserverFunc(observerFunc); + + THPTimer timer; + + runtime.Send(new IEventHandle(NKikimr::NViewer::MakeViewerID(0), sender, request.Release(), 0)); + runtime.GrabEdgeEvent<NMon::TEvHttpInfoRes>(handle); + + Ctest << "Request timer = " << timer.Passed() << Endl; + Ctest << "BASE_PERF = " << BASE_PERF << Endl; + UNIT_ASSERT_LT(timer.Passed(), BASE_PERF); + + } } |