이걸 찾아본거는 serverless 어플리케이션을 만들면 내부적으로 knative의 service에서는 어떤 server를 사용하는걸까?
Autoscaled은 어떤 순서로 되는것일까?
1. func main() {
flag.Parse()
log.Print("Hello world app started.")
test.ListenAndServeGracefully(":8080", handler)
}
2. // ListenAndServeGracefully calls into ListenAndServeGracefullyWithPattern
// by passing handler to handle requests for "/"
func ListenAndServeGracefully(addr string, handler func(w http.ResponseWriter, r *http.Request)) {
ListenAndServeGracefullyWithHandler(addr, http.HandlerFunc(handler))
}
3.
// ListenAndServeGracefullyWithHandler creates an HTTP server, listens on the defined address
// and handles incoming requests with the given handler.
// It blocks until SIGTERM is received and the underlying server has shutdown gracefully.
func ListenAndServeGracefullyWithHandler(addr string, handler http.Handler) {
server := pkgnet.NewServer(addr, handler)
go server.ListenAndServe()
<-signals.SetupSignalHandler()
server.Shutdown(context.Background())
}
4.
// NewServer returns a new HTTP Server with HTTP2 handler.
func NewServer(addr string, h http.Handler) *http.Server {
h1s := &http.Server{
Addr: addr,
Handler: h2c.NewHandler(h, &http2.Server{}),
}
return h1s
}
5. $http.Server는 위에 설명한 go의 src/net/http/server.go를 사용하여 server를 만드는 것이였다.
실제로 activator, autoscaler, revision쯤에서 serverless에 사용되는 server를 생성하는게 있을거 같은데...
그리고 statserver, profileserver등이 있었다.
참고로 위에 사용한 http server와 grpc server를 만들때 사용되는 기본코드 이다.
func NewServer(addr string, h http.Handler) *http.Server {
h1s := &http.Server{
Addr: addr,
Handler: h2c.NewHandler(h, &http2.Server{}),
}
return h1s
}
// NewServer creates a gRPC server which has no service registered and has not
// started to accept requests yet.
func NewServer(opt ...ServerOption) *Server {
opts := defaultServerOptions
for _, o := range opt {
o.apply(&opts)
}
s := &Server{
lis: make(map[net.Listener]bool),
opts: opts,
conns: make(map[transport.ServerTransport]bool),
services: make(map[string]*serviceInfo),
quit: grpcsync.NewEvent(),
done: grpcsync.NewEvent(),
czData: new(channelzData),
}
chainUnaryServerInterceptors(s)
chainStreamServerInterceptors(s)
s.cv = sync.NewCond(&s.mu)
if EnableTracing {
_, file, line, _ := runtime.Caller(1)
s.events = trace.NewEventLog("grpc.Server", fmt.Sprintf("%s:%d", file, line))
}
if s.opts.numServerWorkers > 0 {
s.initServerWorkers()
}
if channelz.IsOn() {
s.channelzID = channelz.RegisterServer(&channelzServer{s}, "")
}
return s
}