java - Is servlet architecture faster than CGI because it uses threads instead of processes? -


i new java , web development in general reading tutorial says 1 advantage of servlet pattern on cgi is:

better performance: because creates thread each request not process.

however, not why should so. based on answer, @ least linux, general consensus seems threads not faster processes , might advantageous use processes instead of threads.

in tutorial written cgi works follows:

for each request, starts process , web server limited start processes.

when taking account startup cost of process, make sense. however, not sure why necessary start new process each request, instead of having pool of running cgi shells serving queued requests.

the main performance difference gci forks / execs new process each request, well-designed servlet container creates (bounded) pool of threads on start up, assigns them requests, , recyles them when request completed.

the cost of creating threads (which is significant) amortized on lifetime of servlet container.

if maintain pool of "cgi shells", suppose more efficient. however, normal assumption of cgi app is starting clean sheet.

there couple of other issues:

  • in servlet container can maintain shared session , request caches, shared pools of db connections , on.
  • the performance of cgi implemented using jvm per request awful ... because of overheads of jvm startup / warmup. typical request wouldn't run long enough bytecodes jit compiled.

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -