added more tuning knobs, particularly in cache sizes
This commit is contained in:
@@ -108,6 +108,18 @@ type AmConfig struct {
|
|||||||
IPBans int `yaml:"ipBans"`
|
IPBans int `yaml:"ipBans"`
|
||||||
WorkerTasks int `yaml:"workerTasks"`
|
WorkerTasks int `yaml:"workerTasks"`
|
||||||
} `yaml:"queues"`
|
} `yaml:"queues"`
|
||||||
|
Caches struct {
|
||||||
|
Communities int `yaml:"communities"`
|
||||||
|
CommunityProps int `yaml:"communityProps"`
|
||||||
|
Conferences int `yaml:"conferences"`
|
||||||
|
ConferenceProps int `yaml:"conferenceProps"`
|
||||||
|
ContactInfo int `yaml:"contactInfo"`
|
||||||
|
Members int `yaml:"members"`
|
||||||
|
Menus int `yaml:"menus"`
|
||||||
|
Services int `yaml:"services"`
|
||||||
|
Users int `yaml:"users"`
|
||||||
|
UserProps int `yaml:"userProps"`
|
||||||
|
} `yaml:"caches"`
|
||||||
} `yaml:"tuning"`
|
} `yaml:"tuning"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,6 +240,16 @@ func overlayConfig(dest *AmConfig, loaded *AmConfig, defaults *AmConfig) {
|
|||||||
dest.Tuning.Queues.EmailSend = overlayInt(loaded.Tuning.Queues.EmailSend, defaults.Tuning.Queues.EmailSend)
|
dest.Tuning.Queues.EmailSend = overlayInt(loaded.Tuning.Queues.EmailSend, defaults.Tuning.Queues.EmailSend)
|
||||||
dest.Tuning.Queues.IPBans = overlayInt(loaded.Tuning.Queues.IPBans, defaults.Tuning.Queues.IPBans)
|
dest.Tuning.Queues.IPBans = overlayInt(loaded.Tuning.Queues.IPBans, defaults.Tuning.Queues.IPBans)
|
||||||
dest.Tuning.Queues.WorkerTasks = overlayInt(loaded.Tuning.Queues.WorkerTasks, defaults.Tuning.Queues.WorkerTasks)
|
dest.Tuning.Queues.WorkerTasks = overlayInt(loaded.Tuning.Queues.WorkerTasks, defaults.Tuning.Queues.WorkerTasks)
|
||||||
|
dest.Tuning.Caches.Communities = overlayInt(loaded.Tuning.Caches.Communities, defaults.Tuning.Caches.Communities)
|
||||||
|
dest.Tuning.Caches.CommunityProps = overlayInt(loaded.Tuning.Caches.CommunityProps, defaults.Tuning.Caches.CommunityProps)
|
||||||
|
dest.Tuning.Caches.Conferences = overlayInt(loaded.Tuning.Caches.Conferences, defaults.Tuning.Caches.Conferences)
|
||||||
|
dest.Tuning.Caches.ConferenceProps = overlayInt(loaded.Tuning.Caches.ConferenceProps, defaults.Tuning.Caches.ConferenceProps)
|
||||||
|
dest.Tuning.Caches.ContactInfo = overlayInt(loaded.Tuning.Caches.ContactInfo, defaults.Tuning.Caches.ContactInfo)
|
||||||
|
dest.Tuning.Caches.Members = overlayInt(loaded.Tuning.Caches.Members, defaults.Tuning.Caches.Members)
|
||||||
|
dest.Tuning.Caches.Menus = overlayInt(loaded.Tuning.Caches.Menus, defaults.Tuning.Caches.Menus)
|
||||||
|
dest.Tuning.Caches.Services = overlayInt(loaded.Tuning.Caches.Services, defaults.Tuning.Caches.Services)
|
||||||
|
dest.Tuning.Caches.Users = overlayInt(loaded.Tuning.Caches.Users, defaults.Tuning.Caches.Users)
|
||||||
|
dest.Tuning.Caches.UserProps = overlayInt(loaded.Tuning.Caches.UserProps, defaults.Tuning.Caches.UserProps)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseDataSize converts the data size in bytes, kilobytes, megabytes, or gigabytes to a number value.
|
// parseDataSize converts the data size in bytes, kilobytes, megabytes, or gigabytes to a number value.
|
||||||
|
|||||||
@@ -61,3 +61,14 @@ tuning:
|
|||||||
emailSend: 16
|
emailSend: 16
|
||||||
ipBans: 32
|
ipBans: 32
|
||||||
workerTasks: 128
|
workerTasks: 128
|
||||||
|
caches:
|
||||||
|
communities: 50
|
||||||
|
communityProps: 100
|
||||||
|
conferences: 100
|
||||||
|
conferenceProps: 100
|
||||||
|
contactInfo: 100
|
||||||
|
members: 250
|
||||||
|
menus: 100
|
||||||
|
services: 50
|
||||||
|
users: 100
|
||||||
|
userProps: 100
|
||||||
+14
-10
@@ -10,30 +10,34 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"slices"
|
||||||
|
|
||||||
"git.erbosoft.com/amy/amsterdam/config"
|
"git.erbosoft.com/amy/amsterdam/config"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/jmoiron/sqlx"
|
"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
|
var amdb *sqlx.DB
|
||||||
|
|
||||||
// SetupDb sets up the database and associated items.
|
// SetupDb sets up the database and associated items.
|
||||||
func SetupDb() (func(), error) {
|
func SetupDb() (func(), error) {
|
||||||
var fn1 func() = nil
|
exitfns := make([]func(), 0, 2)
|
||||||
var fn2 func() = nil
|
|
||||||
db, err := sqlx.Open(config.GlobalConfig.Database.Driver, config.GlobalConfig.Database.Dsn)
|
db, err := sqlx.Open(config.GlobalConfig.Database.Driver, config.GlobalConfig.Database.Dsn)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
amdb = db
|
amdb = db
|
||||||
fn1 = setupAuditWriter()
|
setupUserCache()
|
||||||
fn2 = setupIPBanSweep()
|
setupContactsCache()
|
||||||
|
setupCommunityCache()
|
||||||
|
setupServicesCache()
|
||||||
|
setupConferenceCache()
|
||||||
|
exitfns = append(exitfns, setupAuditWriter())
|
||||||
|
exitfns = append(exitfns, setupIPBanSweep())
|
||||||
}
|
}
|
||||||
return func() {
|
return func() {
|
||||||
if fn2 != nil {
|
slices.Reverse(exitfns)
|
||||||
fn2()
|
for _, f := range exitfns {
|
||||||
}
|
f()
|
||||||
if fn1 != nil {
|
|
||||||
fn1()
|
|
||||||
}
|
}
|
||||||
amdb.Close()
|
amdb.Close()
|
||||||
}, err
|
}, err
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.erbosoft.com/amy/amsterdam/config"
|
||||||
"git.erbosoft.com/amy/amsterdam/util"
|
"git.erbosoft.com/amy/amsterdam/util"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
@@ -130,18 +131,18 @@ func stuffMembership(cid int32, uid int32, member bool, locked bool, level uint1
|
|||||||
memberMutex.Unlock()
|
memberMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// init initializes the caches.
|
// setupCommunityCache initializes the caches.
|
||||||
func init() {
|
func setupCommunityCache() {
|
||||||
var err error
|
var err error
|
||||||
communityCache, err = lru.New2Q(50)
|
communityCache, err = lru.New2Q(config.GlobalConfig.Tuning.Caches.Communities)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
memberCache, err = lru.New(250)
|
memberCache, err = lru.New(config.GlobalConfig.Tuning.Caches.Members)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
communityPropCache, err = lru.New(100)
|
communityPropCache, err = lru.New(config.GlobalConfig.Tuning.Caches.CommunityProps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.erbosoft.com/amy/amsterdam/config"
|
||||||
"git.erbosoft.com/amy/amsterdam/util"
|
"git.erbosoft.com/amy/amsterdam/util"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
@@ -115,14 +116,14 @@ var conferencePropCache *lru.Cache = nil
|
|||||||
// getConferencePropMutex is a mutex on AmGetConferenceProperty.
|
// getConferencePropMutex is a mutex on AmGetConferenceProperty.
|
||||||
var getConferencePropMutex sync.Mutex
|
var getConferencePropMutex sync.Mutex
|
||||||
|
|
||||||
// init initializes the conference cache.
|
// setupConferenceCache initializes the conference cache.
|
||||||
func init() {
|
func setupConferenceCache() {
|
||||||
var err error
|
var err error
|
||||||
conferenceCache, err = lru.New2Q(100)
|
conferenceCache, err = lru.New2Q(config.GlobalConfig.Tuning.Caches.Conferences)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
conferencePropCache, err = lru.New(100)
|
conferencePropCache, err = lru.New(config.GlobalConfig.Tuning.Caches.ConferenceProps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.erbosoft.com/amy/amsterdam/config"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -236,10 +237,10 @@ var contactCache *lru.TwoQueueCache = nil
|
|||||||
// getContactMutex is a mutex on AmGetContactInfo.
|
// getContactMutex is a mutex on AmGetContactInfo.
|
||||||
var getContactMutex sync.Mutex
|
var getContactMutex sync.Mutex
|
||||||
|
|
||||||
// init initializes the contact info cache.
|
// setupContactsCache initializes the contact info cache.
|
||||||
func init() {
|
func setupContactsCache() {
|
||||||
var err error
|
var err error
|
||||||
contactCache, err = lru.New2Q(100)
|
contactCache, err = lru.New2Q(config.GlobalConfig.Tuning.Caches.ContactInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"git.erbosoft.com/amy/amsterdam/config"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@@ -91,8 +92,7 @@ var servicesCacheMutex sync.Mutex
|
|||||||
|
|
||||||
// init loads the service configuration and builds all the internal indexes.
|
// init loads the service configuration and builds all the internal indexes.
|
||||||
func init() {
|
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
|
panic(err) // can't happen
|
||||||
}
|
}
|
||||||
serviceRoot.byName = make(map[string]*ServiceDomain)
|
serviceRoot.byName = make(map[string]*ServiceDomain)
|
||||||
@@ -118,7 +118,12 @@ func init() {
|
|||||||
dom.byId["SysAdmin"].vtable = &empty
|
dom.byId["SysAdmin"].vtable = &empty
|
||||||
dom.byId["Conference"].vtable = &empty // TODO
|
dom.byId["Conference"].vtable = &empty // TODO
|
||||||
dom.byId["Members"].vtable = &empty
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -22,6 +22,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.erbosoft.com/amy/amsterdam/config"
|
||||||
"git.erbosoft.com/amy/amsterdam/util"
|
"git.erbosoft.com/amy/amsterdam/util"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
@@ -188,14 +189,14 @@ var getUserPropMutex sync.Mutex
|
|||||||
// anonUid is the UID of the "anonymous" user.
|
// anonUid is the UID of the "anonymous" user.
|
||||||
var anonUid int32 = -1
|
var anonUid int32 = -1
|
||||||
|
|
||||||
// init initializes the caches.
|
// setupUserCache initializes the caches.
|
||||||
func init() {
|
func setupUserCache() {
|
||||||
var err error
|
var err error
|
||||||
userCache, err = lru.New2Q(100)
|
userCache, err = lru.New2Q(config.GlobalConfig.Tuning.Caches.Users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
userPropCache, err = lru.New(100)
|
userPropCache, err = lru.New(config.GlobalConfig.Tuning.Caches.UserProps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ func main() {
|
|||||||
defer closer()
|
defer closer()
|
||||||
htmlcheck.SetupDicts()
|
htmlcheck.SetupDicts()
|
||||||
ui.SetupTemplates()
|
ui.SetupTemplates()
|
||||||
|
ui.SetupMenuCache()
|
||||||
closer = ui.SetupAmSessionManager()
|
closer = ui.SetupAmSessionManager()
|
||||||
defer closer()
|
defer closer()
|
||||||
closer = ui.SetupAmContext()
|
closer = ui.SetupAmContext()
|
||||||
|
|||||||
+10
-5
@@ -18,6 +18,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"git.erbosoft.com/amy/amsterdam/config"
|
||||||
"git.erbosoft.com/amy/amsterdam/database"
|
"git.erbosoft.com/amy/amsterdam/database"
|
||||||
"git.erbosoft.com/amy/amsterdam/util"
|
"git.erbosoft.com/amy/amsterdam/util"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
@@ -142,11 +143,7 @@ var menuCacheMutex sync.Mutex
|
|||||||
|
|
||||||
// init loads the menu definitions.
|
// init loads the menu definitions.
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
if err := yaml.Unmarshal(initMenuData, &menuDefinitions); err != nil {
|
||||||
if menuCache, err = lru.New(100); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if err = yaml.Unmarshal(initMenuData, &menuDefinitions); err != nil {
|
|
||||||
panic(err) // can't happen
|
panic(err) // can't happen
|
||||||
}
|
}
|
||||||
menuDefinitions.table = make(map[string]*MenuDefinition)
|
menuDefinitions.table = make(map[string]*MenuDefinition)
|
||||||
@@ -159,6 +156,14 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetupMenuCache sets up the menu cache.
|
||||||
|
func SetupMenuCache() {
|
||||||
|
var err error
|
||||||
|
if menuCache, err = lru.New(config.GlobalConfig.Tuning.Caches.Menus); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// AmMenu returns a menu definition.
|
// AmMenu returns a menu definition.
|
||||||
func AmMenu(name string) *MenuDefinition {
|
func AmMenu(name string) *MenuDefinition {
|
||||||
return menuDefinitions.table[name]
|
return menuDefinitions.table[name]
|
||||||
|
|||||||
Reference in New Issue
Block a user