Optimize code
This commit is contained in:
committed by
Ta-Ching Chen
parent
01bcfad44a
commit
b578819202
+1
-1
@@ -78,7 +78,7 @@ func (builder *Builder) Handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
elapsed := time.Now().Sub(startTime)
|
elapsed := time.Since(startTime)
|
||||||
log.Printf("elapsed time in build request = %v", elapsed)
|
log.Printf("elapsed time in build request = %v", elapsed)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
Vendored
+2
-2
@@ -61,11 +61,11 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c *Cache) IsOld(v *Value) bool {
|
func (c *Cache) IsOld(v *Value) bool {
|
||||||
if (c.ctimeExpiry != time.Duration(0)) && (time.Now().Sub(v.ctime) > c.ctimeExpiry) {
|
if (c.ctimeExpiry != time.Duration(0)) && (time.Since(v.ctime) > c.ctimeExpiry) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.atimeExpiry != time.Duration(0)) && (time.Now().Sub(v.atime) > c.atimeExpiry) {
|
if (c.atimeExpiry != time.Duration(0)) && (time.Since(v.atime) > c.atimeExpiry) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -169,7 +169,7 @@ func waitForCRDs(crdClient *rest.RESTClient) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if time.Now().Sub(start) > 30*time.Second {
|
if time.Since(start) > 30*time.Second {
|
||||||
return errors.New("timeout waiting for CRDs")
|
return errors.New("timeout waiting for CRDs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -128,7 +128,7 @@ func functionTests(crdClient *rest.RESTClient) {
|
|||||||
if wf.Spec.Environment.Name != function.Spec.Environment.Name {
|
if wf.Spec.Environment.Name != function.Spec.Environment.Name {
|
||||||
log.Panicf("Bad object from watch: %#v", wf)
|
log.Panicf("Bad object from watch: %#v", wf)
|
||||||
}
|
}
|
||||||
log.Printf("watch event took %v", time.Now().Sub(start))
|
log.Printf("watch event took %v", time.Since(start))
|
||||||
recvd = true
|
recvd = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ func environmentTests(crdClient *rest.RESTClient) {
|
|||||||
if obj.Spec.Runtime.Image != environment.Spec.Runtime.Image {
|
if obj.Spec.Runtime.Image != environment.Spec.Runtime.Image {
|
||||||
log.Panicf("Bad object from watch: %#v", obj)
|
log.Panicf("Bad object from watch: %#v", obj)
|
||||||
}
|
}
|
||||||
log.Printf("watch event took %v", time.Now().Sub(start))
|
log.Printf("watch event took %v", time.Since(start))
|
||||||
recvd = true
|
recvd = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,7 +313,7 @@ func httpTriggerTests(crdClient *rest.RESTClient) {
|
|||||||
if obj.Spec.Method != httpTrigger.Spec.Method {
|
if obj.Spec.Method != httpTrigger.Spec.Method {
|
||||||
log.Panicf("Bad object from watch: %#v", obj)
|
log.Panicf("Bad object from watch: %#v", obj)
|
||||||
}
|
}
|
||||||
log.Printf("watch event took %v", time.Now().Sub(start))
|
log.Printf("watch event took %v", time.Since(start))
|
||||||
recvd = true
|
recvd = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,7 +408,7 @@ func kubernetesWatchTriggerTests(crdClient *rest.RESTClient) {
|
|||||||
if obj.Spec.Type != kubernetesWatchTrigger.Spec.Type {
|
if obj.Spec.Type != kubernetesWatchTrigger.Spec.Type {
|
||||||
log.Panicf("Bad object from watch: %#v", obj)
|
log.Panicf("Bad object from watch: %#v", obj)
|
||||||
}
|
}
|
||||||
log.Printf("watch event took %v", time.Now().Sub(start))
|
log.Printf("watch event took %v", time.Since(start))
|
||||||
recvd = true
|
recvd = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ func (fetcher *Fetcher) FetchHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
elapsed := time.Now().Sub(startTime)
|
elapsed := time.Since(startTime)
|
||||||
log.Printf("elapsed time in fetch request = %v", elapsed)
|
log.Printf("elapsed time in fetch request = %v", elapsed)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -251,7 +251,7 @@ func (fetcher *Fetcher) UploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
elapsed := time.Now().Sub(startTime)
|
elapsed := time.Since(startTime)
|
||||||
log.Printf("elapsed time in upload request = %v", elapsed)
|
log.Printf("elapsed time in upload request = %v", elapsed)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ func TestExecutor(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicf("failed to get func svc: %v", err)
|
log.Panicf("failed to get func svc: %v", err)
|
||||||
}
|
}
|
||||||
log.Printf("svc for function created at: %v (in %v)", svc, time.Now().Sub(t1))
|
log.Printf("svc for function created at: %v (in %v)", svc, time.Since(t1))
|
||||||
|
|
||||||
// ensure that a pod with the label functionName=f.Metadata.Name exists
|
// ensure that a pod with the label functionName=f.Metadata.Name exists
|
||||||
podCount := countPods(kubeClient, functionNs, map[string]string{"functionName": f.Metadata.Name})
|
podCount := countPods(kubeClient, functionNs, map[string]string{"functionName": f.Metadata.Name})
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ func (fsc *FunctionServiceCache) service() {
|
|||||||
for _, funcSvc := range fscs {
|
for _, funcSvc := range fscs {
|
||||||
fsvc := funcSvc.(*FuncSvc)
|
fsvc := funcSvc.(*FuncSvc)
|
||||||
if fsvc.Environment.Metadata.UID == req.env.UID &&
|
if fsvc.Environment.Metadata.UID == req.env.UID &&
|
||||||
time.Now().Sub(fsvc.Atime) > req.age {
|
time.Since(fsvc.Atime) > req.age {
|
||||||
funcObjects = append(funcObjects, fsvc)
|
funcObjects = append(funcObjects, fsvc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -196,7 +196,7 @@ func (fsc *FunctionServiceCache) _touchByAddress(address string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fsc *FunctionServiceCache) DeleteOld(fsvc *FuncSvc, minAge time.Duration) (bool, error) {
|
func (fsc *FunctionServiceCache) DeleteOld(fsvc *FuncSvc, minAge time.Duration) (bool, error) {
|
||||||
if time.Now().Sub(fsvc.Atime) < minAge {
|
if time.Since(fsvc.Atime) < minAge {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ func (gp *GenericPool) _choosePod(newLabels map[string]string) (*apiv1.Pod, erro
|
|||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
for {
|
for {
|
||||||
// Retries took too long, error out.
|
// Retries took too long, error out.
|
||||||
if time.Now().Sub(startTime) > gp.podReadyTimeout {
|
if time.Since(startTime) > gp.podReadyTimeout {
|
||||||
log.Printf("[%v] Erroring out, timed out", newLabels)
|
log.Printf("[%v] Erroring out, timed out", newLabels)
|
||||||
return nil, errors.New("timeout: waited too long to get a ready pod")
|
return nil, errors.New("timeout: waited too long to get a ready pod")
|
||||||
}
|
}
|
||||||
@@ -260,7 +260,7 @@ func (gp *GenericPool) _choosePod(newLabels map[string]string) (*apiv1.Pod, erro
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Printf("Chosen pod: %v (in %v)", chosenPod.ObjectMeta.Name, time.Now().Sub(startTime))
|
log.Printf("Chosen pod: %v (in %v)", chosenPod.ObjectMeta.Name, time.Since(startTime))
|
||||||
return chosenPod, nil
|
return chosenPod, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -510,7 +510,7 @@ func (gp *GenericPool) waitForReadyPod() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if time.Now().Sub(startTime) > gp.podReadyTimeout {
|
if time.Since(startTime) > gp.podReadyTimeout {
|
||||||
return errors.New("timeout: waited too long for pod to be ready")
|
return errors.New("timeout: waited too long for pod to be ready")
|
||||||
}
|
}
|
||||||
time.Sleep(1000 * time.Millisecond)
|
time.Sleep(1000 * time.Millisecond)
|
||||||
|
|||||||
@@ -163,15 +163,15 @@ Options:
|
|||||||
runExecutor(port, fissionNs, functionNs)
|
runExecutor(port, fissionNs, functionNs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if arguments["--kubewatcher"] == true {
|
if arguments["--kubewatcher"] {
|
||||||
runKubeWatcher(routerUrl)
|
runKubeWatcher(routerUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
if arguments["--timer"] == true {
|
if arguments["--timer"] {
|
||||||
runTimer(routerUrl)
|
runTimer(routerUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
if arguments["--mqt"] == true {
|
if arguments["--mqt"] {
|
||||||
runMessageQueueMgr(routerUrl)
|
runMessageQueueMgr(routerUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ func (fh *functionHandler) handler(responseWriter http.ResponseWriter, request *
|
|||||||
initalTimeout: 50 * time.Millisecond,
|
initalTimeout: 50 * time.Millisecond,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
delay := time.Now().Sub(reqStartTime)
|
delay := time.Since(reqStartTime)
|
||||||
if delay > 100*time.Millisecond {
|
if delay > 100*time.Millisecond {
|
||||||
log.Printf("Request delay for %v: %v", serviceUrl, delay)
|
log.Printf("Request delay for %v: %v", serviceUrl, delay)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ func TestStorageService(t *testing.T) {
|
|||||||
panicIf(err)
|
panicIf(err)
|
||||||
contents2, err := ioutil.ReadFile(retrievedfile.Name())
|
contents2, err := ioutil.ReadFile(retrievedfile.Name())
|
||||||
panicIf(err)
|
panicIf(err)
|
||||||
if bytes.Compare(contents1, contents2) != 0 {
|
if !bytes.Equal(contents1, contents2) {
|
||||||
log.Panicf("Contents don't match")
|
log.Panicf("Contents don't match")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user