added tesseract threads
This commit is contained in:
parent
55b8218860
commit
84d48a6eea
4 changed files with 41 additions and 21 deletions
|
|
@ -29,7 +29,8 @@ const (
|
||||||
defRunUser = "docstore"
|
defRunUser = "docstore"
|
||||||
defRunGroup = "docstore"
|
defRunGroup = "docstore"
|
||||||
|
|
||||||
defTimeout = 600
|
defTimeout = 600
|
||||||
|
tesseractThreads = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -71,8 +72,11 @@ func initServer(cfg core.Config) (err error) {
|
||||||
log.InitLogger(cfg)
|
log.InitLogger(cfg)
|
||||||
|
|
||||||
cfg.DataDir = filepath.Join(cfg.RunDir, core.DataDir)
|
cfg.DataDir = filepath.Join(cfg.RunDir, core.DataDir)
|
||||||
|
debugCfg := cfg
|
||||||
|
debugCfg.Secret = "***hidden***"
|
||||||
|
log.Debugf("docstore config: %+v", debugCfg)
|
||||||
|
|
||||||
scanner, err := scan.New(cfg.DataDir, cfg.Langs, time.Second*time.Duration(cfg.CMDTimeout))
|
scanner, err := scan.New(cfg.DataDir, cfg.Langs, cfg.TesseractThreads, time.Second*time.Duration(cfg.CMDTimeout))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("scanner: " + err.Error())
|
return errors.New("scanner: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -255,6 +259,12 @@ func serverFlags() []cli.Flag {
|
||||||
Usage: "timeout in seconds for executed teseract and pdftotext commands",
|
Usage: "timeout in seconds for executed teseract and pdftotext commands",
|
||||||
Destination: &config.CMDTimeout,
|
Destination: &config.CMDTimeout,
|
||||||
},
|
},
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "threads",
|
||||||
|
Value: tesseractThreads,
|
||||||
|
Usage: "tesseract thread limit (1-4)",
|
||||||
|
Destination: &config.TesseractThreads,
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "foreground, f",
|
Name: "foreground, f",
|
||||||
Usage: "do not fork into the background",
|
Usage: "do not fork into the background",
|
||||||
|
|
|
||||||
|
|
@ -34,17 +34,18 @@ func (p Paths) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
||||||
func (p Paths) Less(i, j int) bool { return p[i].Name < p[j].Name }
|
func (p Paths) Less(i, j int) bool { return p[i].Name < p[j].Name }
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
RunDir string `json:"run_dir,omitempty"`
|
RunDir string `json:"run_dir,omitempty"`
|
||||||
DataDir string `json:"-"`
|
DataDir string `json:"-"`
|
||||||
User string `json:"user,omitempty"`
|
User string `json:"user,omitempty"`
|
||||||
Group string `json:"group,omitempty"`
|
Group string `json:"group,omitempty"`
|
||||||
ListenAddr string `json:"listen_addr,omitempty"`
|
ListenAddr string `json:"listen_addr,omitempty"`
|
||||||
LogFile string `json:"log_file,omitempty"`
|
LogFile string `json:"log_file,omitempty"`
|
||||||
Version string `json:"-"`
|
Version string `json:"-"`
|
||||||
Secret string `json:"secret,omitempty"`
|
Secret string `json:"secret,omitempty"`
|
||||||
Langs []string `json:"langs,omitempty"`
|
Langs []string `json:"langs,omitempty"`
|
||||||
CMDTimeout int `json:"cmd_timeout,omitempty"`
|
CMDTimeout int `json:"cmd_timeout,omitempty"`
|
||||||
Foreground bool `json:"foreground,omitempty"`
|
TesseractThreads int `json:"tesseract_threads,omitempty"`
|
||||||
SecureCookie bool `json:"secure_cookie,omitempty"`
|
Foreground bool `json:"foreground,omitempty"`
|
||||||
Debug bool `json:"debug,omitempty"`
|
SecureCookie bool `json:"secure_cookie,omitempty"`
|
||||||
|
Debug bool `json:"debug,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,15 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const pdfExt = ".pdf"
|
const (
|
||||||
|
pdfExt = ".pdf"
|
||||||
|
|
||||||
|
minThreads = 1
|
||||||
|
maxThreads = 4
|
||||||
|
)
|
||||||
|
|
||||||
type PDF struct {
|
type PDF struct {
|
||||||
cmd string
|
cmd string
|
||||||
|
|
@ -46,7 +50,7 @@ type Scanner struct {
|
||||||
p PDF
|
p PDF
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(base string, langs []string, timeout time.Duration) (s *Scanner, err error) {
|
func New(base string, langs []string, threads int, timeout time.Duration) (s *Scanner, err error) {
|
||||||
var (
|
var (
|
||||||
tcmd string
|
tcmd string
|
||||||
pcmd string
|
pcmd string
|
||||||
|
|
@ -77,11 +81,16 @@ func New(base string, langs []string, timeout time.Duration) (s *Scanner, err er
|
||||||
lang += "+"
|
lang += "+"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if threads > maxThreads {
|
||||||
|
threads = maxThreads
|
||||||
|
} else if threads < minThreads {
|
||||||
|
threads = minThreads
|
||||||
|
}
|
||||||
args := []string{"-l", lang, "--oem", tesseract_oem}
|
args := []string{"-l", lang, "--oem", tesseract_oem}
|
||||||
s = &Scanner{
|
s = &Scanner{
|
||||||
base,
|
base,
|
||||||
timeout,
|
timeout,
|
||||||
Tesseract{tcmd, args, []string{fmt.Sprintf("OMP_THREAD_LIMIT=%d", runtime.NumCPU())}},
|
Tesseract{tcmd, args, []string{fmt.Sprintf("OMP_THREAD_LIMIT=%d", threads)}},
|
||||||
PDF{pcmd, []string{"-layout", "-nopgbrk", "-eol", "unix"}},
|
PDF{pcmd, []string{"-layout", "-nopgbrk", "-eol", "unix"}},
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ const (
|
||||||
<td>File</td>
|
<td>File</td>
|
||||||
<td><div class="btn-group">
|
<td><div class="btn-group">
|
||||||
{{if $item.Scan}}
|
{{if $item.Scan}}
|
||||||
<a href="#" class="btn btn-sm btn-warning">Scanning..</a>
|
<a href="#" class="btn btn-sm btn-warning">Scanning</a>
|
||||||
{{else}}
|
{{else}}
|
||||||
{{if not $item.Flag}}
|
{{if not $item.Flag}}
|
||||||
<a href="/index{{$item.Abs}}" class="btn btn-sm btn-success">Index</a>
|
<a href="/index{{$item.Abs}}" class="btn btn-sm btn-success">Index</a>
|
||||||
|
|
@ -109,7 +109,7 @@ const (
|
||||||
</ol>
|
</ol>
|
||||||
<div class="btn-group btn-breadcrumb">
|
<div class="btn-group btn-breadcrumb">
|
||||||
{{if .Data.Scan}}
|
{{if .Data.Scan}}
|
||||||
<a href="#" class="btn btn-sm btn-warning">Scanning..</a>
|
<a href="#" class="btn btn-sm btn-warning">Scanning</a>
|
||||||
{{else}}
|
{{else}}
|
||||||
{{if not .Data.Flag}}
|
{{if not .Data.Flag}}
|
||||||
<a href="/index{{.Data.Name}}" class="btn btn-sm btn-success">Index</a>
|
<a href="/index{{.Data.Name}}" class="btn btn-sm btn-success">Index</a>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue