You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@yunikorn.apache.org by GitBox <gi...@apache.org> on 2020/03/29 23:52:02 UTC

[GitHub] [incubator-yunikorn-core] wangdatan opened a new pull request #118: YUNIKORN-42 (Work in progress changes for recorder)

wangdatan opened a new pull request #118: YUNIKORN-42 (Work in progress changes for recorder)
URL: https://github.com/apache/incubator-yunikorn-core/pull/118
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-yunikorn-core] wangdatan commented on issue #118: YUNIKORN-42 (Work in progress changes for recorder)

Posted by GitBox <gi...@apache.org>.
wangdatan commented on issue #118: YUNIKORN-42 (Work in progress changes for recorder)
URL: https://github.com/apache/incubator-yunikorn-core/pull/118#issuecomment-605721637
 
 
   Just added a WIP change for recorder, which includes: 
   
   1) Recorder implementation. 
   How to use it: 
   ```
   diagnostic. GetEventsRecorder(). RecordResourceRequestEvent(...)
   ```
   
   2) Changes in api package 
   
   3) Changes in RMProxy 
   
   Pending: 
   
   - Haven't added any recording message to scheduler yet. 
   - Haven't properly setup golint/IDE plugin, so the format could be wrong.
   
   @wilfred-s , @TaoYang526 , @yangwwei  please add your suggestions. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-yunikorn-core] adamantal commented on a change in pull request #118: YUNIKORN-42 (Work in progress changes for recorder)

Posted by GitBox <gi...@apache.org>.
adamantal commented on a change in pull request #118: YUNIKORN-42 (Work in progress changes for recorder)
URL: https://github.com/apache/incubator-yunikorn-core/pull/118#discussion_r400839676
 
 

 ##########
 File path: pkg/common/timer_test.go
 ##########
 @@ -0,0 +1,43 @@
