added more tuning knobs, particularly in cache sizes
This commit is contained in:
+14
-10
@@ -10,30 +10,34 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/config"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
// amdb is the reference to the Amsterdam database. Returns a function to close it down.
|
||||
// amdb is the reference to the Amsterdam database.
|
||||
var amdb *sqlx.DB
|
||||
|
||||
// SetupDb sets up the database and associated items.
|
||||
func SetupDb() (func(), error) {
|
||||
var fn1 func() = nil
|
||||
var fn2 func() = nil
|
||||
exitfns := make([]func(), 0, 2)
|
||||
db, err := sqlx.Open(config.GlobalConfig.Database.Driver, config.GlobalConfig.Database.Dsn)
|
||||
if err == nil {
|
||||
amdb = db
|
||||
fn1 = setupAuditWriter()
|
||||
fn2 = setupIPBanSweep()
|
||||
setupUserCache()
|
||||
setupContactsCache()
|
||||
setupCommunityCache()
|
||||
setupServicesCache()
|
||||
setupConferenceCache()
|
||||
exitfns = append(exitfns, setupAuditWriter())
|
||||
exitfns = append(exitfns, setupIPBanSweep())
|
||||
}
|
||||
return func() {
|
||||
if fn2 != nil {
|
||||
fn2()
|
||||
}
|
||||
if fn1 != nil {
|
||||
fn1()
|
||||
slices.Reverse(exitfns)
|
||||
for _, f := range exitfns {
|
||||
f()
|
||||
}
|
||||
amdb.Close()
|
||||
}, err
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/config"
|
||||
"git.erbosoft.com/amy/amsterdam/util"
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"github.com/jmoiron/sqlx"
|
||||
@@ -130,18 +131,18 @@ func stuffMembership(cid int32, uid int32, member bool, locked bool, level uint1
|
||||
memberMutex.Unlock()
|
||||
}
|
||||
|
||||
// init initializes the caches.
|
||||
func init() {
|
||||
// setupCommunityCache initializes the caches.
|
||||
func setupCommunityCache() {
|
||||
var err error
|
||||
communityCache, err = lru.New2Q(50)
|
||||
communityCache, err = lru.New2Q(config.GlobalConfig.Tuning.Caches.Communities)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
memberCache, err = lru.New(250)
|
||||
memberCache, err = lru.New(config.GlobalConfig.Tuning.Caches.Members)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
communityPropCache, err = lru.New(100)
|
||||
communityPropCache, err = lru.New(config.GlobalConfig.Tuning.Caches.CommunityProps)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/config"
|
||||
"git.erbosoft.com/amy/amsterdam/util"
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"github.com/jmoiron/sqlx"
|
||||
@@ -115,14 +116,14 @@ var conferencePropCache *lru.Cache = nil
|
||||
// getConferencePropMutex is a mutex on AmGetConferenceProperty.
|
||||
var getConferencePropMutex sync.Mutex
|
||||
|
||||
// init initializes the conference cache.
|
||||
func init() {
|
||||
// setupConferenceCache initializes the conference cache.
|
||||
func setupConferenceCache() {
|
||||
var err error
|
||||
conferenceCache, err = lru.New2Q(100)
|
||||
conferenceCache, err = lru.New2Q(config.GlobalConfig.Tuning.Caches.Conferences)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
conferencePropCache, err = lru.New(100)
|
||||
conferencePropCache, err = lru.New(config.GlobalConfig.Tuning.Caches.ConferenceProps)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/config"
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
)
|
||||
|
||||
@@ -236,10 +237,10 @@ var contactCache *lru.TwoQueueCache = nil
|
||||
// getContactMutex is a mutex on AmGetContactInfo.
|
||||
var getContactMutex sync.Mutex
|
||||
|
||||
// init initializes the contact info cache.
|
||||
func init() {
|
||||
// setupContactsCache initializes the contact info cache.
|
||||
func setupContactsCache() {
|
||||
var err error
|
||||
contactCache, err = lru.New2Q(100)
|
||||
contactCache, err = lru.New2Q(config.GlobalConfig.Tuning.Caches.ContactInfo)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"slices"
|
||||
"sync"
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/config"
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"gopkg.in/yaml.v3"
|
||||
@@ -91,8 +92,7 @@ var servicesCacheMutex sync.Mutex
|
||||
|
||||
// init loads the service configuration and builds all the internal indexes.
|
||||
func init() {
|
||||
var err error
|
||||
if err = yaml.Unmarshal(initServiceData, &serviceRoot); err != nil {
|
||||
if err := yaml.Unmarshal(initServiceData, &serviceRoot); err != nil {
|
||||
panic(err) // can't happen
|
||||
}
|
||||
serviceRoot.byName = make(map[string]*ServiceDomain)
|
||||
@@ -118,7 +118,12 @@ func init() {
|
||||
dom.byId["SysAdmin"].vtable = &empty
|
||||
dom.byId["Conference"].vtable = &empty // TODO
|
||||
dom.byId["Members"].vtable = &empty
|
||||
servicesCache, err = lru.New2Q(50)
|
||||
}
|
||||
|
||||
// setupServicesCache sets up the services cache.
|
||||
func setupServicesCache() {
|
||||
var err error
|
||||
servicesCache, err = lru.New2Q(config.GlobalConfig.Tuning.Caches.Services)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
+5
-4
@@ -22,6 +22,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/config"
|
||||
"git.erbosoft.com/amy/amsterdam/util"
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"github.com/jmoiron/sqlx"
|
||||
@@ -188,14 +189,14 @@ var getUserPropMutex sync.Mutex
|
||||
// anonUid is the UID of the "anonymous" user.
|
||||
var anonUid int32 = -1
|
||||
|
||||
// init initializes the caches.
|
||||
func init() {
|
||||
// setupUserCache initializes the caches.
|
||||
func setupUserCache() {
|
||||
var err error
|
||||
userCache, err = lru.New2Q(100)
|
||||
userCache, err = lru.New2Q(config.GlobalConfig.Tuning.Caches.Users)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
userPropCache, err = lru.New(100)
|
||||
userPropCache, err = lru.New(config.GlobalConfig.Tuning.Caches.UserProps)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user