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:
@@ -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 {
|
||||
|
||||
@@ -125,7 +125,7 @@ func (s *Server) StartEventListeners() {
|
||||
l.Trigger()
|
||||
}
|
||||
|
||||
s.emitProcUsage()
|
||||
s.Events().Publish(StatsEvent, s.Proc())
|
||||
}()
|
||||
case e := <-docker:
|
||||
go func() {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user