-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Buffer append output results + fix extra incorrect results #1283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7020f0c
Buffer append output results + fix extra incorrect results
82e9c4a
Fix comment
5057bb3
Incorporate feedback
27790e4
Avoid infinite loop in tests
1bdd669
fix javadoc comment
1c893c0
Add licensing
3984ef8
fix tests when ran with other tests
dd24816
Add license in test file
599281f
fix unit tests that run after
72c316d
Scheduler service to replace while loop in AppendOutputRunner
2eae38e
Make AppendOutputRunner non-static
d168614
Remove un-necessary class CheckAppendOutputRunner
4b68c86
fix checkstyle
7852368
nit
17f0524
Use diamond operator
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/AppendOutputBuffer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * 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 org.apache.zeppelin.interpreter.remote; | ||
|
|
||
| /** | ||
| * This element stores the buffered | ||
| * append-data of paragraph's output. | ||
| */ | ||
| public class AppendOutputBuffer { | ||
|
|
||
| private String noteId; | ||
| private String paragraphId; | ||
| private String data; | ||
|
|
||
| public AppendOutputBuffer(String noteId, String paragraphId, String data) { | ||
| this.noteId = noteId; | ||
| this.paragraphId = paragraphId; | ||
| this.data = data; | ||
| } | ||
|
|
||
| public String getNoteId() { | ||
| return noteId; | ||
| } | ||
|
|
||
| public String getParagraphId() { | ||
| return paragraphId; | ||
| } | ||
|
|
||
| public String getData() { | ||
| return data; | ||
| } | ||
|
|
||
| } |
118 changes: 118 additions & 0 deletions
118
...-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/AppendOutputRunner.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| /* | ||
| * 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 org.apache.zeppelin.interpreter.remote; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.LinkedList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.BlockingQueue; | ||
| import java.util.concurrent.LinkedBlockingQueue; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * This thread sends paragraph's append-data | ||
| * periodically, rather than continously, with | ||
| * a period of BUFFER_TIME_MS. It handles append-data | ||
| * for all paragraphs across all notebooks. | ||
| */ | ||
| public class AppendOutputRunner implements Runnable { | ||
|
|
||
| private static final Logger logger = | ||
| LoggerFactory.getLogger(AppendOutputRunner.class); | ||
| public static final Long BUFFER_TIME_MS = new Long(100); | ||
| private static final Long SAFE_PROCESSING_TIME = new Long(10); | ||
| private static final Long SAFE_PROCESSING_STRING_SIZE = new Long(100000); | ||
|
|
||
| private final BlockingQueue<AppendOutputBuffer> queue = new LinkedBlockingQueue<>(); | ||
| private final RemoteInterpreterProcessListener listener; | ||
|
|
||
| public AppendOutputRunner(RemoteInterpreterProcessListener listener) { | ||
| this.listener = listener; | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
|
|
||
| Map<String, Map<String, StringBuilder> > noteMap = new HashMap<>(); | ||
| List<AppendOutputBuffer> list = new LinkedList<>(); | ||
|
|
||
| /* "drainTo" method does not wait for any element | ||
| * to be present in the queue, and thus this loop would | ||
| * continuosly run (with period of BUFFER_TIME_MS). "take()" method | ||
| * waits for the queue to become non-empty and then removes | ||
| * one element from it. Rest elements from queue (if present) are | ||
| * removed using "drainTo" method. Thus we save on some un-necessary | ||
| * cpu-cycles. | ||
| */ | ||
| try { | ||
| list.add(queue.take()); | ||
| } catch (InterruptedException e) { | ||
| logger.error("Wait for OutputBuffer queue interrupted: " + e.getMessage()); | ||
| } | ||
| Long processingStartTime = System.currentTimeMillis(); | ||
| queue.drainTo(list); | ||
|
|
||
| for (AppendOutputBuffer buffer: list) { | ||
| String noteId = buffer.getNoteId(); | ||
| String paragraphId = buffer.getParagraphId(); | ||
|
|
||
| Map<String, StringBuilder> paragraphMap = (noteMap.containsKey(noteId)) ? | ||
| noteMap.get(noteId) : new HashMap<String, StringBuilder>(); | ||
| StringBuilder builder = paragraphMap.containsKey(paragraphId) ? | ||
| paragraphMap.get(paragraphId) : new StringBuilder(); | ||
|
|
||
| builder.append(buffer.getData()); | ||
| paragraphMap.put(paragraphId, builder); | ||
| noteMap.put(noteId, paragraphMap); | ||
| } | ||
| Long processingTime = System.currentTimeMillis() - processingStartTime; | ||
|
|
||
| if (processingTime > SAFE_PROCESSING_TIME) { | ||
| logger.warn("Processing time for buffered append-output is high: " + | ||
| processingTime + " milliseconds."); | ||
| } else { | ||
| logger.debug("Processing time for append-output took " | ||
| + processingTime + " milliseconds"); | ||
| } | ||
|
|
||
| Long sizeProcessed = new Long(0); | ||
| for (String noteId: noteMap.keySet()) { | ||
| for (String paragraphId: noteMap.get(noteId).keySet()) { | ||
| String data = noteMap.get(noteId).get(paragraphId).toString(); | ||
| sizeProcessed += data.length(); | ||
| listener.onOutputAppend(noteId, paragraphId, data); | ||
| } | ||
| } | ||
|
|
||
| if (sizeProcessed > SAFE_PROCESSING_STRING_SIZE) { | ||
| logger.warn("Processing size for buffered append-output is high: " + | ||
| sizeProcessed + " characters."); | ||
| } else { | ||
| logger.debug("Processing size for append-output is " + | ||
| sizeProcessed + " characters"); | ||
| } | ||
| } | ||
|
|
||
| public void appendBuffer(String noteId, String paragraphId, String outputToAppend) { | ||
| queue.offer(new AppendOutputBuffer(noteId, paragraphId, outputToAppend)); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not thread-safe. You should use
synchronizedor something else