Explorar o código

feat: support max launching runtime

Yeuoly hai 8 meses
pai
achega
44ca0f71d6

+ 1 - 1
internal/core/plugin_manager/local_manager/stdio_handle.go

@@ -157,7 +157,7 @@ func (s *stdioHolder) Wait() error {
 		select {
 		case <-ticker.C:
 			// check heartbeat
-			if time.Since(s.last_active_at) > 20*time.Second {
+			if time.Since(s.last_active_at) > 60*time.Second {
 				return plugin_errors.ErrPluginNotActive
 			}
 		case <-s.health_chan:

+ 0 - 1
internal/core/plugin_manager/local_manager/stdio_store.go

@@ -69,7 +69,6 @@ func OnError(id string, session_id string, listener func([]byte)) {
 			holder.error_listener[session_id] = listener
 		}
 	}
-
 }
 
 func RemoveStdioListener(id string, listener string) {

+ 4 - 0
internal/core/plugin_manager/manager.go

@@ -55,6 +55,9 @@ type PluginManager struct {
 
 	// remote plugin server
 	remotePluginServer remote_manager.RemotePluginServerInterface
+
+	// max launching lock to prevent too many plugins launching at the same time
+	maxLaunchingLock chan bool
 }
 
 var (
@@ -72,6 +75,7 @@ func InitGlobalManager(configuration *app.Config) *PluginManager {
 			configuration.PluginMediaCacheSize,
 		),
 		localPluginLaunchingLock: lock.NewGranularityLock(),
+		maxLaunchingLock:         make(chan bool, 2), // by default, we allow 2 plugins launching at the same time
 		pythonInterpreterPath:    configuration.PythonInterpreterPath,
 	}
 

+ 10 - 0
internal/core/plugin_manager/watcher.go

@@ -180,6 +180,16 @@ func (p *PluginManager) launchLocal(plugin_package_path string) (
 			}
 			p.m.Delete(identity.String())
 		}()
+
+		// add max launching lock to prevent too many plugins launching at the same time
+		p.maxLaunchingLock <- true
+		routine.Submit(func() {
+			// wait for plugin launched
+			<-launched_chan
+			// release max launching lock
+			<-p.maxLaunchingLock
+		})
+
 		p.fullDuplexLifetime(local_plugin_runtime, launched_chan)
 	})