Skip to content

Commit

Permalink
Increase database timeout and add logging to /api/v2/update
Browse files Browse the repository at this point in the history
This is a stop-gap measure to help with issue #154 until a more scalable
solution is designed. The logging in /api/v2/update times how long it
takes to fetch the preload list from Chromium and how long it takes to
load preloaded domains from the database. The latter currently takes
around 15 seconds for approximately 50,000 entries.
  • Loading branch information
nharper committed Jun 15, 2018
1 parent a7b7953 commit 0dd2991
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions api/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"fmt"
"net/http"
"time"

"github.com/chromium/hstspreload.org/database"
"github.com/chromium/hstspreload/chromium/preloadlist"
Expand Down Expand Up @@ -31,7 +32,9 @@ func (api API) Update(w http.ResponseWriter, r *http.Request) {
// In order to allow visiting the URL directly in the browser, we allow any method.

// Get preload list.
preloadListFetchStart := time.Now()
preloadList, listErr := api.preloadlist.NewFromLatest()
preloadListFetchDuration := time.Since(preloadListFetchStart)
if listErr != nil {
msg := fmt.Sprintf(
"Internal error: could not retrieve latest preload list. (%s)\n",
Expand All @@ -48,7 +51,9 @@ func (api API) Update(w http.ResponseWriter, r *http.Request) {
}

// Get domains currently recorded as preloaded.
preloadedDomainsFetchStart := time.Now()
preloadedDomains, dbErr := api.database.StatesWithStatus(database.StatusPreloaded)
preloadedDomainsFetchDuration := time.Since(preloadedDomainsFetchStart)
if dbErr != nil {
msg := fmt.Sprintf(
"Internal error: could not retrieve domain names previously marked as preloaded. (%s)\n",
Expand Down Expand Up @@ -120,6 +125,8 @@ func (api API) Update(w http.ResponseWriter, r *http.Request) {
len(removed),
len(selfRejected),
)
fmt.Fprintf(w, "Time spent fetching preload list: %s\n", preloadListFetchDuration)
fmt.Fprintf(w, "Time spent loading domains from database: %s\n", preloadedDomainsFetchDuration)

// Create log function to show progress.
written := false
Expand Down
2 changes: 1 addition & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
prodProjectID = "hstspreload"

batchSize = 450
timeout = 10 * time.Second
timeout = 30 * time.Second

domainStateKind = "DomainState"
)
Expand Down

0 comments on commit 0dd2991

Please sign in to comment.