-
Notifications
You must be signed in to change notification settings - Fork 78
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
Prototype adding async get methods to Transaction #967
Comments
I'd like to try and put together some prototypes. |
I have thought about two possible approaches to prototyping this. Both approaches would have the following.
The difference between the two approaches is how the queue is processed. Below are two ways I have been thinking of processing the queue.
|
Hi Keith, Sorry I haven't been able to look at this until today. My first question is, should I be implementing these methods in the SnapShotBase Interface or one of the implementing classes. If the second option, where are the implementing classes? Thanks, |
You could add a default method to SnapShotBase like the following. default CompletableFuture<String> getsAsync(String row, Column column) {
return CompletableFuture.completedFuture(gets(row, column));
} This default method is actually synchronous and blocks. However it provides a default impl for any existing classes that implement the interface and do not provide this new method. You will want to override this in TransactionImpl and provide an impl that is async. The TransactionImpl class is a bit too big, it needs to be refactored. Could possibly put this async get functionality in its own class and have TransactionImpl call it. Maybe something like the following. class AsyncReader {
private queue
private executor
AsyncReader(TransactionImpl tx) {//TODO}
CompletableFuture<String> gets(String row, String column) {//TODO}
void close() {//TODO clean up any resource, like shutdown thread pool}
} |
I'm a bit new to multi-threading so apologies if any of these questions seem basic. I think I understand your idea and am going to start working on it. My question is though why can't we do something like this:
Is the idea that we want to run each get method sequentially but as a whole do them asynchronously from everything else? |
@jkosh44 there are two problems with the Second, each |
Project Loom is something to consider when thinking about adding async methods to Fluo's public API. http://cr.openjdk.java.net/~rpressler/loom/Loom-Proposal.html Not sure what the timeline for Loom is. |
Fetching multiple cells in the Fluo tour describes
get
methods that Fluo has to quickly read multiple cells. While using these method is faster than callingget(row, col)
sequentially, they can be a bit cumbersome. The same thing performance wise could be accomplished with asynchronousget
methods, however I am not convinced this would be less cumbersome. I have been thinking about this idea for a while, but I have yet to convince myself its a fully baked or good idea. I currently am opening this issue to share my thoughts, not to advocate for this feature.Suppose the following methods were added to SnapshotBase. These method would queue up the get operation in the background and return immediately.
Using these methods, this process() method from a Fluo Tour exercise solution could be written as follows.
The method above is only one line shorter and I think having to call
status.get()
vs just usingstatus
is a bit more cumbersome and possibly buggy. For examplestatus.equals("referenced")
above would probably compile (becauseequals
takesObject
), but it would always return false.The adjustCounts method from a Tour exercise solution could be rewritten as follows.
Personally I think this method is slightly easier to understand, given an understanding of CompletableFuture. I found CompletableFuture a bit daunting when I first looked at it, but it grew on me.
I am interested in seeing more use cases for these proposed get async methods. I am also interested in prototyping them in-order to make it possible to experiment with them.
The text was updated successfully, but these errors were encountered: