From 0e3c0bc6dfc758b749aaf5cd48069598398040e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfonso=20Subiotto=20Marqu=C3=A9s?= Date: Mon, 31 Jul 2017 11:25:51 -0400 Subject: [PATCH] mon: generalize memory accounting Our use of MemoryMonitor had previously been limited solely to tracking memory allocations. However, future changes will use this mechanism to track disk usage. Therefore, Memory{Monitor, Account} have been renamed to Resource{Monitor, Account} and memory specific comments and code have been generalized. --- server.go | 8 +++++--- v3.go | 4 ++-- v3_test.go | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/server.go b/server.go index 5decc92..29bdd76 100644 --- a/server.go +++ b/server.go @@ -106,8 +106,8 @@ type Server struct { draining bool } - sqlMemoryPool mon.MemoryMonitor - connMonitor mon.MemoryMonitor + sqlMemoryPool mon.BytesMonitor + connMonitor mon.BytesMonitor } // ServerMetrics is the set of metrics for the pgwire server. @@ -150,7 +150,7 @@ func MakeServer( cfg *base.Config, executor *sql.Executor, internalMemMetrics *sql.MemoryMetrics, - parentMemoryMonitor *mon.MemoryMonitor, + parentMemoryMonitor *mon.BytesMonitor, histogramWindow time.Duration, ) *Server { server := &Server{ @@ -160,12 +160,14 @@ func MakeServer( metrics: makeServerMetrics(internalMemMetrics, histogramWindow), } server.sqlMemoryPool = mon.MakeMonitor("sql", + mon.MemoryResource, server.metrics.SQLMemMetrics.CurBytesCount, server.metrics.SQLMemMetrics.MaxBytesHist, 0, noteworthySQLMemoryUsageBytes) server.sqlMemoryPool.Start(context.Background(), parentMemoryMonitor, mon.BoundAccount{}) server.connMonitor = mon.MakeMonitor("conn", + mon.MemoryResource, server.metrics.ConnMemMetrics.CurBytesCount, server.metrics.ConnMemMetrics.MaxBytesHist, int64(connReservationBatchSize)*baseSQLMemoryBudget, noteworthyConnMemoryUsageBytes) diff --git a/v3.go b/v3.go index f8794e1..d33f342 100644 --- a/v3.go +++ b/v3.go @@ -186,11 +186,11 @@ type v3Conn struct { metrics *ServerMetrics - sqlMemoryPool *mon.MemoryMonitor + sqlMemoryPool *mon.BytesMonitor } func makeV3Conn( - conn net.Conn, metrics *ServerMetrics, sqlMemoryPool *mon.MemoryMonitor, executor *sql.Executor, + conn net.Conn, metrics *ServerMetrics, sqlMemoryPool *mon.BytesMonitor, executor *sql.Executor, ) v3Conn { return v3Conn{ conn: conn, diff --git a/v3_test.go b/v3_test.go index 8e3624d..efa8942 100644 --- a/v3_test.go +++ b/v3_test.go @@ -35,7 +35,9 @@ import ( func makeTestV3Conn(c net.Conn) v3Conn { metrics := makeServerMetrics(nil, metric.TestSampleInterval) - mon := mon.MakeUnlimitedMonitor(context.Background(), "test", nil, nil, 1000) + mon := mon.MakeUnlimitedMonitor( + context.Background(), "test", mon.MemoryResource, nil, nil, 1000, + ) exec := sql.NewExecutor( sql.ExecutorConfig{ AmbientCtx: log.AmbientContext{Tracer: tracing.NewTracer()},