diff options
| author | Martin Ridgers <[email protected]> | 2021-10-12 14:46:10 +0200 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2021-10-12 14:46:10 +0200 |
| commit | 7afea60028346eaff55deaf4f4ddbd213a265e4d (patch) | |
| tree | e17d8e1d1ec2a0013df10994db28929a86189568 | |
| parent | Added "xmake project" output to .gitignore (diff) | |
| parent | Ratios should not be percentages (this should be done in presentation) (diff) | |
| download | zen-7afea60028346eaff55deaf4f4ddbd213a265e4d.tar.xz zen-7afea60028346eaff55deaf4f4ddbd213a265e4d.zip | |
Merged main
| -rw-r--r-- | zencore/timer.cpp | 8 | ||||
| -rw-r--r-- | zenhttp/httpsys.cpp | 2 | ||||
| -rw-r--r-- | zenserver/cache/structuredcache.cpp | 12 | ||||
| -rw-r--r-- | zenserver/monitoring/httpstats.cpp | 16 | ||||
| -rw-r--r-- | zenserver/monitoring/httpstats.h | 1 | ||||
| -rw-r--r-- | zenserver/monitoring/httpstatus.cpp | 16 | ||||
| -rw-r--r-- | zenserver/monitoring/httpstatus.h | 1 | ||||
| -rw-r--r-- | zenserver/upstream/upstreamcache.cpp | 4 |
8 files changed, 48 insertions, 12 deletions
diff --git a/zencore/timer.cpp b/zencore/timer.cpp index 9180519bd..1655e912d 100644 --- a/zencore/timer.cpp +++ b/zencore/timer.cpp @@ -17,16 +17,20 @@ namespace zen { uint64_t GetHifreqTimerValue() { + uint64_t Timestamp; + #if ZEN_PLATFORM_WINDOWS LARGE_INTEGER li; QueryPerformanceCounter(&li); - return li.QuadPart; + Timestamp = li.QuadPart; #else struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (uint64_t(ts.tv_sec) * 1000000ull) + (uint64_t(ts.tv_nsec) / 1000ull); + Timestamp = (uint64_t(ts.tv_sec) * 1000000ull) + (uint64_t(ts.tv_nsec) / 1000ull); #endif + + return Timestamp; } uint64_t diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp index f88563097..f550f1f4c 100644 --- a/zenhttp/httpsys.cpp +++ b/zenhttp/httpsys.cpp @@ -9,6 +9,7 @@ #include <zencore/logging.h> #include <zencore/scopeguard.h> #include <zencore/string.h> +#include <zencore/timer.h> #include <zenhttp/httpshared.h> #if ZEN_WITH_HTTPSYS @@ -878,6 +879,7 @@ HttpSysServer::Run(bool IsInteractive) } m_ShutdownEvent.Wait(WaitTimeout); + UpdateLofreqTimerValue(); } while (!IsApplicationExitRequested()); } diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp index 4a2a3748a..35cb02cbb 100644 --- a/zenserver/cache/structuredcache.cpp +++ b/zenserver/cache/structuredcache.cpp @@ -161,13 +161,16 @@ HttpStructuredCacheService::HttpStructuredCacheService(ZenCacheStore& InCac , m_CidStore(InCidStore) , m_UpstreamCache(std::move(UpstreamCache)) { - StatsService.RegisterHandler("z$", *this); - StatusService.RegisterHandler("z$", *this); + m_StatsService.RegisterHandler("z$", *this); + m_StatusService.RegisterHandler("z$", *this); } HttpStructuredCacheService::~HttpStructuredCacheService() { ZEN_INFO("closing structured cache"); + + m_StatsService.UnregisterHandler("z$", *this); + m_StatusService.UnregisterHandler("z$", *this); } const char* @@ -275,6 +278,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(HttpServerRequest& Request, HandleGetCacheRecord(Request, Ref, Policy); } break; + case kPut: HandlePutCacheRecord(Request, Ref, Policy); break; @@ -883,9 +887,9 @@ HttpStructuredCacheService::HandleStatsRequest(zen::HttpServerRequest& Request) Cbo.BeginObject("cache"); Cbo << "hits" << HitCount << "misses" << MissCount; - Cbo << "hit_ratio" << (TotalCount > 0 ? (double(HitCount) / double(TotalCount) * 100.0) : 0.0); + Cbo << "hit_ratio" << (TotalCount > 0 ? (double(HitCount) / double(TotalCount)) : 0.0); Cbo << "upstream_hits" << m_CacheStats.UpstreamHitCount; - Cbo << "upstream_ratio" << (HitCount > 0 ? (double(UpstreamHitCount) / double(HitCount)) * 100.0 : 0.0); + Cbo << "upstream_ratio" << (HitCount > 0 ? (double(UpstreamHitCount) / double(HitCount)) : 0.0); Cbo.EndObject(); if (m_UpstreamCache) diff --git a/zenserver/monitoring/httpstats.cpp b/zenserver/monitoring/httpstats.cpp index de04294d0..4d985f8c2 100644 --- a/zenserver/monitoring/httpstats.cpp +++ b/zenserver/monitoring/httpstats.cpp @@ -26,6 +26,15 @@ HttpStatsService::RegisterHandler(std::string_view Id, IHttpStatsProvider& Provi } void +HttpStatsService::UnregisterHandler(std::string_view Id, IHttpStatsProvider& Provider) +{ + ZEN_UNUSED(Provider); + + RwLock::ExclusiveLockScope _(m_Lock); + m_Providers.erase(std::string(Id)); +} + +void HttpStatsService::HandleRequest(HttpServerRequest& Request) { using namespace std::literals; @@ -36,9 +45,12 @@ HttpStatsService::HandleRequest(HttpServerRequest& Request) { case HttpVerb::kHead: case HttpVerb::kGet: - if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers)) { - return It->second->HandleStatsRequest(Request); + RwLock::SharedLockScope _(m_Lock); + if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers)) + { + return It->second->HandleStatsRequest(Request); + } } [[fallthrough]]; diff --git a/zenserver/monitoring/httpstats.h b/zenserver/monitoring/httpstats.h index 1c3c79dd0..732815a9a 100644 --- a/zenserver/monitoring/httpstats.h +++ b/zenserver/monitoring/httpstats.h @@ -23,6 +23,7 @@ public: virtual const char* BaseUri() const override; virtual void HandleRequest(HttpServerRequest& Request) override; void RegisterHandler(std::string_view Id, IHttpStatsProvider& Provider); + void UnregisterHandler(std::string_view Id, IHttpStatsProvider& Provider); private: spdlog::logger& m_Log; diff --git a/zenserver/monitoring/httpstatus.cpp b/zenserver/monitoring/httpstatus.cpp index e12662b1c..8b10601dd 100644 --- a/zenserver/monitoring/httpstatus.cpp +++ b/zenserver/monitoring/httpstatus.cpp @@ -26,6 +26,15 @@ HttpStatusService::RegisterHandler(std::string_view Id, IHttpStatusProvider& Pro } void +HttpStatusService::UnregisterHandler(std::string_view Id, IHttpStatusProvider& Provider) +{ + ZEN_UNUSED(Provider); + + RwLock::ExclusiveLockScope _(m_Lock); + m_Providers.erase(std::string(Id)); +} + +void HttpStatusService::HandleRequest(HttpServerRequest& Request) { using namespace std::literals; @@ -36,9 +45,12 @@ HttpStatusService::HandleRequest(HttpServerRequest& Request) { case HttpVerb::kHead: case HttpVerb::kGet: - if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers)) { - return It->second->HandleStatusRequest(Request); + RwLock::SharedLockScope _(m_Lock); + if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers)) + { + return It->second->HandleStatusRequest(Request); + } } [[fallthrough]]; diff --git a/zenserver/monitoring/httpstatus.h b/zenserver/monitoring/httpstatus.h index 8f069f760..b04e45324 100644 --- a/zenserver/monitoring/httpstatus.h +++ b/zenserver/monitoring/httpstatus.h @@ -23,6 +23,7 @@ public: virtual const char* BaseUri() const override; virtual void HandleRequest(HttpServerRequest& Request) override; void RegisterHandler(std::string_view Id, IHttpStatusProvider& Provider); + void UnregisterHandler(std::string_view Id, IHttpStatusProvider& Provider); private: spdlog::logger& m_Log; diff --git a/zenserver/upstream/upstreamcache.cpp b/zenserver/upstream/upstreamcache.cpp index 5b2629f72..168449d05 100644 --- a/zenserver/upstream/upstreamcache.cpp +++ b/zenserver/upstream/upstreamcache.cpp @@ -697,7 +697,7 @@ struct UpstreamStats const double UpSpeed = UpBytes > 0 ? UpBytes / SecondsUp : 0.0; const double DownSpeed = DownBytes > 0 ? DownBytes / SecondsDown : 0.0; const uint64_t TotalCount = HitCount + MissCount; - const double HitRate = TotalCount > 0 ? (double(HitCount) / double(TotalCount)) * 100.0 : 0.0; + const double HitRate = TotalCount > 0 ? (double(HitCount) / double(TotalCount)) : 0.0; Logger.debug("STATS - '{}', Hit rate: {:.2f}%, DOWN: '{:.2f} MiB {:.2f} MiB/s', UP: '{:.2f} MiB {:.2f} MiB/s'", Ep->DisplayName(), @@ -842,7 +842,7 @@ public: const uint64_t HitCount = Stats.HitCount; const uint64_t MissCount = Stats.MissCount; const uint64_t TotalCount = HitCount + MissCount; - const double HitRate = TotalCount > 0 ? (double(HitCount) / double(TotalCount)) * 100.0 : 0.0; + const double HitRate = TotalCount > 0 ? (double(HitCount) / double(TotalCount)) : 0.0; Status << "hit_ratio" << HitRate; Status << "downloaded_mb" << Stats.DownBytes; |