mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-18 05:32:02 +08:00
prefetch custom cores, -jobs=3
This commit is contained in:
parent
c0f5368319
commit
f4a1bad454
@ -39,6 +39,7 @@ const version = "0.0.3"
|
||||
|
||||
var configPath string
|
||||
var prefetch bool
|
||||
var jobs int
|
||||
var dumpConfig bool
|
||||
var dumpSystemd bool
|
||||
|
||||
@ -159,6 +160,7 @@ func webpEncoder(p1, p2 string, quality float32, Log bool, c chan int) (err erro
|
||||
func init() {
|
||||
flag.StringVar(&configPath, "config", "config.json", "/path/to/config.json. (Default: ./config.json)")
|
||||
flag.BoolVar(&prefetch, "prefetch", false, "Prefetch and convert image to webp")
|
||||
flag.IntVar(&jobs, "jobs", runtime.NumCPU(), "Prefetch thread, default is all.")
|
||||
flag.BoolVar(&dumpConfig, "dump-config", false, "Print sample config.json")
|
||||
flag.BoolVar(&dumpSystemd, "dump-systemd", false, "Print sample systemd service file.")
|
||||
flag.Parse()
|
||||
@ -278,8 +280,9 @@ func prefetchImages(confImgPath string, ExhaustPath string, QUALITY string) {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
char, _, _ := reader.ReadRune() //y Y enter
|
||||
// maximum ongoing prefetch is depending on your core of CPU
|
||||
var finishChan = make(chan int, runtime.NumCPU())
|
||||
for i := 0; i < runtime.NumCPU(); i++ {
|
||||
log.Printf("Prefetching using %d cores", jobs)
|
||||
var finishChan = make(chan int, jobs)
|
||||
for i := 0; i < jobs; i++ {
|
||||
finishChan <- 0
|
||||
}
|
||||
if char == 121 || char == 10 || char == 89 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user