Skip to content

Commit 5b09bd4

Browse files
authored
Merge branch 'master' into remove-old-ctlogs
2 parents e848338 + c71e2a6 commit 5b09bd4

5 files changed

Lines changed: 35 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99
### Added
1010
- Remove old CT logs as soon as they are removed from the Google CT Loglist (#60)
11+
- New configuration for buffer sizes (#58)
1112
### Changed
1213
### Fixed
1314
### Docs
@@ -18,9 +19,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1819
- Support for non-browsers by implementing server initiated heartbeats (#39)
1920
- Start new ct-watchers as new ct logs become available (#42)
2021
- More logging to document currently watched logs (03d878e)
22+
2123
### Changed
2224
- Changed log output to be better grepable (5c055cc)
2325
- Update ct log update interval to once per hour instead of once per 6 hours as previously (9b6e77d)
26+
2427
### Fixed
2528
- Fixed a possible race condition when accessing metrics
2629

config.sample.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ general:
2828
- url: https://dodo.ct.comodo.com/
2929
operator: "Comodo"
3030
description: "Comodo Dodo"
31+
# To optimize the performance of the server, you can overwrite the size of different buffers
32+
# For low CPU, low memory machines, you should reduce the buffer sizes to save memory in case the CPU is maxed.
33+
buffer_sizes:
34+
# Buffer for each websocket connection
35+
websocket: 300
36+
# Buffer for each CT log connection
37+
ctlog: 1000
38+
# Combined buffer for the broadcast manager
39+
broadcastmanager: 10000
3140
# Google regularly updates the log list. If this option is set to true, the server will remove all old logs.
3241
# This option defaults to true. See https://github.com/d-Rickyy-b/certstream-server-go/issues/51
3342
drop_old_logs: true

internal/certificatetransparency/ct-watcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func (w *worker) runWorker(ctx context.Context) error {
292292
Matcher: scanner.MatchAll{},
293293
PrecertOnly: false,
294294
NumWorkers: 1,
295-
BufferSize: 1000,
295+
BufferSize: config.AppConfig.General.BufferSizes.CTLog,
296296
})
297297

298298
scanErr := certScanner.Scan(ctx, w.foundCertCallback, w.foundPrecertCallback)

internal/config/config.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ type LogConfig struct {
3131
Description string `yaml:"description"`
3232
}
3333

34+
type BufferSizes struct {
35+
Websocket int `yaml:"websocket"`
36+
CTLog int `yaml:"ctlog"`
37+
BroadcastManager int `yaml:"broadcastmanager"`
38+
}
39+
3440
type Config struct {
3541
Webserver struct {
3642
ServerConfig `yaml:",inline"`
@@ -47,6 +53,7 @@ type Config struct {
4753
}
4854
General struct {
4955
AdditionalLogs []LogConfig `yaml:"additional_logs"`
56+
BufferSizes BufferSizes `yaml:"buffer_sizes"`
5057
DropOldLogs *bool `yaml:"drop_old_logs"`
5158
}
5259
}
@@ -212,12 +219,23 @@ func validateConfig(config *Config) bool {
212219

213220
config.General.AdditionalLogs = validLogs
214221

215-
// If the cleanup flag is not set, default to true
222+
if config.General.BufferSizes.Websocket <= 0 {
223+
config.General.BufferSizes.Websocket = 300
224+
}
225+
226+
if config.General.BufferSizes.CTLog <= 0 {
227+
config.General.BufferSizes.CTLog = 1000
228+
}
229+
230+
if config.General.BufferSizes.BroadcastManager <= 0 {
231+
config.General.BufferSizes.BroadcastManager = 10000
232+
233+
// If the cleanup flag is not set, default to true
216234
if config.General.DropOldLogs == nil {
217235
log.Println("drop_old_logs is not set, defaulting to true")
218236
defaultCleanup := true
219237
config.General.DropOldLogs = &defaultCleanup
220-
}
238+
}
221239

222240
return true
223241
}

internal/web/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func upgradeConnection(w http.ResponseWriter, r *http.Request) (*websocket.Conn,
168168

169169
// setupClient initializes a client struct and starts the broadcastHandler and websocket listener.
170170
func setupClient(connection *websocket.Conn, subscriptionType SubscriptionType, name string) {
171-
c := newClient(connection, subscriptionType, name, 300)
171+
c := newClient(connection, subscriptionType, name, config.AppConfig.General.BufferSizes.Websocket)
172172
go c.broadcastHandler()
173173
go c.listenWebsocket()
174174

@@ -275,7 +275,7 @@ func NewWebsocketServer(networkIf string, port int, certPath, keyPath string) *W
275275
setupWebsocketRoutes(server.routes)
276276
server.initServer()
277277

278-
ClientHandler.Broadcast = make(chan models.Entry, 10_000)
278+
ClientHandler.Broadcast = make(chan models.Entry, config.AppConfig.General.BufferSizes.BroadcastManager)
279279
go ClientHandler.broadcaster()
280280

281281
return server

0 commit comments

Comments
 (0)