| Filename | /usr/bin/starman |
| Statements | Executed 0 statements in 0s |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 24µs | 1.49ms | CGI::Compile::ROOT::home_vagrant_kohaclone_circ_ysearch_2epl::BEGIN@39 |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 0 | 1 | 1.49ms | Profile data that couldn't be associated with a specific line: # spent 1.49ms making 1 call to CGI::Compile::ROOT::home_vagrant_kohaclone_circ_ysearch_2epl::BEGIN@39 | ||
| 1 | #!/usr/bin/perl | ||||
| 2 | use strict; | ||||
| 3 | use Plack::Runner; | ||||
| 4 | |||||
| 5 | sub version { | ||||
| 6 | require Starman; | ||||
| 7 | print "Starman $Starman::VERSION\n"; | ||||
| 8 | } | ||||
| 9 | |||||
| 10 | my $preload_app; | ||||
| 11 | |||||
| 12 | require Getopt::Long; | ||||
| 13 | Getopt::Long::Configure("no_ignore_case", "no_auto_abbrev", "pass_through"); | ||||
| 14 | Getopt::Long::GetOptions( | ||||
| 15 | "preload-app" => \$preload_app, | ||||
| 16 | ); | ||||
| 17 | |||||
| 18 | my @args = (server => 'Starman', env => 'deployment', version_cb => \&version); | ||||
| 19 | if (!$preload_app) { | ||||
| 20 | push @args, 'loader' => 'Delayed'; | ||||
| 21 | } | ||||
| 22 | |||||
| 23 | my @argv = @ARGV; | ||||
| 24 | |||||
| 25 | my $runner = Plack::Runner->new(@args); | ||||
| 26 | $runner->parse_options(@argv); | ||||
| 27 | |||||
| 28 | if ($runner->{loader} eq 'Restarter') { | ||||
| 29 | warn <<WARN; | ||||
| 30 | !! | ||||
| 31 | !! Using restarter with -r or -R options is known to cause issues with process supervisor | ||||
| 32 | !! such as start_server, and it is STRONGLY discouraged to use with Starman. You have been warned. | ||||
| 33 | !! | ||||
| 34 | WARN | ||||
| 35 | } | ||||
| 36 | |||||
| 37 | $runner->set_options(argv => \@argv); | ||||
| 38 | $runner->run; | ||||
| 39 | # spent 1.49ms (24µs+1.47) within CGI::Compile::ROOT::home_vagrant_kohaclone_circ_ysearch_2epl::BEGIN@39 which was called:
# once (24µs+1.47ms) by CGI::Compile::ROOT::home_vagrant_kohaclone_circ_ysearch_2epl::CORE:binmode at line 0 | ||||
| 40 | __END__ | ||||
| 41 | |||||
| 42 | =head1 NAME | ||||
| 43 | |||||
| 44 | starman - Starman launcher | ||||
| 45 | |||||
| 46 | =head1 SYNOPSIS | ||||
| 47 | |||||
| 48 | starman --listen :5001 --listen /tmp/starman.sock | ||||
| 49 | starman --workers 32 --port 8080 | ||||
| 50 | |||||
| 51 | =head1 OPTIONS | ||||
| 52 | |||||
| 53 | =over 4 | ||||
| 54 | |||||
| 55 | =item -l, --listen | ||||
| 56 | |||||
| 57 | --listen HOST:PORT --listen :PORT --listen UNIX_SOCKET | ||||
| 58 | --listen HOST:PORT:ssl | ||||
| 59 | |||||
| 60 | Specifies the TCP address, ports and UNIX domain sockets to bind to | ||||
| 61 | wait for requests. You can repeat as many times as you want and mix | ||||
| 62 | TCP and UNIX domain sockets. | ||||
| 63 | |||||
| 64 | For TCP sockets you can append C<:ssl> after the port to specify that | ||||
| 65 | connections on that port should use SSL. Note that the SSL support is | ||||
| 66 | experimental and hasn't been widely tested. | ||||
| 67 | |||||
| 68 | Defaults to any IP address and port 5000. | ||||
| 69 | |||||
| 70 | =item --host | ||||
| 71 | |||||
| 72 | --host 127.0.0.1 | ||||
| 73 | |||||
| 74 | Specifies the address to bind. | ||||
| 75 | |||||
| 76 | This option is for a compatibility with L<plackup> and you're | ||||
| 77 | recommended to use C<--listen> instead. | ||||
| 78 | |||||
| 79 | =item --port | ||||
| 80 | |||||
| 81 | --port 8080 | ||||
| 82 | |||||
| 83 | Specifies the port to bind. | ||||
| 84 | |||||
| 85 | This option is for a compatibility with L<plackup> and you're | ||||
| 86 | recommended to use C<--listen> instead. | ||||
| 87 | |||||
| 88 | =item -S, --socket | ||||
| 89 | |||||
| 90 | -S /tmp/starman.sock | ||||
| 91 | |||||
| 92 | Specifies the path to UNIX domain socket to bind. | ||||
| 93 | |||||
| 94 | This option is for a compatibility with L<plackup> and you're | ||||
| 95 | recommended to use C<--listen> instead. | ||||
| 96 | |||||
| 97 | =item --workers | ||||
| 98 | |||||
| 99 | Specifies the number of worker pool. Defaults to 5. | ||||
| 100 | |||||
| 101 | Starman by default sets up other spare server configuration based on this | ||||
| 102 | workers value, making sure there are B<always only> C<N> worker | ||||
| 103 | processes running. So even if there're no idle workers, Starman won't | ||||
| 104 | spawn off spare processes since that's mostly what you want to do by | ||||
| 105 | fine tuning the memory usage etc. in the production environment. | ||||
| 106 | |||||
| 107 | =item --backlog | ||||
| 108 | |||||
| 109 | Specifies the number of backlog (listen queue size) of listener sockets. Defaults to 1024. | ||||
| 110 | |||||
| 111 | On production systems, setting a very low value can allow failover on | ||||
| 112 | frontend proxy (like nginx) to happen more quickly, if you have | ||||
| 113 | multiple Starman clusters. | ||||
| 114 | |||||
| 115 | If you're doing simple benchmarks and getting connection errors, | ||||
| 116 | increasing this parameter can help avoid them. You should also | ||||
| 117 | consider increasing C<net.core.somaxconn>. Note that this is not | ||||
| 118 | recommended for real production system if you have another cluster to | ||||
| 119 | failover (see above). | ||||
| 120 | |||||
| 121 | =item --max-requests | ||||
| 122 | |||||
| 123 | Number of the requests to process per one worker process. Defaults to 1000. | ||||
| 124 | |||||
| 125 | =item --preload-app | ||||
| 126 | |||||
| 127 | This option lets Starman preload the specified PSGI application in the | ||||
| 128 | master parent process before preforking children. This allows memory | ||||
| 129 | savings with copy-on-write memory management. When not set (default), | ||||
| 130 | forked children loads the application in the initialization hook. | ||||
| 131 | |||||
| 132 | Enabling this option can cause bad things happen when resources like | ||||
| 133 | sockets or database connections are opened at load time by the master | ||||
| 134 | process and shared by multiple children. | ||||
| 135 | |||||
| 136 | Since Starman 0.2000, this option defaults to false, and you should | ||||
| 137 | explicitly set this option to preload the application in the master | ||||
| 138 | process. | ||||
| 139 | |||||
| 140 | Alternatively, you can use -M command line option (plackup's common | ||||
| 141 | option) to preload the I<modules> rather than the <application> | ||||
| 142 | itself. | ||||
| 143 | |||||
| 144 | starman -MCatalyst -MDBIx::Class myapp.psgi | ||||
| 145 | |||||
| 146 | will load the modules in the master process for memory savings with | ||||
| 147 | CoW, but the actual loading of C<myapp.psgi> is done per children, | ||||
| 148 | allowing resource managements such as database connection safer. | ||||
| 149 | |||||
| 150 | If you enable this option, sending C<HUP> signal to the master process | ||||
| 151 | I<will not> pick up any code changes you make. See L</SIGNALS> for | ||||
| 152 | details. | ||||
| 153 | |||||
| 154 | =item --disable-keepalive | ||||
| 155 | |||||
| 156 | Disable Keep-alive persistent connections. It is an useful workaround | ||||
| 157 | if you run Starman behind a broken frontend proxy that tries to pool | ||||
| 158 | connections more than a number of backend workers (i.e. Apache | ||||
| 159 | mpm_prefork + mod_proxy). | ||||
| 160 | |||||
| 161 | =item --keepalive-timeout | ||||
| 162 | |||||
| 163 | The number of seconds Starman will wait for a subsequent request | ||||
| 164 | before closing the connection if Keep-alive persistent connections | ||||
| 165 | are enabled. Setting this to a high value may cause performance | ||||
| 166 | problems in heavily loaded servers. The higher the timeout, the | ||||
| 167 | more backend workers will be kept occupied waiting on connections | ||||
| 168 | with idle clients. | ||||
| 169 | |||||
| 170 | Defaults to 1. | ||||
| 171 | |||||
| 172 | =item --read-timeout | ||||
| 173 | |||||
| 174 | The number of seconds Starman will wait for a request on a new connection | ||||
| 175 | before closing it. Setting this to a high value may cause performance | ||||
| 176 | problems in heavily loaded servers. The higher the timeout, the | ||||
| 177 | more backend workers will be kept occupied waiting on connections | ||||
| 178 | with idle clients. You may need this if your proxy / load balancer likes to | ||||
| 179 | keep a pool of open connections while waiting for clients (eg. Amazon ELB). | ||||
| 180 | |||||
| 181 | Defaults to 5. | ||||
| 182 | |||||
| 183 | =item --user | ||||
| 184 | |||||
| 185 | To listen on a low-numbered (E<lt>1024) port, it will be necessary to | ||||
| 186 | start the server as root. Use the C<--user> option to specify a userid | ||||
| 187 | or username that the server process should switch to after binding to | ||||
| 188 | the port. | ||||
| 189 | |||||
| 190 | Defaults to the current userid. | ||||
| 191 | |||||
| 192 | =item --group | ||||
| 193 | |||||
| 194 | Specify the group id or group name that the server should switch to after | ||||
| 195 | binding to the port. This option is usually used with C<--user>. | ||||
| 196 | |||||
| 197 | Defaults to the current group id. | ||||
| 198 | |||||
| 199 | =item --pid | ||||
| 200 | |||||
| 201 | Specify the pid file path. Use it with C<-D|--daemonize> option, | ||||
| 202 | described in C<plackup -h>. | ||||
| 203 | |||||
| 204 | =item --error-log | ||||
| 205 | |||||
| 206 | Specify the pathname of a file where the error log should be written. | ||||
| 207 | This enables you to still have access to the errors when using C<--daemonize>. | ||||
| 208 | |||||
| 209 | =item --ssl-cert | ||||
| 210 | |||||
| 211 | Specify the path to SSL certificate file. | ||||
| 212 | |||||
| 213 | =item --ssl-key | ||||
| 214 | |||||
| 215 | Specify the path to SSL key file. | ||||
| 216 | |||||
| 217 | =item --enable-ssl | ||||
| 218 | |||||
| 219 | Enable SSL on I<all> TCP sockets. This is an experimental feature. | ||||
| 220 | |||||
| 221 | =item --disable-proctitle | ||||
| 222 | |||||
| 223 | Disable the behavior to set proctitle to "starman (master)" and | ||||
| 224 | "starman (worker)" respectively on master and workers. | ||||
| 225 | |||||
| 226 | =back | ||||
| 227 | |||||
| 228 | Starman passes through other options given to L<Plack::Runner>, the | ||||
| 229 | common backend that L<plackup> uses, so the most options explained in | ||||
| 230 | C<plackup -h> such as C<--access-log> or C<--daemonize> works fine in | ||||
| 231 | starman too. | ||||
| 232 | |||||
| 233 | Setting the environment variable C<STARMAN_DEBUG> to 1 makes the | ||||
| 234 | Starman server running in the debug mode. | ||||
| 235 | |||||
| 236 | =cut | ||||
| 237 | |||||
| 238 | =head1 SIGNALS | ||||
| 239 | |||||
| 240 | =over 4 | ||||
| 241 | |||||
| 242 | =item HUP | ||||
| 243 | |||||
| 244 | Sending C<HUP> signal to the master process will restart all the workers | ||||
| 245 | gracefully (meaning the currently running requests will shut down once | ||||
| 246 | the request is complete), and by default, the workers will pick up the | ||||
| 247 | code changes you make by reloading the application. | ||||
| 248 | |||||
| 249 | If you enable C<--preload-app> option, however, the code will be only | ||||
| 250 | loaded in the startup process and will not pick up the code changes | ||||
| 251 | you made. If you want to preload the app I<and> do graceful restarts | ||||
| 252 | by reloading the code changes, you're recommended to use | ||||
| 253 | L<Server::Starter>, configured to send C<QUIT> signal when superdaemon | ||||
| 254 | received C<HUP>, i.e: | ||||
| 255 | |||||
| 256 | start_server --interval 5 --port 8080 --signal-on-hup=QUIT -- \ | ||||
| 257 | starman --preload-app myapp.psgi | ||||
| 258 | |||||
| 259 | You will then send the HUP signal to C<start_server> process to | ||||
| 260 | gracefully reload the starman cluster (master and workers). | ||||
| 261 | |||||
| 262 | With Server::Starter 0.12 or later, you should also be able to set | ||||
| 263 | C<--signal-on-term> to QUIT so that you can safely shutdown Starman | ||||
| 264 | first and then stop the C<start_server> daemon process as well. | ||||
| 265 | |||||
| 266 | =item TTIN, TTOU | ||||
| 267 | |||||
| 268 | Sending C<TTIN> signal to the master process will dynamically increase | ||||
| 269 | the number of workers, and C<TTOU> signal will decrease it. | ||||
| 270 | |||||
| 271 | =item INT, TERM | ||||
| 272 | |||||
| 273 | Sending C<INT> or C<TERM> signal to the master process will kill all | ||||
| 274 | the workers immediately and shut down the server. | ||||
| 275 | |||||
| 276 | =item QUIT | ||||
| 277 | |||||
| 278 | Sending C<QUIT> signal to the master process will gracefully shutdown | ||||
| 279 | the workers (meaning the currently running requests will shut down | ||||
| 280 | once the request is complete). | ||||
| 281 | |||||
| 282 | =back | ||||
| 283 | |||||
| 284 | =head1 RELOADING THE APPLICATION | ||||
| 285 | |||||
| 286 | You're recommended to use signals (see above) to reload the | ||||
| 287 | application, and are strongly discouraged to use C<-r> or C<-R> | ||||
| 288 | (reloading flag) from plackup. These options will make a separate | ||||
| 289 | directory watcher process, and makes your life difficult if you want to | ||||
| 290 | combine with other process daemon tools such as L<Server::Starter>. | ||||
| 291 | |||||
| 292 | =head1 DIFFERENCES WITH PLACKUP | ||||
| 293 | |||||
| 294 | C<starman> executable is basically the equivalent of using C<plackup> | ||||
| 295 | with C<Starman> server handler i.e. C<plackup -s Starman>, except that | ||||
| 296 | C<starman> delay loads the application with the Delayed loader by | ||||
| 297 | default, which can be disabled with C<--preload-app>. | ||||
| 298 | |||||
| 299 | C<starman> command also automatically sets the environment (C<-E>) to | ||||
| 300 | the value of I<deployment>. | ||||
| 301 | |||||
| 302 | You're recommended to use C<starman> unless there's a reason to stick to | ||||
| 303 | C<plackup> for compatibility. | ||||
| 304 | |||||
| 305 | =head1 SEE ALSO | ||||
| 306 | |||||
| 307 | L<Starman> | ||||
| 308 | |||||
| 309 | =cut |