Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions go/cmd/gitter/gitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
persistancePath = path.Join(defaultGitterWorkDir, persistanceFileName)
gitStorePath = path.Join(defaultGitterWorkDir, gitStoreFileName)
fetchTimeout time.Duration
semaphore chan struct{}
)

const shutdownTimeout = 10 * time.Second
Expand Down Expand Up @@ -205,8 +206,11 @@ func main() {
port := flag.Int("port", 8888, "Listen port")
workDir := flag.String("work_dir", defaultGitterWorkDir, "Work directory")
flag.DurationVar(&fetchTimeout, "fetch_timeout", time.Hour, "Fetch timeout duration")
concurrentLimit := flag.Int("concurrent_limit", 100, "Concurrent limit for unique requests")
flag.Parse()

semaphore = make(chan struct{}, *concurrentLimit)

persistancePath = path.Join(*workDir, persistanceFileName)
gitStorePath = path.Join(*workDir, gitStoreFileName)

Expand Down Expand Up @@ -296,6 +300,10 @@ func gitHandler(w http.ResponseWriter, r *http.Request) {
// the repo once, and always with force update.
// This is a tradeoff for simplicity to avoid having to setup locks per repo.
fileData, err, _ := g.Do(url, func() (any, error) {
semaphore <- struct{}{}
defer func() { <-semaphore }()
logger.DebugContext(ctx, "Concurrent processes", slog.Int("count", len(semaphore)))

return fetchBlob(ctx, url, forceUpdate)
})

Expand Down
1 change: 1 addition & 0 deletions go/cmd/gitter/gitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func TestGitHandler_Integration(t *testing.T) {
// but for this simple script we modify package globals.
gitStorePath = tmpDir
fetchTimeout = time.Minute
semaphore = make(chan struct{}, 100)
// Ensure lastFetch map is initialized
if lastFetch == nil {
loadMap()
Expand Down
Loading