You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@yunikorn.apache.org by "pbacsko (via GitHub)" <gi...@apache.org> on 2023/05/01 15:09:09 UTC

[GitHub] [yunikorn-core] pbacsko commented on a diff in pull request #533: [WIP] [YUNIKORN-1709] Store events separately for event streaming

pbacsko commented on code in PR #533:
URL: https://github.com/apache/yunikorn-core/pull/533#discussion_r1181641754


##########
pkg/events/event_ringbuffer.go:
##########
@@ -0,0 +1,175 @@
+/*
+ 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 events
+
+import (
+	"time"
+
+	"github.com/apache/yunikorn-scheduler-interface/lib/go/si"
+)
+
+const latestUnset int64 = -1 << 63
+
+var now = time.Now
+
+// EventRingBuffer A specialized circular buffer to store event objects.
+//
+// Unlike to regular circular buffers, new entries can be added if the buffer is full. In this case,
+// the oldest entry is overwritten. This is not a classic enqueue operation, so it's named differently.
+//
+// Retrieving the records can be achieved with GetLatestEntriesCount and GetLatestEntries. Since these do not
+// remove the elements, they are not regular dequeue operations either.
+//
+// Entries have a maximum lifespan defined in nanoseconds. Cleanup of expired objects occurs when a call to
+// RemoveExpiredEntries is made.
+//
+// The buffer does not use locking, proper synchronization is delegated to the client.
+type EventRingBuffer struct {
+	events        []*si.EventRecord

Review Comment:
   IMO we need to switch to `[]si.EventRecord` if we want to store a lot of elements. We want to avoid GC interactions, so using a value type here is very much reasonable.
   
   In fact, I'm considering a specia, internal type here instead of `EventRecord` with interned strings. There will be a lot of string duplications in the events (especially IDs). 
   This library looks promising: https://github.com/philpearl/intern



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org