+package common
+
+import (
+    "gotest.tools/assert"
+    "testing"
+    "time"
+)
+
+func TestRegularTimer(t *testing.T) {
+    timer := NewTimer()
+    before := timer.NanoTimeNow()
+    timer.Sleep(100 * time.Millisecond)
+    after := timer.NanoTimeNow()
+
+    if after-before < 100*time.Millisecond.Nanoseconds() {
+        t.Errorf("Sleep for RegularTimer doesn't work properly")
+    }
+
+    newTime := after + time.Hour.Nanoseconds()
+
+    // This should not take any effect
+    timer.SetNanoTimeNow(newTime)
+    if timer.NanoTimeNow()-after > time.Second.Nanoseconds() {
+        t.Errorf("SetNanoTime for regular timer should not take effect")
+    }
 
 Review comment:
   I think this test case is wrong. If the `regularTimer`'s `SetNanoTimeNow` took effect, the test would pass.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-yunikorn-core] adamantal commented on a change in pull request #118: YUNIKORN-42 (Work in progress changes for recorder)

Posted by GitBox <gi...@apache.org>.
adamantal commented on a change in pull request #118: YUNIKORN-42 (Work in progress changes for recorder)
URL: https://github.com/apache/incubator-yunikorn-core/pull/118#discussion_r400851384
 
 

 ##########
 File path: pkg/diagnostic/diagnostic_events_recorder.go
 ##########
 @@ -0,0 +1,173 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package diagnostic
+
+import (
+    "github.com/apache/incubator-yunikorn-core/pkg/api"
+    "github.com/apache/incubator-yunikorn-core/pkg/common"
+    "sync"
+    "time"
+)
+
+var initOnce sync.Once
+var recorder *DiagEventsRecorder
+
+type Level int
+
+const (
+    Debug Level = iota
+    Info        = iota
+    Warn        = iota
+    Error       = iota
+)
+
+type DiagEventsRecorder struct {
+    eventMap map[string]*api.DiagnosticEvent
+    timer    common.Timer
+
+    // Nano-second interval of record for same key
+    minimumRecordIntervalForSameKeyInNS int64
+    // How long it takes to expire an event (and will be removed from cache)
+    recordExpireIntervalInNS int64
+    // Wait time In NS between cleanup runs
+    waitTimeBetweenCleanupRuns time.Duration
+
+    sync.RWMutex
+}
+
+func emptyOrAlternative(s string) string {
+    if s == "" {
+        return "(_)"
+    }
+    return s
+}
+
+func (de *DiagEventsRecorder) shouldRecord(level Level, uid string) bool {
+    de.RLock()
+    defer de.RUnlock()
+
+    // check level
+    // TODO
+
+    // check timestamp
+    event := de.eventMap[uid]
+    if event == nil {
+        return true
+    }
+    if de.timer.NanoTimeNow()-event.NanoTimestamp < de.minimumRecordIntervalForSameKeyInNS {
+        return false
+    }
+
+    return true
+}
+
+func (de *DiagEventsRecorder) RecordResourceRequestEvent(level Level, requestId string, appId string, queueName string, nodeId string, message string) {
 
 Review comment:
   A technical question: just by looking at the datastructure I assume we only allow one event per request. Is this intended? Isn't it a bit too strict? I can imagine scenarios where for a request we can emit multiple event records.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-yunikorn-core] adamantal commented on a change in pull request #118: YUNIKORN-42 (Work in progress changes for recorder)

Posted by GitBox <gi...@apache.org>.
adamantal commented on a change in pull request #118: YUNIKORN-42 (Work in progress changes for recorder)
URL: https://github.com/apache/incubator-yunikorn-core/pull/118#discussion_r400852130
 
 

 ##########
 File path: pkg/diagnostic/diagnostic_events_recorder.go
 ##########
 @@ -0,0 +1,173 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package diagnostic
+
+import (
+    "github.com/apache/incubator-yunikorn-core/pkg/api"
+    "github.com/apache/incubator-yunikorn-core/pkg/common"
+    "sync"
+    "time"
+)
+
+var initOnce sync.Once
+var recorder *DiagEventsRecorder
+
+type Level int
+
+const (
+    Debug Level = iota
+    Info        = iota
+    Warn        = iota
+    Error       = iota
+)
+
+type DiagEventsRecorder struct {
+    eventMap map[string]*api.DiagnosticEvent
+    timer    common.Timer
+
+    // Nano-second interval of record for same key
+    minimumRecordIntervalForSameKeyInNS int64
+    // How long it takes to expire an event (and will be removed from cache)
+    recordExpireIntervalInNS int64
+    // Wait time In NS between cleanup runs
+    waitTimeBetweenCleanupRuns time.Duration
+
+    sync.RWMutex
+}
+
+func emptyOrAlternative(s string) string {
+    if s == "" {
+        return "(_)"
+    }
+    return s
+}
+
+func (de *DiagEventsRecorder) shouldRecord(level Level, uid string) bool {
+    de.RLock()
+    defer de.RUnlock()
+
+    // check level
+    // TODO
+
+    // check timestamp
+    event := de.eventMap[uid]
+    if event == nil {
+        return true
+    }
+    if de.timer.NanoTimeNow()-event.NanoTimestamp < de.minimumRecordIntervalForSameKeyInNS {
+        return false
+    }
+
+    return true
+}
+
+func (de *DiagEventsRecorder) RecordResourceRequestEvent(level Level, requestId string, appId string, queueName string, nodeId string, message string) {
+    // Use one single layer of uid, instead of multi-layer map.
+    requestPrimaryKey := emptyOrAlternative(requestId) + emptyOrAlternative(appId) + emptyOrAlternative(nodeId)
+
+    if de.shouldRecord(level, requestPrimaryKey) {
+        de.recordResourceRequestEventInternal(requestPrimaryKey, level, requestId, appId, queueName, nodeId, message, de.timer.NanoTimeNow())
+    }
+}
+
+func (de *DiagEventsRecorder) recordResourceRequestEventInternal(requestPrimaryKey string, level Level, requestId string, appId string, queueName string, nodeId string,
+    message string,
+    nanoTs int64) {
+    ev := &api.DiagnosticEvent{
+        RequestId:     requestId,
+        AppId:         appId,
+        QueueName:     queueName,
+        NodeId:        nodeId,
+        Message:       message,
+        NanoTimestamp: nanoTs,
+    }
+
+    de.Lock()
+    defer de.Unlock()
+    de.eventMap[requestPrimaryKey] = ev
+}
+
+// It should be invoked by a period-executed goroutine and cleanup too old events
+func (de *DiagEventsRecorder) start() {
+    // Run cleanup goroutine
+    go func() {
+        for {
+            de.cleanupOldEvents()
+            de.timer.Sleep(de.waitTimeBetweenCleanupRuns)
+        }
+    }()
+}
+
+func (de *DiagEventsRecorder) cleanupOldEvents() {
+    de.Lock()
+    defer de.Unlock()
+
+    if len(de.eventMap) == 0 {
+        return
+    }
+
+    for k, v := range de.eventMap {
+        if de.timer.NanoTimeNow()-v.NanoTimestamp > de.recordExpireIntervalInNS {
+            delete(de.eventMap, k)
+        }
+    }
+}
+
+func (de *DiagEventsRecorder) FlushEvents() []*api.DiagnosticEvent {
+    de.Lock()
+    defer de.Unlock()
+
+    if len(de.eventMap) == 0 {
+        return nil
+    }
+
+    ret := make([]*api.DiagnosticEvent, len(de.eventMap))
+    idx := 0
+    for _, v := range de.eventMap {
+        ret[idx] = v
+        idx ++
+    }
 
 Review comment:
   ```suggestion
       for idx, v := range de.eventMap {
           ret[idx] = v
       }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-yunikorn-core] adamantal commented on a change in pull request #118: YUNIKORN-42 (Work in progress changes for recorder)

Posted by GitBox <gi...@apache.org>.
adamantal commented on a change in pull request #118: YUNIKORN-42 (Work in progress changes for recorder)
URL: https://github.com/apache/incubator-yunikorn-core/pull/118#discussion_r400845513
 
 

 ##########
 File path: pkg/diagnostic/diagnostic_events_recorder.go
 ##########
 @@ -0,0 +1,173 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package diagnostic
+
+import (
+    "github.com/apache/incubator-yunikorn-core/pkg/api"
+    "github.com/apache/incubator-yunikorn-core/pkg/common"
+    "sync"
+    "time"
+)
+
+var initOnce sync.Once
+var recorder *DiagEventsRecorder
+
+type Level int
+
+const (
+    Debug Level = iota
+    Info        = iota
+    Warn        = iota
+    Error       = iota
+)
+
+type DiagEventsRecorder struct {
+    eventMap map[string]*api.DiagnosticEvent
+    timer    common.Timer
+
+    // Nano-second interval of record for same key
+    minimumRecordIntervalForSameKeyInNS int64
 
 Review comment:
   We can store that in `time.Time`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services