Skip to content

Commit 62eb1b0

Browse files
zeripathguillep2klafrikstechknowlogicklunny
authored andcommitted
Graceful Queues: Issue Indexing and Tasks (#9363)
* Queue: Add generic graceful queues with settings * Queue & Setting: Add worker pool implementation * Queue: Add worker settings * Queue: Make resizing worker pools * Queue: Add name variable to queues * Queue: Add monitoring * Queue: Improve logging * Issues: Gracefulise the issues indexer Remove the old now unused specific queues * Task: Move to generic queue and gracefulise * Issues: Standardise the issues indexer queue settings * Fix test * Queue: Allow Redis to connect to unix * Prevent deadlock during early shutdown of issue indexer * Add MaxWorker settings to queues * Merge branch 'master' into graceful-queues * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <[email protected]> * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <[email protected]> * Update modules/queue/queue_channel.go Co-Authored-By: guillep2k <[email protected]> * Update modules/queue/queue_disk.go * Update modules/queue/queue_disk_channel.go Co-Authored-By: guillep2k <[email protected]> * Rename queue.Description to queue.ManagedQueue as per @guillep2k * Cancel pool workers when removed * Remove dependency on queue from setting * Update modules/queue/queue_redis.go Co-Authored-By: guillep2k <[email protected]> * As per @guillep2k add mutex locks on shutdown/terminate * move unlocking out of setInternal * Add warning if number of workers < 0 * Small changes as per @guillep2k * No redis host specified not found * Clean up documentation for queues * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md * Update modules/indexer/issues/indexer_test.go * Ensure that persistable channel queue is added to manager * Rename QUEUE_NAME REDIS_QUEUE_NAME * Revert "Rename QUEUE_NAME REDIS_QUEUE_NAME" This reverts commit 1f83b4f. Co-authored-by: guillep2k <[email protected]> Co-authored-by: Lauris BH <[email protected]> Co-authored-by: techknowlogick <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent f71e1c8 commit 62eb1b0

35 files changed

+2875
-647
lines changed

custom/conf/app.ini.sample

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,39 @@ REPO_INDEXER_INCLUDE =
382382
; A comma separated list of glob patterns to exclude from the index; ; default is empty
383383
REPO_INDEXER_EXCLUDE =
384384

385+
[queue]
386+
; Specific queues can be individually configured with [queue.name]. [queue] provides defaults
387+
;
388+
; General queue queue type, currently support: persistable-channel, channel, level, redis, dummy
389+
; default to persistable-channel
390+
TYPE = persistable-channel
391+
; data-dir for storing persistable queues and level queues, individual queues will be named by their type
392+
DATADIR = queues/
393+
; Default queue length before a channel queue will block
394+
LENGTH = 20
395+
; Batch size to send for batched queues
396+
BATCH_LENGTH = 20
397+
; Connection string for redis queues this will store the redis connection string.
398+
CONN_STR = "addrs=127.0.0.1:6379 db=0"
399+
; Provide the suffix of the default redis queue name - specific queues can be overriden within in their [queue.name] sections.
400+
QUEUE_NAME = "_queue"
401+
; If the queue cannot be created at startup - level queues may need a timeout at startup - wrap the queue:
402+
WRAP_IF_NECESSARY = true
403+
; Attempt to create the wrapped queue at max
404+
MAX_ATTEMPTS = 10
405+
; Timeout queue creation
406+
TIMEOUT = 15m30s
407+
; Create a pool with this many workers
408+
WORKERS = 1
409+
; Dynamically scale the worker pool to at this many workers
410+
MAX_WORKERS = 10
411+
; Add boost workers when the queue blocks for BLOCK_TIMEOUT
412+
BLOCK_TIMEOUT = 1s
413+
; Remove the boost workers after BOOST_TIMEOUT
414+
BOOST_TIMEOUT = 5m
415+
; During a boost add BOOST_WORKERS
416+
BOOST_WORKERS = 5
417+
385418
[admin]
386419
; Disallow regular (non-admin) users from creating organizations.
387420
DISABLE_REGULAR_ORG_CREATION = false

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ relation to port exhaustion.
226226

227227
- `ISSUE_INDEXER_TYPE`: **bleve**: Issue indexer type, currently support: bleve or db, if it's db, below issue indexer item will be invalid.
228228
- `ISSUE_INDEXER_PATH`: **indexers/issues.bleve**: Index file used for issue search.
229+
- The next 4 configuration values are deprecated and should be set in `queue.issue_indexer` however are kept for backwards compatibility:
229230
- `ISSUE_INDEXER_QUEUE_TYPE`: **levelqueue**: Issue indexer queue, currently supports:`channel`, `levelqueue`, `redis`.
230231
- `ISSUE_INDEXER_QUEUE_DIR`: **indexers/issues.queue**: When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this will be the queue will be saved path.
231232
- `ISSUE_INDEXER_QUEUE_CONN_STR`: **addrs=127.0.0.1:6379 db=0**: When `ISSUE_INDEXER_QUEUE_TYPE` is `redis`, this will store the redis connection string.
@@ -239,6 +240,24 @@ relation to port exhaustion.
239240
- `MAX_FILE_SIZE`: **1048576**: Maximum size in bytes of files to be indexed.
240241
- `STARTUP_TIMEOUT`: **30s**: If the indexer takes longer than this timeout to start - fail. (This timeout will be added to the hammer time above for child processes - as bleve will not start until the previous parent is shutdown.) Set to zero to never timeout.
241242

243+
## Queue (`queue` and `queue.*`)
244+
245+
- `TYPE`: **persistable-channel**: General queue type, currently support: `persistable-channel`, `channel`, `level`, `redis`, `dummy`
246+
- `DATADIR`: **queues/**: Base DataDir for storing persistent and level queues. `DATADIR` for inidividual queues can be set in `queue.name` sections but will default to `DATADIR/`**`name`**.
247+
- `LENGTH`: **20**: Maximal queue size before channel queues block
248+
- `BATCH_LENGTH`: **20**: Batch data before passing to the handler
249+
- `CONN_STR`: **addrs=127.0.0.1:6379 db=0**: Connection string for the redis queue type.
250+
- `QUEUE_NAME`: **_queue**: The suffix for default redis queue name. Individual queues will default to **`name`**`QUEUE_NAME` but can be overriden in the specific `queue.name` section.
251+
- `WRAP_IF_NECESSARY`: **true**: Will wrap queues with a timeoutable queue if the selected queue is not ready to be created - (Only relevant for the level queue.)
252+
- `MAX_ATTEMPTS`: **10**: Maximum number of attempts to create the wrapped queue
253+
- `TIMEOUT`: **GRACEFUL_HAMMER_TIME + 30s**: Timeout the creation of the wrapped queue if it takes longer than this to create.
254+
- Queues by default come with a dynamically scaling worker pool. The following settings configure this:
255+
- `WORKERS`: **1**: Number of initial workers for the queue.
256+
- `MAX_WORKERS`: **10**: Maximum number of worker go-routines for the queue.
257+
- `BLOCK_TIMEOUT`: **1s**: If the queue blocks for this time, boost the number of workers - the `BLOCK_TIMEOUT` will then be doubled before boosting again whilst the boost is ongoing.
258+
- `BOOST_TIMEOUT`: **5m**: Boost workers will timeout after this long.
259+
- `BOOST_WORKERS`: **5**: This many workers will be added to the worker pool if there is a boost.
260+
242261
## Admin (`admin`)
243262
- `DEFAULT_EMAIL_NOTIFICATIONS`: **enabled**: Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
244263

@@ -614,6 +633,7 @@ You may redefine `ELEMENT`, `ALLOW_ATTR`, and `REGEXP` multiple times; each time
614633

615634
## Task (`task`)
616635

636+
- Task queue configuration has been moved to `queue.task` however, the below configuration values are kept for backwards compatibilityx:
617637
- `QUEUE_TYPE`: **channel**: Task queue type, could be `channel` or `redis`.
618638
- `QUEUE_LENGTH`: **1000**: Task queue length, available only when `QUEUE_TYPE` is `channel`.
619639
- `QUEUE_CONN_STR`: **addrs=127.0.0.1:6379 db=0**: Task queue connection string, available only when `QUEUE_TYPE` is `redis`. If there redis needs a password, use `addrs=127.0.0.1:6379 password=123 db=0`.

integrations/issue_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import (
1111
"strconv"
1212
"strings"
1313
"testing"
14+
"time"
1415

1516
"code.gitea.io/gitea/models"
17+
"code.gitea.io/gitea/modules/indexer/issues"
1618
"code.gitea.io/gitea/modules/references"
1719
"code.gitea.io/gitea/modules/setting"
1820
"code.gitea.io/gitea/modules/test"
@@ -87,7 +89,12 @@ func TestViewIssuesKeyword(t *testing.T) {
8789
defer prepareTestEnv(t)()
8890

8991
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
90-
92+
issue := models.AssertExistsAndLoadBean(t, &models.Issue{
93+
RepoID: repo.ID,
94+
Index: 1,
95+
}).(*models.Issue)
96+
issues.UpdateIssueIndexer(issue)
97+
time.Sleep(time.Second * 1)
9198
const keyword = "first"
9299
req := NewRequestf(t, "GET", "%s/issues?q=%s", repo.RelLink(), keyword)
93100
resp := MakeRequest(t, req, http.StatusOK)

modules/indexer/issues/db.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ func (db *DBIndexer) Delete(ids ...int64) error {
2525
return nil
2626
}
2727

28+
// Close dummy function
29+
func (db *DBIndexer) Close() {
30+
}
31+
2832
// Search dummy function
2933
func (db *DBIndexer) Search(kw string, repoIDs []int64, limit, start int) (*SearchResult, error) {
3034
total, ids, err := models.SearchIssueIDsByKeyword(kw, repoIDs, limit, start)

0 commit comments

Comments
 (0)