Replace encoding/json with goccy/go-json for cpu and memory usage improvement

This new package has significant better resource usage, and we do a _lot_ of JSON parsing in this application, so any amount of improvement becomes significant
This commit is contained in:
Dane Everitt
2022-01-23 15:17:40 -05:00
parent 301788805c
commit 34c0db9dff
21 changed files with 39 additions and 43 deletions

View File

@@ -1,12 +1,12 @@
package filesystem
import (
"encoding/json"
"os"
"strconv"
"time"
"github.com/gabriel-vasile/mimetype"
"github.com/goccy/go-json"
)
type Stat struct {

View File

@@ -125,7 +125,7 @@ func (s *Server) StartEventListeners() {
l.Trigger()
}
s.emitProcUsage()
s.Events().Publish(StatsEvent, s.Proc())
}()
case e := <-docker:
go func() {

View File

@@ -2,7 +2,6 @@ package server
import (
"context"
"encoding/json"
"fmt"
"io"
"os"
@@ -14,6 +13,7 @@ import (
"emperror.dev/errors"
"github.com/apex/log"
"github.com/gammazero/workerpool"
"github.com/goccy/go-json"
"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/environment"

View File

@@ -50,7 +50,3 @@ func (ru *ResourceUsage) Reset() {
ru.Network.TxBytes = 0
ru.Network.RxBytes = 0
}
func (s *Server) emitProcUsage() {
s.Events().Publish(StatsEvent, s.Proc())
}

View File

@@ -2,7 +2,6 @@ package server
import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
@@ -12,6 +11,8 @@ import (
"emperror.dev/errors"
"github.com/apex/log"
"github.com/creasty/defaults"
"github.com/goccy/go-json"
"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/environment"
"github.com/pterodactyl/wings/events"
@@ -312,7 +313,7 @@ func (s *Server) OnStateChange() {
// views in the Panel correctly display 0.
if st == environment.ProcessOfflineState {
s.resources.Reset()
s.emitProcUsage()
s.Events().Publish(StatsEvent, s.Proc())
}
// If server was in an online state, and is now in an offline state we should handle