Exemple #1
0
func makeInternalPlanner(
	opName string, txn *client.Txn, user string, memMetrics *MemoryMetrics,
) *planner {
	p := makePlanner(opName)
	p.setTxn(txn)
	p.resetContexts()
	p.session.User = user

	p.session.mon = mon.MakeUnlimitedMonitor(p.session.context,
		"internal-root",
		memMetrics.CurBytesCount, memMetrics.MaxBytesHist,
		noteworthyInternalMemoryUsageBytes)

	p.session.sessionMon = mon.MakeMonitor("internal-session",
		memMetrics.SessionCurBytesCount,
		memMetrics.SessionMaxBytesHist,
		-1, noteworthyInternalMemoryUsageBytes/5)
	p.session.sessionMon.Start(p.session.context, &p.session.mon, mon.BoundAccount{})

	p.session.TxnState.mon = mon.MakeMonitor("internal-txn",
		memMetrics.TxnCurBytesCount,
		memMetrics.TxnMaxBytesHist,
		-1, noteworthyInternalMemoryUsageBytes/5)
	p.session.TxnState.mon.Start(p.session.context, &p.session.mon, mon.BoundAccount{})

	return p
}
Exemple #2
0
// MakeServer creates a Server.
func MakeServer(
	ambientCtx log.AmbientContext,
	cfg *base.Config,
	executor *sql.Executor,
	internalMemMetrics *sql.MemoryMetrics,
	maxSQLMem int64,
) *Server {
	server := &Server{
		AmbientCtx: ambientCtx,
		cfg:        cfg,
		executor:   executor,
		metrics:    makeServerMetrics(internalMemMetrics),
	}
	server.sqlMemoryPool = mon.MakeMonitor("sql",
		server.metrics.SQLMemMetrics.CurBytesCount,
		server.metrics.SQLMemMetrics.MaxBytesHist,
		0, noteworthySQLMemoryUsageBytes)
	server.sqlMemoryPool.Start(context.Background(), nil, mon.MakeStandaloneBudget(maxSQLMem))

	server.connMonitor = mon.MakeMonitor("conn",
		server.metrics.ConnMemMetrics.CurBytesCount,
		server.metrics.ConnMemMetrics.MaxBytesHist,
		int64(connReservationBatchSize)*baseSQLMemoryBudget, noteworthyConnMemoryUsageBytes)
	server.connMonitor.Start(context.Background(), &server.sqlMemoryPool, mon.BoundAccount{})

	return server
}
Exemple #3
0
func (s *Session) deriveAndStartMonitors() {
	s.sessionMon = mon.MakeMonitor("session",
		s.memMetrics.SessionCurBytesCount,
		s.memMetrics.SessionMaxBytesHist,
		-1, noteworthyMemoryUsageBytes)
	s.sessionMon.Start(s.context, &s.mon, mon.BoundAccount{})

	// We merely prepare the txn monitor here. It is fully started in
	// resetForNewSQLTxn().
	s.TxnState.mon = mon.MakeMonitor("txn",
		s.memMetrics.TxnCurBytesCount,
		s.memMetrics.TxnMaxBytesHist,
		-1, noteworthyMemoryUsageBytes)
}
Exemple #4
0
// StartMonitor interfaces between Session and mon.MemoryMonitor
func (s *Session) StartMonitor(pool *mon.MemoryMonitor, reserved mon.BoundAccount) {
	// Note: we pass `reserved` to s.mon where it causes `s.mon` to act
	// as a buffer. This is not done for sessionMon nor TxnState.mon:
	// these monitors don't start with any buffer, so they'll need to
	// ask their "parent" for memory as soon as the first
	// allocation. This is acceptable because the session is single
	// threaded, and the point of buffering is just to avoid contention.
	s.mon = mon.MakeMonitor("root",
		s.memMetrics.CurBytesCount,
		s.memMetrics.MaxBytesHist,
		-1, math.MaxInt64)
	s.mon.Start(s.context, pool, reserved)
	s.deriveAndStartMonitors()
}