Browse Source

Updated for testing auto calculated buffer

TC pushbot 5 4 years ago
parent
commit
40a326ffcf
1 changed files with 13 additions and 1 deletions
  1. 13 1
      file_system.go

+ 13 - 1
file_system.go

@@ -38,6 +38,8 @@ import (
 var (
 	thumbRenderHandler *metadata.RenderHandler
 	shareManager       *share.Manager
+
+	systemReservedUploadMem int64 = 0
 )
 
 type trashedFile struct {
@@ -528,8 +530,12 @@ func system_fs_handleUpload(w http.ResponseWriter, r *http.Request) {
 	//Experimental code: Get the remaining memory and use 1/2 - 10MB of it
 	//See https://golang.org/pkg/mime/multipart/#Reader.ReadForm for why 10MB
 	usedRam, totalRam := usage.GetNumericRAMUsage()
+	autoCalculatedUploadBuf := int64(0)
 	if usedRam > 0 && totalRam > 0 {
-		autoCalculatedUploadBuf := ((totalRam-usedRam)/2)/1048576 - 10
+		//Do not use all RAM. Use only 80% of it
+		totalRam = int64(float64(totalRam) * 0.8)
+		autoCalculatedUploadBuf = ((totalRam-usedRam-systemReservedUploadMem)/2)/1048576 - 12 //12 MB as max memory overflow buffer
+		systemReservedUploadMem += (autoCalculatedUploadBuf + 12)
 		log.Println("*Testing* Upload buffer set to ", autoCalculatedUploadBuf, "MB")
 		err = r.ParseMultipartForm(int64(autoCalculatedUploadBuf) << 20)
 	} else {
@@ -631,6 +637,9 @@ func system_fs_handleUpload(w http.ResponseWriter, r *http.Request) {
 			//Perform a GC afterward
 			runtime.GC()
 
+			//Deduce the buffered memory
+			systemReservedUploadMem -= autoCalculatedUploadBuf
+
 		}(r, file, destination, userinfo)
 	} else {
 		//Use blocking upload and move method
@@ -672,6 +681,9 @@ func system_fs_handleUpload(w http.ResponseWriter, r *http.Request) {
 	//Perform a GC
 	runtime.GC()
 
+	//Deduce the buffered memory
+	systemReservedUploadMem -= autoCalculatedUploadBuf
+
 	//Completed
 	sendOK(w)