csharptest / CSharpTest.Net.Collections

BPlusTree and other collections moved from http://code.google.com/p/csharptest-net
109 stars 48 forks source link

Atomic update #2

Closed VJalili closed 10 years ago

VJalili commented 10 years ago

First of all, I would like to thank you for sharing such an awesome work with us. Although it took me a while, but eventually I succeeded in adapting it with my work.

Based on my work scenario, I have quite a lot of updates. Checking the update functions, it seems to me that "TryUpdate(TKey key, KeyValueUpdate<TKey, TValue> fnUpdate)" is a better solution. However, I'm not sure I know how to run a proper function for KeyValueUpdate.

I would sincerely appreciate if you could share an example with us.

csharptest commented 10 years ago

Correct all atomic operations are done through several methods mostly defined by the IConcurrentDictionary<TKey, TValue> interface.

If you download and open the solution and search for TryUpdate, or any other method, you should find plenty of examples. The only interesting part of TryUpdate, or other methods that take a KeyValueUpdate delegate is that the default value comparer is used to determine if the record has been modified. Thus if you have a BPlusTree<int, int> and the update delegate returns the same number that was provided for (TValue original), then no update will occur. This is mostly a concern for a value type with a class that uses the IComparable or IComparable interfaces and does not perform a full equality expression.

VJalili commented 10 years ago

Dear Mr. Knapp;

First of all I would like to thank you for your very kind supports.

Regarding this matter, I used the examples you provided in test solutions. I found .TryUpdate with update function most interesting, but that raises some issues at deserialization time (after almost <5E+7 add/update operations). I tried other .TryUpdate options, but none worked well for me.

I solved the issue in the most "dirty" way: get the key-value to be updated, update the new in-memory object, delete the key-value from tree, insert the updated one. I can imagine what an unnecessary overhead this cause on BPlusTree; but to be honest other methods did not work very well.

I posted my question on stackoverflow http://stackoverflow.com/questions/26223017/length-prefix-with-dynamic-messages-in-protobuf-net. The issue might be in adaptation with protobuf-net hence my stackoverflow question is mainly focused in this direction.

Performance is a critical aspect of my application, which based on my input size could have huge impact on runtime. Hence I sincerely appreciate if you could help me toward the best performing solution.

Best Regards Vahid Jalili

On Thu, Oct 9, 2014 at 2:14 AM, Roger Knapp notifications@github.com wrote:

Correct all atomic operations are done through several methods mostly defined by the IConcurrentDictionary https://github.com/csharptest/CSharpTest.Net.Collections/blob/master/src/CSharpTest.Net.Collections/Collections/IConcurrentDictionary.cs#L77 interface.

If you download and open the solution and search for TryUpdate, or any other method, you should find plenty of examples. The only interesting part of TryUpdate, or other methods that take a KeyValueUpdate delegate is that the default value comparer is used to determine if the record has been modified. Thus if you have a BPlusTree and the update delegate returns the same number that was provided for (TValue original), then no update will occur. This is mostly a concern for a value type with a class that uses the IComparable or IComparable interfaces and does not perform a full equality expression.

— Reply to this email directly or view it on GitHub https://github.com/csharptest/CSharpTest.Net.Collections/issues/2#issuecomment-58447502 .