Skip to content

Commit 0568c6d

Browse files
committed
Speed up TCP Server initialisation
Previously the TCP Server would only start after parts of Puppet were initialised. This commit changes the startup behaviour so that the TCP Server is running as soon as the Puppet Version can be determined, and further initialisation is handed to a different thread. A new command line option of --start-slow is added, mainly for testing, to slow down the startup if required. This will help when the server is started by the VSCode client directly so that the TCP socket is available as soon as possible.
1 parent df0dcab commit 0568c6d

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

server/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Usage: puppet-languageserver.rb [options]
7676
-t, --timeout=TIMEOUT Stop the language server if a client does not connection within TIMEOUT seconds. A value of zero will not timeout. Default is 10 seconds
7777
-d, --no-preload Do not preload Puppet information when the language server starts. Default is to preload
7878
--debug=DEBUG Output debug information. Either specify a filename or 'STDOUT'. Default is no debug output
79+
-s, --slow-start Delay starting the TCP Server until Puppet initialisation has completed. Default is to start fast
7980
-h, --help Prints this help
8081
```
8182

server/lib/puppet-languageserver.rb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def self.parse(options)
2626
:stop_on_client_exit => true,
2727
:connection_timeout => 10,
2828
:preload_puppet => true,
29-
:debug => nil
29+
:debug => nil,
30+
:fast_start_tcpserver => true
3031
}
3132

3233
opt_parser = OptionParser.new do |opts|
@@ -56,6 +57,10 @@ def self.parse(options)
5657
args[:debug] = debug
5758
end
5859

60+
opts.on('-s', '--slow-start', 'Delay starting the TCP Server until Puppet initialisation has completed. Default is to start fast') do |_misc|
61+
args[:fast_start_tcpserver] = false
62+
end
63+
5964
opts.on('-h', '--help', 'Prints this help') do
6065
puts opts
6166
exit
@@ -98,6 +103,19 @@ def self.init_puppet(options)
98103
log_message(:info, "Using Puppet v#{Puppet.version}")
99104

100105
log_message(:info, 'Initializing settings...')
106+
if options[:fast_start_tcpserver]
107+
Thread.new do
108+
init_puppet_worker(options)
109+
end
110+
else
111+
init_puppet_worker(options)
112+
end
113+
114+
true
115+
end
116+
117+
def self.init_puppet_worker(options)
118+
log_message('information', 'Initializing settings...')
101119
Puppet.initialize_settings
102120

103121
log_message(:info, 'Creating puppet function environment...')
@@ -117,8 +135,6 @@ def self.init_puppet(options)
117135
else
118136
log_message(:info, 'Skipping preloading Puppet')
119137
end
120-
121-
true
122138
end
123139

124140
def self.rpc_server(options)

0 commit comments

Comments
 (0)