# HG changeset patch # User Alain Mazy # Date 1705339640 -3600 # Node ID 5881e4af57997a6b61e6d58bab32a543da536055 # Parent 9e039e65d68e5c0009ca804e77b799e741b17a15 measure DB latency diff -r 9e039e65d68e -r 5881e4af5799 Framework/Plugins/DatabaseBackendAdapterV4.cpp --- a/Framework/Plugins/DatabaseBackendAdapterV4.cpp Mon Jan 15 15:21:43 2024 +0100 +++ b/Framework/Plugins/DatabaseBackendAdapterV4.cpp Mon Jan 15 18:27:20 2024 +0100 @@ -433,6 +433,7 @@ response.mutable_get_system_information()->set_supports_labels(accessor.GetBackend().HasLabelsSupport()); response.mutable_get_system_information()->set_supports_increment_global_property(accessor.GetBackend().HasAtomicIncrementGlobalProperty()); response.mutable_get_system_information()->set_has_update_and_get_statistics(accessor.GetBackend().HasUpdateAndGetStatistics()); + response.mutable_get_system_information()->set_has_measure_latency(accessor.GetBackend().HasMeasureLatency()); break; } @@ -516,7 +517,14 @@ break; } - + + case Orthanc::DatabasePluginMessages::OPERATION_MEASURE_LATENCY: + { + IndexConnectionsPool::Accessor accessor(pool); + response.mutable_measure_latency()->set_latency_us(accessor.GetBackend().MeasureLatency(accessor.GetManager())); + break; + } + default: LOG(ERROR) << "Not implemented database operation from protobuf: " << request.operation(); throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); diff -r 9e039e65d68e -r 5881e4af5799 Framework/Plugins/IDatabaseBackend.h --- a/Framework/Plugins/IDatabaseBackend.h Mon Jan 15 15:21:43 2024 +0100 +++ b/Framework/Plugins/IDatabaseBackend.h Mon Jan 15 18:27:20 2024 +0100 @@ -349,15 +349,19 @@ virtual void ListAllLabels(std::list& target, DatabaseManager& manager) = 0; + // New in Orthanc 1.12.X virtual bool HasAtomicIncrementGlobalProperty() = 0; + // New in Orthanc 1.12.X virtual int64_t IncrementGlobalProperty(DatabaseManager& manager, const char* serverIdentifier, int32_t property, int64_t increment) = 0; + // New in Orthanc 1.12.X virtual bool HasUpdateAndGetStatistics() = 0; + // New in Orthanc 1.12.X virtual void UpdateAndGetStatistics(DatabaseManager& manager, int64_t& patientsCount, int64_t& studiesCount, @@ -366,5 +370,12 @@ int64_t& compressedSize, int64_t& uncompressedSize) = 0; + // New in Orthanc 1.12.X + virtual bool HasMeasureLatency() = 0; + + // New in Orthanc 1.12.X + virtual uint64_t MeasureLatency(DatabaseManager& manager) = 0; + + }; } diff -r 9e039e65d68e -r 5881e4af5799 Framework/Plugins/IndexBackend.cpp --- a/Framework/Plugins/IndexBackend.cpp Mon Jan 15 15:21:43 2024 +0100 +++ b/Framework/Plugins/IndexBackend.cpp Mon Jan 15 18:27:20 2024 +0100 @@ -33,6 +33,7 @@ #include // For std::unique_ptr<> #include #include +#include namespace OrthancDatabases @@ -1236,6 +1237,12 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); } + bool IndexBackend::HasMeasureLatency() + { + return true; + } + + void IndexBackend::LookupIdentifier(std::list& target /*out*/, DatabaseManager& manager, OrthancPluginResourceType resourceType, @@ -2870,6 +2877,30 @@ } + uint64_t IndexBackend::MeasureLatency(DatabaseManager& manager) + { + // execute 11x the simplest statement and return the median value + std::vector measures; + + for (int i = 0; i < 11; i++) + { + DatabaseManager::CachedStatement statement( + STATEMENT_FROM_HERE, manager, + "SELECT 1"); + + Orthanc::Toolbox::ElapsedTimer timer; + + statement.Execute(); + + measures.push_back(timer.GetElapsedMicroseconds()); + } + + std::sort(measures.begin(), measures.end()); + + return measures[measures.size() / 2]; + } + + DatabaseManager* IndexBackend::CreateSingleDatabaseManager(IDatabaseBackend& backend, bool hasIdentifierTags, const std::list& identifierTags) diff -r 9e039e65d68e -r 5881e4af5799 Framework/Plugins/IndexBackend.h --- a/Framework/Plugins/IndexBackend.h Mon Jan 15 15:21:43 2024 +0100 +++ b/Framework/Plugins/IndexBackend.h Mon Jan 15 18:27:20 2024 +0100 @@ -415,6 +415,10 @@ int64_t& compressedSize, int64_t& uncompressedSize) ORTHANC_OVERRIDE; + virtual bool HasMeasureLatency() ORTHANC_OVERRIDE; + + virtual uint64_t MeasureLatency(DatabaseManager& manager) ORTHANC_OVERRIDE; + /** * "maxDatabaseRetries" is to handle * "OrthancPluginErrorCode_DatabaseCannotSerialize" if there is a