Compare commits

..

35 Commits

Author SHA1 Message Date
kim b7dc94e795
Merge 0f486ebb59 into f456bd3401 2024-05-06 18:04:13 -04:00
kim f456bd3401
update the total ratios calculation to include ALL caches (previously was missing a few!) (#2907) 2024-05-06 22:29:31 +01:00
kim 0f486ebb59 on busy errors return bad conn to signal retry 2024-05-06 21:57:35 +01:00
kim 70d994f800 fix remaining tests 2024-05-06 21:41:07 +01:00
kim cc5cb79f66 on busy errors return bad conn to signal retry 2024-05-06 21:21:52 +01:00
kim 73e4ef4a8b don't use timeout context on close 2024-05-06 21:15:49 +01:00
kim fb71073726 update to ncruces/go-sqlite3 v0.15.0 2024-05-06 21:15:49 +01:00
kim 85558f7419 add '/' prefix to in-memory uuid addr 2024-05-06 21:15:49 +01:00
kim 67588d6fc2 fix tests now that db is properly closed in test teardown 2024-05-06 21:15:49 +01:00
kim 1c68f042f8 fix broken test after fixing db teardown to close conn 2024-05-06 21:15:49 +01:00
kim 6887003d57 remove unused code 2024-05-06 21:15:49 +01:00
kim 402f8b37a1 ensure the database gets closed on standarddbteardown 2024-05-06 21:15:49 +01:00
kim 4466e0fee0 update test configuration setting to ensure no settings linger 2024-05-06 21:15:49 +01:00
kim 4312b00942 unset set-x 2024-05-06 21:15:49 +01:00
kim 08a6ff55ab make run-postgres compatible with podman 2024-05-06 21:15:49 +01:00
kim 7719768130 update postgres test script to support docker or podman 2024-05-06 21:15:48 +01:00
kim 097672859a move postgres driver into separate subpkg 2024-05-06 21:15:48 +01:00
kim 2301fb45aa small changes 2024-05-06 21:15:48 +01:00
kim e9a2af739f move sqlite driver into separate package, make wasm sqlite3 build build-taggable 2024-05-06 21:15:48 +01:00
kim ea4c9b08ac fix imports 2024-05-06 21:15:47 +01:00
kim 7c2beb8741 remove unused code 2024-05-06 21:15:47 +01:00
kim 06ecc1ec1e remove unneeded type 2024-05-06 21:15:47 +01:00
kim 07a1afe594 add comments to imports, remove unneeded ctx from SQLiteRows{} 2024-05-06 21:15:47 +01:00
kim 97b20b8136 re-enable txlock immediate 2024-05-06 21:15:47 +01:00
kim 18af23206e try removing our own retryBusy handler to rely on in-built busy-timeout-handler 2024-05-06 21:15:47 +01:00
kim 2b45e17981 bump on-close analysis limit back up to 1000, timeout should prevent long-running 2024-05-06 21:15:47 +01:00
kim ea943a7983 set busy timeout, don't add querycontext to SQLiteConn{}, pass through ExecerContext 2024-05-06 21:15:47 +01:00
kim a6c753e370 don't bother releasing memory, it's not helping :( 2024-05-06 21:15:47 +01:00
kim ebc082aed3 log optimize on close errors 2024-05-06 21:15:47 +01:00
kim 848b611bf3 unset interrupt BEFORE closing connection 2024-05-06 21:15:47 +01:00
kim f0d6306011 use timeout context on close 2024-05-06 21:15:47 +01:00
kim bb7413ca21 release memory on close, return close error 2024-05-06 21:15:47 +01:00
kim abcdec3196 some small tweaks 2024-05-06 21:15:47 +01:00
kim d04d4f2378 try out using wasm sqlite instead of modernc.org/sqlite 2024-05-06 21:15:46 +01:00
kim 3554991444
update go-structr -> v0.8.2 which includes some minor memory usage improvements (#2904) 2024-05-06 19:44:22 +00:00
12 changed files with 67 additions and 11 deletions

2
go.mod
View File

@ -22,7 +22,7 @@ require (
codeberg.org/gruf/go-runners v1.6.2
codeberg.org/gruf/go-sched v1.2.3
codeberg.org/gruf/go-store/v2 v2.2.4
codeberg.org/gruf/go-structr v0.8.0
codeberg.org/gruf/go-structr v0.8.2
codeberg.org/superseriousbusiness/exif-terminator v0.7.0
github.com/DmitriyVTitov/size v1.5.0
github.com/KimMachineGun/automemlimit v0.6.0

4
go.sum
View File

@ -74,8 +74,8 @@ codeberg.org/gruf/go-sched v1.2.3 h1:H5ViDxxzOBR3uIyGBCf0eH8b1L8wMybOXcdtUUTXZHk
codeberg.org/gruf/go-sched v1.2.3/go.mod h1:vT9uB6KWFIIwnG9vcPY2a0alYNoqdL1mSzRM8I+PK7A=
codeberg.org/gruf/go-store/v2 v2.2.4 h1:8HO1Jh2gg7boQKA3hsDAIXd9zwieu5uXwDXEcTOD9js=
codeberg.org/gruf/go-store/v2 v2.2.4/go.mod h1:zI4VWe5CpXAktYMtaBMrgA5QmO0sQH53LBRvfn1huys=
codeberg.org/gruf/go-structr v0.8.0 h1:aZ+ziv2R6zTU16PW7B2d349wY9Du3mObc3hCeUIqtME=
codeberg.org/gruf/go-structr v0.8.0/go.mod h1:K1FXkUyO6N/JKt8aWqyQ8rtW7Z9ZmXKWP8mFAQ2OJjE=
codeberg.org/gruf/go-structr v0.8.2 h1:0zH5HuOZWTVOGqIq8o5W1jRi944CQWdPXUWZfKUbF0o=
codeberg.org/gruf/go-structr v0.8.2/go.mod h1:K1FXkUyO6N/JKt8aWqyQ8rtW7Z9ZmXKWP8mFAQ2OJjE=
codeberg.org/superseriousbusiness/exif-terminator v0.7.0 h1:Y6VApSXhKqExG0H2hZ2JelRK4xmWdjDQjn13CpEfzko=
codeberg.org/superseriousbusiness/exif-terminator v0.7.0/go.mod h1:gCWKduudUWFzsnixoMzu0FYVdxHWG+AbXnZ50DqxsUE=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=

View File

@ -70,8 +70,6 @@ func (suite *FileserverTestSuite) SetupSuite() {
testrig.InitTestConfig()
testrig.InitTestLog()
suite.db = testrig.NewTestDB(&suite.state)
suite.state.DB = suite.db
suite.storage = testrig.NewInMemoryStorage()
suite.state.Storage = suite.storage
@ -98,8 +96,12 @@ func (suite *FileserverTestSuite) SetupTest() {
suite.state.Caches.Init()
testrig.StartNoopWorkers(&suite.state)
suite.db = testrig.NewTestDB(&suite.state)
suite.state.DB = suite.db
testrig.StandardDBSetup(suite.db, nil)
testrig.StandardStorageSetup(suite.storage, "../../../testrig/media")
suite.testTokens = testrig.NewTestTokens()
suite.testClients = testrig.NewTestClients()
suite.testApplications = testrig.NewTestApplications()

View File

@ -148,15 +148,15 @@ type GTSCaches struct {
// Tag provides access to the gtsmodel Tag database cache.
Tag StructCache[*gtsmodel.Tag]
// ThreadMute provides access to the gtsmodel ThreadMute database cache.
ThreadMute StructCache[*gtsmodel.ThreadMute]
// Token provides access to the gtsmodel Token database cache.
Token StructCache[*gtsmodel.Token]
// Tombstone provides access to the gtsmodel Tombstone database cache.
Tombstone StructCache[*gtsmodel.Tombstone]
// ThreadMute provides access to the gtsmodel ThreadMute database cache.
ThreadMute StructCache[*gtsmodel.ThreadMute]
// User provides access to the gtsmodel User database cache.
User StructCache[*gtsmodel.User]

View File

@ -172,6 +172,8 @@ func totalOfRatios() float64 {
return 0 +
config.GetCacheAccountMemRatio() +
config.GetCacheAccountNoteMemRatio() +
config.GetCacheAccountSettingsMemRatio() +
config.GetCacheAccountStatsMemRatio() +
config.GetCacheApplicationMemRatio() +
config.GetCacheBlockMemRatio() +
config.GetCacheBlockIDsMemRatio() +
@ -179,17 +181,21 @@ func totalOfRatios() float64 {
config.GetCacheClientMemRatio() +
config.GetCacheEmojiMemRatio() +
config.GetCacheEmojiCategoryMemRatio() +
config.GetCacheFilterMemRatio() +
config.GetCacheFilterKeywordMemRatio() +
config.GetCacheFilterStatusMemRatio() +
config.GetCacheFollowMemRatio() +
config.GetCacheFollowIDsMemRatio() +
config.GetCacheFollowRequestMemRatio() +
config.GetCacheFollowRequestIDsMemRatio() +
config.GetCacheInReplyToIDsMemRatio() +
config.GetCacheInstanceMemRatio() +
config.GetCacheInReplyToIDsMemRatio() +
config.GetCacheListMemRatio() +
config.GetCacheListEntryMemRatio() +
config.GetCacheMarkerMemRatio() +
config.GetCacheMediaMemRatio() +
config.GetCacheMentionMemRatio() +
config.GetCacheMoveMemRatio() +
config.GetCacheNotificationMemRatio() +
config.GetCachePollMemRatio() +
config.GetCachePollVoteMemRatio() +

View File

@ -20,6 +20,7 @@
package sqlite
import (
"database/sql/driver"
"fmt"
"modernc.org/sqlite"
@ -42,6 +43,15 @@ func processSQLiteError(err error) error {
case sqlite3.SQLITE_CONSTRAINT_UNIQUE,
sqlite3.SQLITE_CONSTRAINT_PRIMARYKEY:
return db.ErrAlreadyExists
// Busy should be very rare, but
// on busy tell the database to close
// the connection, re-open and re-attempt
// which should give a necessary timeout.
case sqlite3.SQLITE_BUSY,
sqlite3.SQLITE_BUSY_RECOVERY,
sqlite3.SQLITE_BUSY_SNAPSHOT:
return driver.ErrBadConn
}
// Wrap the returned error with the code and

View File

@ -20,6 +20,7 @@
package sqlite
import (
"database/sql/driver"
"fmt"
"github.com/ncruces/go-sqlite3"
@ -40,6 +41,14 @@ func processSQLiteError(err error) error {
case sqlite3.CONSTRAINT_UNIQUE,
sqlite3.CONSTRAINT_PRIMARYKEY:
return db.ErrAlreadyExists
// Busy should be very rare, but on
// busy tell the database to close the
// connection, re-open and re-attempt
// which should give necessary timeout.
case sqlite3.BUSY_RECOVERY,
sqlite3.BUSY_SNAPSHOT:
return driver.ErrBadConn
}
// Wrap the returned error with the code and

View File

@ -30,6 +30,7 @@ type PagingSuite struct {
}
func (suite *PagingSuite) TestPagingStandard() {
config.SetProtocol("https")
config.SetHost("example.org")
params := util.PageableResponseParams{
@ -52,6 +53,7 @@ func (suite *PagingSuite) TestPagingStandard() {
}
func (suite *PagingSuite) TestPagingNoLimit() {
config.SetProtocol("https")
config.SetHost("example.org")
params := util.PageableResponseParams{
@ -73,6 +75,7 @@ func (suite *PagingSuite) TestPagingNoLimit() {
}
func (suite *PagingSuite) TestPagingNoNextID() {
config.SetProtocol("https")
config.SetHost("example.org")
params := util.PageableResponseParams{
@ -94,6 +97,7 @@ func (suite *PagingSuite) TestPagingNoNextID() {
}
func (suite *PagingSuite) TestPagingNoPrevID() {
config.SetProtocol("https")
config.SetHost("example.org")
params := util.PageableResponseParams{
@ -115,6 +119,7 @@ func (suite *PagingSuite) TestPagingNoPrevID() {
}
func (suite *PagingSuite) TestPagingNoItems() {
config.SetProtocol("https")
config.SetHost("example.org")
params := util.PageableResponseParams{

View File

@ -556,6 +556,12 @@ func (c *Cache[T]) Cap() int {
func (c *Cache[T]) store_value(index *Index, key Key, value T) {
// Alloc new index item.
item := new_indexed_item()
if cap(item.indexed) < len(c.indices) {
// Preallocate item indices slice to prevent Go auto
// allocating overlying large slices we don't need.
item.indexed = make([]*index_entry, 0, len(c.indices))
}
// Create COPY of value.
value = c.copy(value)
@ -622,6 +628,14 @@ func (c *Cache[T]) store_error(index *Index, key Key, err error) {
// Alloc new index item.
item := new_indexed_item()
if cap(item.indexed) < len(c.indices) {
// Preallocate item indices slice to prevent Go auto
// allocating overlying large slices we don't need.
item.indexed = make([]*index_entry, 0, len(c.indices))
}
// Set error val.
item.data = err
// Append item to index.

View File

@ -51,8 +51,12 @@ func (i *indexed_item) drop_index(entry *index_entry) {
continue
}
// Unset tptr value to
// ensure GC can take it.
i.indexed[x] = nil
// Move all index entries down + reslice.
copy(i.indexed[x:], i.indexed[x+1:])
_ = copy(i.indexed[x:], i.indexed[x+1:])
i.indexed = i.indexed[:len(i.indexed)-1]
break
}

View File

@ -276,6 +276,12 @@ func (q *Queue[T]) pop_n(n int, next func() *list_elem) []T {
func (q *Queue[T]) index(value T) *indexed_item {
item := new_indexed_item()
if cap(item.indexed) < len(q.indices) {
// Preallocate item indices slice to prevent Go auto
// allocating overlying large slices we don't need.
item.indexed = make([]*index_entry, 0, len(q.indices))
}
// Set item value.
item.data = value

2
vendor/modules.txt vendored
View File

@ -62,7 +62,7 @@ codeberg.org/gruf/go-sched
## explicit; go 1.19
codeberg.org/gruf/go-store/v2/storage
codeberg.org/gruf/go-store/v2/util
# codeberg.org/gruf/go-structr v0.8.0
# codeberg.org/gruf/go-structr v0.8.2
## explicit; go 1.21
codeberg.org/gruf/go-structr
# codeberg.org/superseriousbusiness/exif-terminator v0.7.0