Further performance optimization
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -48,8 +49,13 @@ var (
|
||||
thumbLocks = map[string]*sync.Mutex{}
|
||||
thumbLocksMu sync.Mutex
|
||||
|
||||
digestCache = map[string]digestEntry{}
|
||||
digestCache = map[string]digestEntry{}
|
||||
digestCacheMu sync.Mutex
|
||||
|
||||
// thumbGenSlots bounds concurrent thumbnail generation. A grid of uncached
|
||||
// photos otherwise decodes one full-size image per browser connection at
|
||||
// once, which on the NAS means memory pressure and CPU thrash.
|
||||
thumbGenSlots = make(chan struct{}, runtime.NumCPU())
|
||||
)
|
||||
|
||||
// digestEntry remembers the digest of a source file so repeated requests do
|
||||
@@ -179,7 +185,10 @@ func (h *handler) serveThumbnail(w http.ResponseWriter, r *http.Request, srcFS s
|
||||
return
|
||||
}
|
||||
|
||||
if err := generateThumb(cacheFS, write); err != nil {
|
||||
thumbGenSlots <- struct{}{}
|
||||
err = generateThumb(cacheFS, write)
|
||||
<-thumbGenSlots
|
||||
if err != nil {
|
||||
log.Printf("thumb %s: %v", rel, err)
|
||||
http.Error(w, "thumbnail failed", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user