Skip to content
This repository has been archived by the owner on Mar 30, 2020. It is now read-only.

Commit

Permalink
mon: generalize memory accounting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
asubiotto committed Aug 7, 2017
1 parent fde3fbd commit 0e3c0bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()},
Expand Down

0 comments on commit 0e3c0bc

Please sign in to comment.