Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
fe1978c6
Commit
fe1978c6
authored
Jan 21, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New 'cpu' directive; now uses all cores by default (if needed)
parent
509db0b0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
1 deletion
+57
-1
config/config.go
config/config.go
+1
-0
config/directives.go
config/directives.go
+46
-1
server/server.go
server/server.go
+10
-0
No files found.
config/config.go
View file @
fe1978c6
...
...
@@ -65,6 +65,7 @@ type Config struct {
TLS
TLSConfig
Middleware
[]
middleware
.
Middleware
Startup
[]
func
()
error
MaxCPU
int
}
// Address returns the host:port of c as a string.
...
...
config/directives.go
View file @
fe1978c6
package
config
import
"os"
import
(
"os"
"runtime"
"strconv"
"strings"
)
// dirFunc is a type of parsing function which processes
// a particular directive and populates the config.
...
...
@@ -64,5 +69,45 @@ func init() {
p
.
cfg
.
TLS
=
tls
return
nil
},
"cpu"
:
func
(
p
*
parser
)
error
{
sysCores
:=
runtime
.
NumCPU
()
if
!
p
.
nextArg
()
{
return
p
.
argErr
()
}
strNum
:=
p
.
tkn
()
setCPU
:=
func
(
val
int
)
{
if
val
<
1
{
val
=
1
}
if
val
>
sysCores
{
val
=
sysCores
}
if
val
>
p
.
cfg
.
MaxCPU
{
p
.
cfg
.
MaxCPU
=
val
}
}
if
strings
.
HasSuffix
(
strNum
,
"%"
)
{
// Percent
var
percent
float32
pctStr
:=
strNum
[
:
len
(
strNum
)
-
1
]
pctInt
,
err
:=
strconv
.
Atoi
(
pctStr
)
if
err
!=
nil
||
pctInt
<
1
||
pctInt
>
100
{
return
p
.
err
(
"Parse"
,
"Invalid number '"
+
strNum
+
"' (must be a positive percentage between 1 and 100)"
)
}
percent
=
float32
(
pctInt
)
/
100
setCPU
(
int
(
float32
(
sysCores
)
*
percent
))
}
else
{
// Number
num
,
err
:=
strconv
.
Atoi
(
strNum
)
if
err
!=
nil
||
num
<
0
{
return
p
.
err
(
"Parse"
,
"Invalid number '"
+
strNum
+
"' (requires positive integer or percent)"
)
}
setCPU
(
num
)
}
return
nil
},
}
}
server/server.go
View file @
fe1978c6
...
...
@@ -4,6 +4,7 @@ import (
"errors"
"log"
"net/http"
"runtime"
"github.com/mholt/caddy/config"
"github.com/mholt/caddy/middleware"
...
...
@@ -36,6 +37,11 @@ func New(conf config.Config) (*Server, error) {
return
nil
,
errors
.
New
(
"Address "
+
addr
+
" is already in use"
)
}
// Use all CPUs (if needed) by default
if
conf
.
MaxCPU
==
0
{
conf
.
MaxCPU
=
runtime
.
NumCPU
()
}
// Initialize
s
:=
new
(
Server
)
s
.
config
=
conf
...
...
@@ -53,6 +59,10 @@ func (s *Server) Serve() error {
return
err
}
if
s
.
config
.
MaxCPU
>
0
{
runtime
.
GOMAXPROCS
(
s
.
config
.
MaxCPU
)
}
if
s
.
config
.
TLS
.
Enabled
{
return
http
.
ListenAndServeTLS
(
s
.
config
.
Address
(),
s
.
config
.
TLS
.
Certificate
,
s
.
config
.
TLS
.
Key
,
s
)
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment