Procházet zdrojové kódy

Always use SetGCPercent(5)

- To reduce memory spikes, continuous, aggressive
  garbage collection is required since ssh, http2,
  and quic-go components continuously allocate fresh
  memory while relaying data within an established
  tunnel.
Rod Hynes před 7 roky
rodič
revize
6e5013ccd7
4 změnil soubory, kde provedl 12 přidání a 25 odebrání
  1. 7 7
      psiphon/controller.go
  2. 3 3
      psiphon/dataStore.go
  3. 1 1
      psiphon/remoteServerList.go
  4. 1 14
      psiphon/utils.go

+ 7 - 7
psiphon/controller.go

@@ -663,7 +663,7 @@ loop:
 				// Clear the reference to this discarded tunnel and immediately run
 				// Clear the reference to this discarded tunnel and immediately run
 				// a garbage collection to reclaim its memory.
 				// a garbage collection to reclaim its memory.
 				connectedTunnel = nil
 				connectedTunnel = nil
-				defaultGarbageCollection()
+				DoGarbageCollection()
 
 
 				// Skip the rest of this case
 				// Skip the rest of this case
 				break
 				break
@@ -1047,7 +1047,7 @@ func (controller *Controller) startEstablishing() {
 	controller.peakConcurrentIntensiveEstablishTunnels = 0
 	controller.peakConcurrentIntensiveEstablishTunnels = 0
 	controller.concurrentEstablishTunnelsMutex.Unlock()
 	controller.concurrentEstablishTunnelsMutex.Unlock()
 
 
-	aggressiveGarbageCollection()
+	DoGarbageCollection()
 	emitMemoryMetrics()
 	emitMemoryMetrics()
 
 
 	// Note: the establish context cancelFunc, controller.stopEstablish,
 	// Note: the establish context cancelFunc, controller.stopEstablish,
@@ -1213,7 +1213,7 @@ func (controller *Controller) stopEstablishing() {
 	NoticeInfo("peak concurrent resource intensive establish tunnels: %d", peakConcurrentIntensive)
 	NoticeInfo("peak concurrent resource intensive establish tunnels: %d", peakConcurrentIntensive)
 
 
 	emitMemoryMetrics()
 	emitMemoryMetrics()
-	standardGarbageCollection()
+	DoGarbageCollection()
 }
 }
 
 
 func (controller *Controller) getTactics(done chan struct{}) {
 func (controller *Controller) getTactics(done chan struct{}) {
@@ -1316,7 +1316,7 @@ func (controller *Controller) getTactics(done chan struct{}) {
 
 
 	// Reclaim memory from the completed tactics request as we're likely
 	// Reclaim memory from the completed tactics request as we're likely
 	// to be proceeding to the memory-intensive tunnel establishment phase.
 	// to be proceeding to the memory-intensive tunnel establishment phase.
-	aggressiveGarbageCollection()
+	DoGarbageCollection()
 	emitMemoryMetrics()
 	emitMemoryMetrics()
 }
 }
 
 
@@ -1737,7 +1737,7 @@ loop:
 
 
 		// ConnectTunnel will allocate significant memory, so first attempt to
 		// ConnectTunnel will allocate significant memory, so first attempt to
 		// reclaim as much as possible.
 		// reclaim as much as possible.
-		defaultGarbageCollection()
+		DoGarbageCollection()
 
 
 		tunnel, err := ConnectTunnel(
 		tunnel, err := ConnectTunnel(
 			controller.establishCtx,
 			controller.establishCtx,
@@ -1767,7 +1767,7 @@ loop:
 		if err != nil {
 		if err != nil {
 			tunnel = nil
 			tunnel = nil
 		}
 		}
-		defaultGarbageCollection()
+		DoGarbageCollection()
 
 
 		if err != nil {
 		if err != nil {
 
 
@@ -1801,7 +1801,7 @@ loop:
 			// Clear the reference to this discarded tunnel and immediately run
 			// Clear the reference to this discarded tunnel and immediately run
 			// a garbage collection to reclaim its memory.
 			// a garbage collection to reclaim its memory.
 			tunnel = nil
 			tunnel = nil
-			defaultGarbageCollection()
+			DoGarbageCollection()
 		}
 		}
 
 
 		// Unblock other candidates only after delivering when
 		// Unblock other candidates only after delivering when

+ 3 - 3
psiphon/dataStore.go

@@ -260,7 +260,7 @@ func StreamingStoreServerEntries(
 
 
 		n += 1
 		n += 1
 		if n == datastoreServerEntryFetchGCThreshold {
 		if n == datastoreServerEntryFetchGCThreshold {
-			defaultGarbageCollection()
+			DoGarbageCollection()
 			n = 0
 			n = 0
 		}
 		}
 	}
 	}
@@ -605,7 +605,7 @@ func (iterator *ServerEntryIterator) Next() (*protocol.ServerEntry, error) {
 		}
 		}
 
 
 		if iterator.serverEntryIndex%datastoreServerEntryFetchGCThreshold == 0 {
 		if iterator.serverEntryIndex%datastoreServerEntryFetchGCThreshold == 0 {
-			defaultGarbageCollection()
+			DoGarbageCollection()
 		}
 		}
 
 
 		// Check filter requirements
 		// Check filter requirements
@@ -660,7 +660,7 @@ func scanServerEntries(scanner func(*protocol.ServerEntry)) error {
 
 
 			n += 1
 			n += 1
 			if n == datastoreServerEntryFetchGCThreshold {
 			if n == datastoreServerEntryFetchGCThreshold {
-				defaultGarbageCollection()
+				DoGarbageCollection()
 				n = 0
 				n = 0
 			}
 			}
 		}
 		}

+ 1 - 1
psiphon/remoteServerList.go

@@ -317,7 +317,7 @@ func FetchObfuscatedServerLists(
 		// a garbage collection to reclaim its memory before processing the
 		// a garbage collection to reclaim its memory before processing the
 		// next file.
 		// next file.
 		serverListPayloadReader = nil
 		serverListPayloadReader = nil
-		defaultGarbageCollection()
+		DoGarbageCollection()
 	}
 	}
 
 
 	// Now that a new registry is downloaded, validated, and parsed, store
 	// Now that a new registry is downloaded, validated, and parsed, store

+ 1 - 14
psiphon/utils.go

@@ -214,20 +214,7 @@ func emitMemoryMetrics() {
 		common.FormatByteCount(memStats.NextGC))
 		common.FormatByteCount(memStats.NextGC))
 }
 }
 
 
-func aggressiveGarbageCollection() {
+func DoGarbageCollection() {
 	debug.SetGCPercent(5)
 	debug.SetGCPercent(5)
 	debug.FreeOSMemory()
 	debug.FreeOSMemory()
 }
 }
-
-func standardGarbageCollection() {
-	debug.SetGCPercent(100)
-	debug.FreeOSMemory()
-}
-
-func defaultGarbageCollection() {
-	debug.FreeOSMemory()
-}
-
-func DoGarbageCollection() {
-	defaultGarbageCollection()
-}