Optimize function latency when cache expired/invalid under high concurrency (#856)
* Optimize router response time by adding update lock In 0.9.2, the router sends multiple GetServiceForFunction requests to executor to get the service URL. However, the response time of executor will increase under high-concurrency situation due to too many requests are waiting for processing. To solve the problem, an update lock was added to the router. All of goroutines belongs to the same function need to grab the update lock before sending the request. Only the first goroutine which gets the update lock is allowed to send request. In this way, we reduce the burden of executor and lower the failure rate.
This commit is contained in:
+13
-1
@@ -53,10 +53,12 @@ type HTTPTriggerSet struct {
|
||||
updateRouterRequestChannel chan struct{}
|
||||
tsRoundTripperParams *tsRoundTripperParams
|
||||
isDebugEnv bool
|
||||
svcAddrUpdateLocks *svcAddrUpdateLocks
|
||||
}
|
||||
|
||||
func makeHTTPTriggerSet(fmap *functionServiceMap, frmap *functionRecorderMap, trmap *triggerRecorderMap, fissionClient *crd.FissionClient,
|
||||
kubeClient *kubernetes.Clientset, executor *executorClient.Client, crdClient *rest.RESTClient, params *tsRoundTripperParams, isDebugEnv bool) (*HTTPTriggerSet, k8sCache.Store, k8sCache.Store) {
|
||||
kubeClient *kubernetes.Clientset, executor *executorClient.Client, crdClient *rest.RESTClient, params *tsRoundTripperParams, isDebugEnv bool, locks *svcAddrUpdateLocks) (*HTTPTriggerSet, k8sCache.Store, k8sCache.Store) {
|
||||
|
||||
httpTriggerSet := &HTTPTriggerSet{
|
||||
functionServiceMap: fmap,
|
||||
triggers: []crd.HTTPTrigger{},
|
||||
@@ -67,6 +69,7 @@ func makeHTTPTriggerSet(fmap *functionServiceMap, frmap *functionRecorderMap, tr
|
||||
updateRouterRequestChannel: make(chan struct{}),
|
||||
tsRoundTripperParams: params,
|
||||
isDebugEnv: isDebugEnv,
|
||||
svcAddrUpdateLocks: locks,
|
||||
}
|
||||
var tStore, fnStore, rStore k8sCache.Store
|
||||
var tController, fnController k8sCache.Controller
|
||||
@@ -153,8 +156,16 @@ func (ts *HTTPTriggerSet) getRouter() *mux.Router {
|
||||
tsRoundTripperParams: ts.tsRoundTripperParams,
|
||||
recorderName: recorderName,
|
||||
isDebugEnv: ts.isDebugEnv,
|
||||
svcAddrUpdateLocks: ts.svcAddrUpdateLocks,
|
||||
}
|
||||
|
||||
// The functionHandler for HTTP trigger with fn reference type "FunctionReferenceTypeFunctionName",
|
||||
// it's function metadata is set here.
|
||||
|
||||
// The functionHandler For HTTP trigger with fn reference type "FunctionReferenceTypeFunctionWeights",
|
||||
// it's function metadata is decided dynamically before proxying the request in order to support canary
|
||||
// deployment. For more details, please check "handler" function of functionHandler.
|
||||
|
||||
if rr.resolveResultType == resolveResultSingleFunction {
|
||||
for _, metadata := range fh.functionMetadataMap {
|
||||
fh.function = metadata
|
||||
@@ -201,6 +212,7 @@ func (ts *HTTPTriggerSet) getRouter() *mux.Router {
|
||||
tsRoundTripperParams: ts.tsRoundTripperParams,
|
||||
recorderName: recorderName,
|
||||
isDebugEnv: ts.isDebugEnv,
|
||||
svcAddrUpdateLocks: ts.svcAddrUpdateLocks,
|
||||
}
|
||||
muxRouter.HandleFunc(fission.UrlForFunction(function.Metadata.Name, function.Metadata.Namespace), fh.handler)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user