The forum page now uses EasyJSON to speed it up slightly.

Added SemrushBot to the analytics rather than treating it as an unknown.
The word compatible is now skipped in UA to hopefully avoid allocating a little bit more.
The tickloop is a little more resilient against hard stale connections now.
Removed a temporary benchmark which was used for comparing the built-in JSON library to EasyJSON.

Added the semrush phrase.
This commit is contained in:
Azareal 2019-02-10 19:32:05 +10:00
parent 5099162d9c
commit d5a58421a7
6 changed files with 20 additions and 15 deletions

View File

@ -486,7 +486,8 @@ var agentMapEnum = map[string]int{
"blank": 25, "blank": 25,
"malformed": 26, "malformed": 26,
"suspicious": 27, "suspicious": 27,
"zgrab": 28, "semrush": 28,
"zgrab": 29,
} }
var reverseAgentMapEnum = map[int]string{ var reverseAgentMapEnum = map[int]string{
0: "unknown", 0: "unknown",
@ -517,7 +518,8 @@ var reverseAgentMapEnum = map[int]string{
25: "blank", 25: "blank",
26: "malformed", 26: "malformed",
27: "suspicious", 27: "suspicious",
28: "zgrab", 28: "semrush",
29: "zgrab",
} }
var markToAgent = map[string]string{ var markToAgent = map[string]string{
"OPR": "opera", "OPR": "opera",
@ -543,6 +545,7 @@ var markToAgent = map[string]string{
"Discordbot": "discord", "Discordbot": "discord",
"Twitterbot": "twitter", "Twitterbot": "twitter",
"Discourse": "discourse", "Discourse": "discourse",
"SemrushBot": "semrush",
"zgrab": "zgrab", "zgrab": "zgrab",
} }
/*var agentRank = map[string]int{ /*var agentRank = map[string]int{
@ -762,7 +765,7 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
for _, item := range StringToBytes(ua) { for _, item := range StringToBytes(ua) {
if (item > 64 && item < 91) || (item > 96 && item < 123) { if (item > 64 && item < 91) || (item > 96 && item < 123) {
buffer = append(buffer, item) buffer = append(buffer, item)
} else if item == ' ' || item == '(' || item == ')' || item == '-' || (item > 47 && item < 58) || item == '_' || item == ';' || item == '.' || item == '+' || (item == ':' && bytes.Equal(buffer,[]byte("http"))) || item == ',' || item == '/' { } else if item == ' ' || item == '(' || item == ')' || item == '-' || (item > 47 && item < 58) || item == '_' || item == ';' || item == '.' || item == '+' || item == '~' || (item == ':' && bytes.Equal(buffer,[]byte("http"))) || item == ',' || item == '/' {
if len(buffer) != 0 { if len(buffer) != 0 {
if len(buffer) > 2 { if len(buffer) > 2 {
// Use an unsafe zero copy conversion here just to use the switch, it's not safe for this string to escape from here, as it will get mutated, so do a regular string conversion in append // Use an unsafe zero copy conversion here just to use the switch, it's not safe for this string to escape from here, as it will get mutated, so do a regular string conversion in append
@ -777,8 +780,8 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
os = "iphone" os = "iphone"
case "Android": case "Android":
os = "android" os = "android"
case "like": case "like","compatible":
// Skip this word // Skip these words
default: default:
items = append(items, string(buffer)) items = append(items, string(buffer))
} }

View File

@ -350,10 +350,6 @@ func BenchmarkTopicsGuestJSRouteParallelWithRouter(b *testing.B) {
obRoute(b, "/topics/?js=1") obRoute(b, "/topics/?js=1")
} }
func BenchmarkTopicsGuestEJSRouteParallelWithRouter(b *testing.B) {
obRoute(b, "/topics/?ejs=1")
}
func BenchmarkForumsGuestRouteParallelWithRouter(b *testing.B) { func BenchmarkForumsGuestRouteParallelWithRouter(b *testing.B) {
obRoute(b, "/forums/") obRoute(b, "/forums/")
} }

View File

@ -190,6 +190,7 @@
"discourse":"Discourse Forum Onebox", "discourse":"Discourse Forum Onebox",
"lynx":"Lynx", "lynx":"Lynx",
"semrush":"SemrushBot",
"zgrab":"Zgrab Application Scanner", "zgrab":"Zgrab Application Scanner",
"suspicious":"Suspicious", "suspicious":"Suspicious",
"unknown":"Unknown", "unknown":"Unknown",

View File

@ -221,6 +221,7 @@ func main() {
"blank", "blank",
"malformed", "malformed",
"suspicious", "suspicious",
"semrush",
"zgrab", "zgrab",
} }
@ -255,6 +256,7 @@ func main() {
"Twitterbot", "Twitterbot",
"Discourse", "Discourse",
"SemrushBot",
"zgrab", "zgrab",
} }
@ -284,7 +286,8 @@ func main() {
"Twitterbot": "twitter", "Twitterbot": "twitter",
"Discourse": "discourse", "Discourse": "discourse",
"zgrab": "zgrab", "SemrushBot": "semrush",
"zgrab": "zgrab",
} }
var fileData = `// Code generated by Gosora's Router Generator. DO NOT EDIT. var fileData = `// Code generated by Gosora's Router Generator. DO NOT EDIT.
@ -554,7 +557,7 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
for _, item := range StringToBytes(ua) { for _, item := range StringToBytes(ua) {
if (item > 64 && item < 91) || (item > 96 && item < 123) { if (item > 64 && item < 91) || (item > 96 && item < 123) {
buffer = append(buffer, item) buffer = append(buffer, item)
} else if item == ' ' || item == '(' || item == ')' || item == '-' || (item > 47 && item < 58) || item == '_' || item == ';' || item == '.' || item == '+' || (item == ':' && bytes.Equal(buffer,[]byte("http"))) || item == ',' || item == '/' { } else if item == ' ' || item == '(' || item == ')' || item == '-' || (item > 47 && item < 58) || item == '_' || item == ';' || item == '.' || item == '+' || item == '~' || (item == ':' && bytes.Equal(buffer,[]byte("http"))) || item == ',' || item == '/' {
if len(buffer) != 0 { if len(buffer) != 0 {
if len(buffer) > 2 { if len(buffer) > 2 {
// Use an unsafe zero copy conversion here just to use the switch, it's not safe for this string to escape from here, as it will get mutated, so do a regular string conversion in append // Use an unsafe zero copy conversion here just to use the switch, it's not safe for this string to escape from here, as it will get mutated, so do a regular string conversion in append
@ -569,8 +572,8 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
os = "iphone" os = "iphone"
case "Android": case "Android":
os = "android" os = "android"
case "like": case "like","compatible":
// Skip this word // Skip these words
default: default:
items = append(items, string(buffer)) items = append(items, string(buffer))
} }

View File

@ -2,7 +2,6 @@ package routes
import ( import (
"database/sql" "database/sql"
"encoding/json"
"net/http" "net/http"
"strconv" "strconv"
@ -114,7 +113,7 @@ func ViewForum(w http.ResponseWriter, r *http.Request, user common.User, header
// TODO: Reduce the amount of boilerplate here // TODO: Reduce the amount of boilerplate here
if r.FormValue("js") == "1" { if r.FormValue("js") == "1" {
outBytes, err := json.Marshal(wsTopicList(topicList, lastPage)) outBytes, err := wsTopicList(topicList, lastPage).MarshalJSON()
if err != nil { if err != nil {
return common.InternalError(err, w, r) return common.InternalError(err, w, r)
} }

View File

@ -25,6 +25,7 @@ func startTick() (abort bool) {
if err != nil { if err != nil {
// TODO: There's a bit of a race here, but it doesn't matter if this error appears multiple times in the logs as it's capped at three times, we just want to cut it down 99% of the time // TODO: There's a bit of a race here, but it doesn't matter if this error appears multiple times in the logs as it's capped at three times, we just want to cut it down 99% of the time
if isDBDown == 0 { if isDBDown == 0 {
db.SetConnMaxLifetime(time.Second) // Drop all the connections and start over
common.LogWarning(err) common.LogWarning(err)
common.LogWarning(errors.New("The database is down")) common.LogWarning(errors.New("The database is down"))
} }
@ -34,6 +35,8 @@ func startTick() (abort bool) {
if isDBDown == 1 { if isDBDown == 1 {
log.Print("The database is back") log.Print("The database is back")
} }
//db.SetConnMaxLifetime(time.Second * 60 * 5) // Make this infinite as the temporary lifetime change will purge the stale connections?
db.SetConnMaxLifetime(-1)
atomic.StoreInt32(&common.IsDBDown, 0) atomic.StoreInt32(&common.IsDBDown, 0)
return false return false
} }