comparison Framework/Plugins/IndexBackend.cpp @ 447:5881e4af5799 pg-transactions

measure DB latency
author Alain Mazy <am@osimis.io>
date Mon, 15 Jan 2024 18:27:20 +0100
parents f16faa1fdc46
children 6780dd8b0a66
comparison
equal deleted inserted replaced
446:9e039e65d68e 447:5881e4af5799
31 #include "GlobalProperties.h" 31 #include "GlobalProperties.h"
32 32
33 #include <Compatibility.h> // For std::unique_ptr<> 33 #include <Compatibility.h> // For std::unique_ptr<>
34 #include <Logging.h> 34 #include <Logging.h>
35 #include <OrthancException.h> 35 #include <OrthancException.h>
36 #include <Toolbox.h>
36 37
37 38
38 namespace OrthancDatabases 39 namespace OrthancDatabases
39 { 40 {
40 static std::string ConvertWildcardToLike(const std::string& query) 41 static std::string ConvertWildcardToLike(const std::string& query)
1233 int64_t& compressedSize, 1234 int64_t& compressedSize,
1234 int64_t& uncompressedSize) 1235 int64_t& uncompressedSize)
1235 { 1236 {
1236 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 1237 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
1237 } 1238 }
1239
1240 bool IndexBackend::HasMeasureLatency()
1241 {
1242 return true;
1243 }
1244
1238 1245
1239 void IndexBackend::LookupIdentifier(std::list<int64_t>& target /*out*/, 1246 void IndexBackend::LookupIdentifier(std::list<int64_t>& target /*out*/,
1240 DatabaseManager& manager, 1247 DatabaseManager& manager,
1241 OrthancPluginResourceType resourceType, 1248 OrthancPluginResourceType resourceType,
1242 uint16_t group, 1249 uint16_t group,
2868 # endif 2875 # endif
2869 #endif 2876 #endif
2870 } 2877 }
2871 2878
2872 2879
2880 uint64_t IndexBackend::MeasureLatency(DatabaseManager& manager)
2881 {
2882 // execute 11x the simplest statement and return the median value
2883 std::vector<uint64_t> measures;
2884
2885 for (int i = 0; i < 11; i++)
2886 {
2887 DatabaseManager::CachedStatement statement(
2888 STATEMENT_FROM_HERE, manager,
2889 "SELECT 1");
2890
2891 Orthanc::Toolbox::ElapsedTimer timer;
2892
2893 statement.Execute();
2894
2895 measures.push_back(timer.GetElapsedMicroseconds());
2896 }
2897
2898 std::sort(measures.begin(), measures.end());
2899
2900 return measures[measures.size() / 2];
2901 }
2902
2903
2873 DatabaseManager* IndexBackend::CreateSingleDatabaseManager(IDatabaseBackend& backend, 2904 DatabaseManager* IndexBackend::CreateSingleDatabaseManager(IDatabaseBackend& backend,
2874 bool hasIdentifierTags, 2905 bool hasIdentifierTags,
2875 const std::list<IdentifierTag>& identifierTags) 2906 const std::list<IdentifierTag>& identifierTags)
2876 { 2907 {
2877 std::unique_ptr<DatabaseManager> manager(new DatabaseManager(backend.CreateDatabaseFactory())); 2908 std::unique_ptr<DatabaseManager> manager(new DatabaseManager(backend.CreateDatabaseFactory()));