Skip to content

Commit

Permalink
PMM-10665 Func to get cache sizes from DB variables. (#2362)
Browse files Browse the repository at this point in the history
* PMM-10655 Func to get cache sizes from DB variables.

* PMM-10665 Add logs.

* PMM-10665 Fix.

* PMM-10665 Add debug log.
  • Loading branch information
JiriCtvrtka authored Jul 24, 2023
1 parent 4d38bb9 commit 0c9fdbe
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions agent/agents/mysql/perfschema/perfschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package perfschema
import (
"context"
"database/sql"
"fmt"
"io"
"math"
"sync"
Expand Down Expand Up @@ -119,6 +120,39 @@ type newPerfSchemaParams struct {

const queryTag = "agent='perfschema'"

// getPerfschemaSummarySize returns size of rows for perfschema summary cache.
func getPerfschemaSummarySize(q reform.Querier, l *logrus.Entry) uint {
var name string
var size uint

query := fmt.Sprintf("SHOW VARIABLES /* %s */ LIKE 'performance_schema_digests_size'", queryTag)
err := q.QueryRow(query).Scan(&name, &size)
if err != nil {
l.Debug(err)
size = summariesCacheSize
}

l.Infof("performance_schema_digests_size=%d", size)

return size
}

// getPerfschemaHistorySize returns size of rows for perfschema history cache.
func getPerfschemaHistorySize(q reform.Querier, l *logrus.Entry) uint {
var name string
var size uint
query := fmt.Sprintf("SHOW VARIABLES /* %s */ LIKE 'performance_schema_events_statements_history_long_size'", queryTag)
err := q.QueryRow(query).Scan(&name, &size)
if err != nil {
l.Debug(err)
size = historyCacheSize
}

l.Infof("performance_schema_events_statements_history_long_size=%d", size)

return size
}

// New creates new PerfSchema QAN service.
func New(params *Params, l *logrus.Entry) (*PerfSchema, error) {
if params.TextFiles != nil {
Expand Down Expand Up @@ -152,12 +186,12 @@ func New(params *Params, l *logrus.Entry) (*PerfSchema, error) {
}

func newPerfSchema(params *newPerfSchemaParams) (*PerfSchema, error) {
historyCache, err := newHistoryCache(historyMap{}, retainHistory, historyCacheSize, params.LogEntry)
historyCache, err := newHistoryCache(historyMap{}, retainHistory, getPerfschemaHistorySize(*params.Querier, params.LogEntry), params.LogEntry)
if err != nil {
return nil, errors.Wrap(err, "cannot create cache")
}

summaryCache, err := newSummaryCache(summaryMap{}, retainSummaries, summariesCacheSize, params.LogEntry)
summaryCache, err := newSummaryCache(summaryMap{}, retainSummaries, getPerfschemaSummarySize(*params.Querier, params.LogEntry), params.LogEntry)
if err != nil {
return nil, errors.Wrap(err, "cannot create cache")
}
Expand Down

0 comments on commit 0c9fdbe

Please sign in to comment.