From cf5007110e1f79338c069408d91eb71badd2166e Mon Sep 17 00:00:00 2001 From: giongto35 Date: Mon, 30 Sep 2019 02:17:38 +0800 Subject: [PATCH] Improve performance (#92) * Update performance * Turn off prometheus * Add gbc * Remove MAXPROCS 1 * Add updte config * Update util + docker ignore --- .dockerignore | 7 ++++++- .gitignore | 5 ++++- pkg/config/config.go | 1 + pkg/emulator/libretro/nanoarch/naemulator.go | 3 +++ pkg/emulator/libretro/nanoarch/nanoarch.go | 10 ++++------ pkg/overlord/config.go | 7 ++++--- pkg/util/util.go | 5 +---- pkg/worker/overworker.go | 5 ----- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.dockerignore b/.dockerignore index 84d4140a..947490d5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,6 @@ -games +*/assets/games/* +.git +.gitignore +LICENSE +VERSION +docs diff --git a/.gitignore b/.gitignore index 400551f7..a4b303e8 100644 --- a/.gitignore +++ b/.gitignore @@ -58,4 +58,7 @@ turnserver.conf ### Ignore build artifact directory bin/ .coverage.out -_output/ \ No newline at end of file +_output/ +./build + +.dockerignore diff --git a/pkg/config/config.go b/pkg/config/config.go index 48cffa07..a50c11bb 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -23,6 +23,7 @@ const NumKeys = 10 var FileTypeToEmulator = map[string]string{ "gba": "gba", + "gbc": "gba", "cue": "pcsx", "zip": "mame", "nes": "nes", diff --git a/pkg/emulator/libretro/nanoarch/naemulator.go b/pkg/emulator/libretro/nanoarch/naemulator.go index 83196f07..65384653 100644 --- a/pkg/emulator/libretro/nanoarch/naemulator.go +++ b/pkg/emulator/libretro/nanoarch/naemulator.go @@ -62,12 +62,15 @@ type naEmulator struct { } var NAEmulator *naEmulator +var outputImg *image.RGBA // NAEmulator implements CloudEmulator interface based on NanoArch(golang RetroArch) func NewNAEmulator(etype string, roomID string, imageChannel chan<- *image.RGBA, audioChannel chan<- float32, inputChannel <-chan int) *naEmulator { meta := config.EmulatorConfig[etype] ewidth = meta.Width eheight = meta.Height + // outputImg is tmp img used for decoding and reuse in encoding flow + outputImg = image.NewRGBA(image.Rect(0, 0, ewidth, eheight)) return &naEmulator{ meta: meta, diff --git a/pkg/emulator/libretro/nanoarch/nanoarch.go b/pkg/emulator/libretro/nanoarch/nanoarch.go index 8541bd36..543ce2b6 100644 --- a/pkg/emulator/libretro/nanoarch/nanoarch.go +++ b/pkg/emulator/libretro/nanoarch/nanoarch.go @@ -153,7 +153,6 @@ func to8888Image(data unsafe.Pointer, bytes []byte, bytesPerRow int, inputWidth, scaleWidth := float64(ewidth) / float64(inputWidth) scaleHeight := float64(eheight) / float64(inputHeight) - image := image.NewRGBA(image.Rect(0, 0, ewidth, eheight)) for y := 0; y < inputHeight; y++ { for x := 0; x < bytesPerRow; x++ { xx := int(float64(x) * scaleWidth) @@ -164,7 +163,7 @@ func to8888Image(data unsafe.Pointer, bytes []byte, bytesPerRow int, inputWidth, r8 := bytes[seek+2] a8 := bytes[seek+3] - image.Set(xx, yy, color.RGBA{byte(r8), byte(g8), byte(b8), byte(a8)}) + outputImg.Set(xx, yy, color.RGBA{byte(r8), byte(g8), byte(b8), byte(a8)}) } seek += 4 @@ -172,7 +171,7 @@ func to8888Image(data unsafe.Pointer, bytes []byte, bytesPerRow int, inputWidth, } // TODO: Resize Image - return image + return outputImg } func to565Image(data unsafe.Pointer, bytes []byte, bytesPerRow int, inputWidth, inputHeight int) *image.RGBA { @@ -182,7 +181,6 @@ func to565Image(data unsafe.Pointer, bytes []byte, bytesPerRow int, inputWidth, scaleWidth := float64(ewidth) / float64(inputWidth) scaleHeight := float64(eheight) / float64(inputHeight) - image := image.NewRGBA(image.Rect(0, 0, ewidth, eheight)) for y := 0; y < inputHeight; y++ { for x := 0; x < bytesPerRow; x++ { xx := int(float64(x) * scaleWidth) @@ -198,7 +196,7 @@ func to565Image(data unsafe.Pointer, bytes []byte, bytesPerRow int, inputWidth, g8 := (g6*255 + 31) / 63 r8 := (r5*255 + 15) / 31 - image.Set(int(float64(xx)*scaleWidth), int(float64(yy)*scaleHeight), color.RGBA{byte(r8), byte(g8), byte(b8), 255}) + outputImg.Set(int(float64(xx)*scaleWidth), int(float64(yy)*scaleHeight), color.RGBA{byte(r8), byte(g8), byte(b8), 255}) } seek += 2 @@ -206,7 +204,7 @@ func to565Image(data unsafe.Pointer, bytes []byte, bytesPerRow int, inputWidth, } // TODO: Resize Image - return image + return outputImg } //export coreInputPoll diff --git a/pkg/overlord/config.go b/pkg/overlord/config.go index e501ffa7..eb03e353 100644 --- a/pkg/overlord/config.go +++ b/pkg/overlord/config.go @@ -18,9 +18,10 @@ func NewDefaultConfig() Config { Port: 8800, MonitoringConfig: monitoring.ServerMonitoringConfig{ - Port: 6601, - URLPrefix: "/overlord", - MetricEnabled: true, + Port: 6601, + URLPrefix: "/overlord", + MetricEnabled: false, + ProfilingEnabled: false, }, } } diff --git a/pkg/util/util.go b/pkg/util/util.go index cabe6a10..47793dd5 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -88,8 +88,5 @@ func savePath(hash string) string { // Actually Android is only supporting VP8 but H264 has better encoding performance // TODO: Better use useragent attribute from frontend func GetVideoEncoder(isMobile bool) string { - if isMobile == true { - return config.CODEC_VP8 - } - return config.CODEC_H264 + return config.CODEC_VP8 } diff --git a/pkg/worker/overworker.go b/pkg/worker/overworker.go index fb5300e6..89a85396 100644 --- a/pkg/worker/overworker.go +++ b/pkg/worker/overworker.go @@ -10,7 +10,6 @@ import ( "github.com/giongto35/cloud-game/pkg/monitoring" "github.com/golang/glog" - "github.com/prometheus/client_golang/prometheus/promhttp" ) type OverWorker struct { @@ -75,10 +74,6 @@ func (o *OverWorker) initializeWorker() { } l.Close() - if port == 9000 { - // only turn on metric for the first worker to avoid overlap - http.Handle("/metrics", promhttp.Handler()) - } // echo endpoint is where user will request to test latency http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) {