You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directmemory.apache.org by Simone Tripodi <si...@apache.org> on 2012/02/26 01:24:41 UTC

changing the DM behavior at runtime

Hi all guys,

I had a chat with Benoit in another thread and I realized no one of
our class is Thread safe - what do you think of actual behavior that
every component accepts a setter for any member - that could cause
strange behaviors at runtime?

I would analyze wich components can be converted to immutable - IIUC
Benoit agreed with me on having some PointerImpl members as immutable,
i.e. CacheService#setMap( ConcurrentMap<K, Pointer<V>> map ) means
dropping all the already stored data :)

Thoughts?
best,
-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/

Re: changing the DM behavior at runtime

Posted by Simone Tripodi <si...@apache.org>.
Hi Mike,

> I dont see any scenario  of resetting the map after youve set it the once (correct me if you can think of one), surely this is where then maybe set method should be removed and it is passed in at construction, and the field is final? avoiding risk of changing it ever.

that is exactly what I meant, I don't see any scenario as well - but
ATM users are still exposed to the risk of damaging the application.
the ConcurrentMap ATM is totally replaced without any check.

+1

-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/



On Sun, Feb 26, 2012 at 1:51 AM, Michael André Pearce
<mi...@me.com> wrote:

>
> Mike
>
>
> On 26 Feb 2012, at 00:33, Michael André Pearce wrote:
>
>> Also can i suggest locking on the key for put/updates/deletes? avoids someone getting a key whilst it is in transitive state of being updated by another, ive seen before a fancy way of doing this, avoiding a lock for every key, will have to try remember.
>>
>> On 26 Feb 2012, at 00:24, Simone Tripodi wrote:
>>
>>> Hi all guys,
>>>
>>> I had a chat with Benoit in another thread and I realized no one of
>>> our class is Thread safe - what do you think of actual behavior that
>>> every component accepts a setter for any member - that could cause
>>> strange behaviors at runtime?
>>>
>>> I would analyze wich components can be converted to immutable - IIUC
>>> Benoit agreed with me on having some PointerImpl members as immutable,
>>> i.e. CacheService#setMap( ConcurrentMap<K, Pointer<V>> map ) means
>>> dropping all the already stored data :)
>>>
>>> Thoughts?
>>> best,
>>> -Simo
>>>
>>> http://people.apache.org/~simonetripodi/
>>> http://simonetripodi.livejournal.com/
>>> http://twitter.com/simonetripodi
>>> http://www.99soft.org/
>>
>

Re: changing the DM behavior at runtime

Posted by Michael André Pearce <mi...@me.com>.
On a note of CacheService#setMap( ConcurrentMap<K, Pointer<V>> map ), you wouldnt want to drop this, as then you would leave buffered data off the heap with loosing critical information to where it is, thus causing a possible memory leak, unless on doing this, you free'd all the buffers.

I dont see any scenario  of resetting the map after youve set it the once (correct me if you can think of one), surely this is where then maybe set method should be removed and it is passed in at construction, and the field is final? avoiding risk of changing it ever.

Mike


On 26 Feb 2012, at 00:33, Michael André Pearce wrote:

> Also can i suggest locking on the key for put/updates/deletes? avoids someone getting a key whilst it is in transitive state of being updated by another, ive seen before a fancy way of doing this, avoiding a lock for every key, will have to try remember.
> 
> On 26 Feb 2012, at 00:24, Simone Tripodi wrote:
> 
>> Hi all guys,
>> 
>> I had a chat with Benoit in another thread and I realized no one of
>> our class is Thread safe - what do you think of actual behavior that
>> every component accepts a setter for any member - that could cause
>> strange behaviors at runtime?
>> 
>> I would analyze wich components can be converted to immutable - IIUC
>> Benoit agreed with me on having some PointerImpl members as immutable,
>> i.e. CacheService#setMap( ConcurrentMap<K, Pointer<V>> map ) means
>> dropping all the already stored data :)
>> 
>> Thoughts?
>> best,
>> -Simo
>> 
>> http://people.apache.org/~simonetripodi/
>> http://simonetripodi.livejournal.com/
>> http://twitter.com/simonetripodi
>> http://www.99soft.org/
> 


Re: changing the DM behavior at runtime

Posted by Simone Tripodi <si...@apache.org>.
guys, can you please open a separated discussion about concurrency?
the thread has been completely hijacked  :(

best,
-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/



On Sun, Feb 26, 2012 at 8:12 AM, Tommaso Teofili
<to...@gmail.com> wrote:
> I think ConcurrentSkipLisMap [1] would be also a nice option to inspect
> (should be more performant [2]).
> I think I can make some tests next week.
> Tommaso
>
> [1] :
> http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentSkipListMap.html
> [2] :
> http://stackoverflow.com/questions/1811782/when-should-i-use-concurrentskiplistmap
>
>
> 2012/2/26 Michael André Pearce <mi...@me.com>
>
>> Haha i knew i remember seeing something, we can take insperation for key
>> locking from how concurrenthashmap achieves it.
>>
>>
>> http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/ConcurrentHashMap.java
>>
>>
>>
>> On 26 Feb 2012, at 01:14, Michael André Pearce wrote:
>>
>> > Doug Lee and using hashes, though i still cant remember for the life of
>> me where ive seen this atm. (it cant be too distant past if i remember the
>> guys name)
>> >
>> >
>> > On 26 Feb 2012, at 01:06, Simone Tripodi wrote:
>> >
>> >> +1 concurrency is still an open issue in DM
>> >>
>> >> best,
>> >> -Simo
>> >>
>> >> http://people.apache.org/~simonetripodi/
>> >> http://simonetripodi.livejournal.com/
>> >> http://twitter.com/simonetripodi
>> >> http://www.99soft.org/
>> >>
>> >>
>> >>
>> >> On Sun, Feb 26, 2012 at 1:33 AM, Michael André Pearce
>> >> <mi...@me.com> wrote:
>> >>> Also can i suggest locking on the key for put/updates/deletes? avoids
>> someone getting a key whilst it is in transitive state of being updated by
>> another, ive seen before a fancy way of doing this, avoiding a lock for
>> every key, will have to try remember.
>> >>>
>> >>> On 26 Feb 2012, at 00:24, Simone Tripodi wrote:
>> >>>
>> >>>> Hi all guys,
>> >>>>
>> >>>> I had a chat with Benoit in another thread and I realized no one of
>> >>>> our class is Thread safe - what do you think of actual behavior that
>> >>>> every component accepts a setter for any member - that could cause
>> >>>> strange behaviors at runtime?
>> >>>>
>> >>>> I would analyze wich components can be converted to immutable - IIUC
>> >>>> Benoit agreed with me on having some PointerImpl members as immutable,
>> >>>> i.e. CacheService#setMap( ConcurrentMap<K, Pointer<V>> map ) means
>> >>>> dropping all the already stored data :)
>> >>>>
>> >>>> Thoughts?
>> >>>> best,
>> >>>> -Simo
>> >>>>
>> >>>> http://people.apache.org/~simonetripodi/
>> >>>> http://simonetripodi.livejournal.com/
>> >>>> http://twitter.com/simonetripodi
>> >>>> http://www.99soft.org/
>> >>>
>> >
>>
>>

Re: changing the DM behavior at runtime

Posted by Tommaso Teofili <to...@gmail.com>.
I think ConcurrentSkipLisMap [1] would be also a nice option to inspect
(should be more performant [2]).
I think I can make some tests next week.
Tommaso

[1] :
http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentSkipListMap.html
[2] :
http://stackoverflow.com/questions/1811782/when-should-i-use-concurrentskiplistmap


2012/2/26 Michael André Pearce <mi...@me.com>

> Haha i knew i remember seeing something, we can take insperation for key
> locking from how concurrenthashmap achieves it.
>
>
> http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/ConcurrentHashMap.java
>
>
>
> On 26 Feb 2012, at 01:14, Michael André Pearce wrote:
>
> > Doug Lee and using hashes, though i still cant remember for the life of
> me where ive seen this atm. (it cant be too distant past if i remember the
> guys name)
> >
> >
> > On 26 Feb 2012, at 01:06, Simone Tripodi wrote:
> >
> >> +1 concurrency is still an open issue in DM
> >>
> >> best,
> >> -Simo
> >>
> >> http://people.apache.org/~simonetripodi/
> >> http://simonetripodi.livejournal.com/
> >> http://twitter.com/simonetripodi
> >> http://www.99soft.org/
> >>
> >>
> >>
> >> On Sun, Feb 26, 2012 at 1:33 AM, Michael André Pearce
> >> <mi...@me.com> wrote:
> >>> Also can i suggest locking on the key for put/updates/deletes? avoids
> someone getting a key whilst it is in transitive state of being updated by
> another, ive seen before a fancy way of doing this, avoiding a lock for
> every key, will have to try remember.
> >>>
> >>> On 26 Feb 2012, at 00:24, Simone Tripodi wrote:
> >>>
> >>>> Hi all guys,
> >>>>
> >>>> I had a chat with Benoit in another thread and I realized no one of
> >>>> our class is Thread safe - what do you think of actual behavior that
> >>>> every component accepts a setter for any member - that could cause
> >>>> strange behaviors at runtime?
> >>>>
> >>>> I would analyze wich components can be converted to immutable - IIUC
> >>>> Benoit agreed with me on having some PointerImpl members as immutable,
> >>>> i.e. CacheService#setMap( ConcurrentMap<K, Pointer<V>> map ) means
> >>>> dropping all the already stored data :)
> >>>>
> >>>> Thoughts?
> >>>> best,
> >>>> -Simo
> >>>>
> >>>> http://people.apache.org/~simonetripodi/
> >>>> http://simonetripodi.livejournal.com/
> >>>> http://twitter.com/simonetripodi
> >>>> http://www.99soft.org/
> >>>
> >
>
>

Re: changing the DM behavior at runtime

Posted by Michael André Pearce <mi...@me.com>.
contain an array of locks (where lockId = lockarray index) and then use the following bit of black magic to select the lock to return, this allows for locking safely yet, keeping a spread of threads running concurrently. below is a pseudo example of how to get a lock for key, default number of locks is 32 as is same with concurrent hash map.


  public class LockHolder<K> {
  private final Lock[] locks;

  public LockHolder(){
    this(32);
  } 
  public LockHolder(int numberOfLocks){
     if ((numberOfLocks & numberOfLocks - 1) == 0){
     locks = new Lock[numberOfLocks];
	//populate array with locks;
     } else {
        throw new LockHolderExcpetion("number of lucks must be to the power of 2!");
     }
  }
  public Lock getLock(K key)
  {
    int lockId = hash(key) & numberOfLocks -1;
    return this.locks[lockId];
  }

 /**
   * Return hash code for Object key. Since we are using power-of-two
   * tables, it is worth the effort to improve hashcode via
   * the same multiplicative scheme as used in IdentityHashMap.
   */
  protected static int hash(K key) {
    int h = x.hashCode();
    // Multiply by 127 (quickly, via shifts), and mix in some high
    // bits to help guard against bunching of codes that are
    // consecutive or equally spaced.
    return ((h << 7) - h + (h >>> 9) + (h >>> 17));
  }
}



On 26 Feb 2012, at 01:23, Michael André Pearce wrote:

> Haha i knew i remember seeing something, we can take insperation for key locking from how concurrenthashmap achieves it.
> 
> http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/ConcurrentHashMap.java
> 
> 
> 
> On 26 Feb 2012, at 01:14, Michael André Pearce wrote:
> 
>> Doug Lee and using hashes, though i still cant remember for the life of me where ive seen this atm. (it cant be too distant past if i remember the guys name)
>> 
>> 
>> On 26 Feb 2012, at 01:06, Simone Tripodi wrote:
>> 
>>> +1 concurrency is still an open issue in DM
>>> 
>>> best,
>>> -Simo
>>> 
>>> http://people.apache.org/~simonetripodi/
>>> http://simonetripodi.livejournal.com/
>>> http://twitter.com/simonetripodi
>>> http://www.99soft.org/
>>> 
>>> 
>>> 
>>> On Sun, Feb 26, 2012 at 1:33 AM, Michael André Pearce
>>> <mi...@me.com> wrote:
>>>> Also can i suggest locking on the key for put/updates/deletes? avoids someone getting a key whilst it is in transitive state of being updated by another, ive seen before a fancy way of doing this, avoiding a lock for every key, will have to try remember.
>>>> 
>>>> On 26 Feb 2012, at 00:24, Simone Tripodi wrote:
>>>> 
>>>>> Hi all guys,
>>>>> 
>>>>> I had a chat with Benoit in another thread and I realized no one of
>>>>> our class is Thread safe - what do you think of actual behavior that
>>>>> every component accepts a setter for any member - that could cause
>>>>> strange behaviors at runtime?
>>>>> 
>>>>> I would analyze wich components can be converted to immutable - IIUC
>>>>> Benoit agreed with me on having some PointerImpl members as immutable,
>>>>> i.e. CacheService#setMap( ConcurrentMap<K, Pointer<V>> map ) means
>>>>> dropping all the already stored data :)
>>>>> 
>>>>> Thoughts?
>>>>> best,
>>>>> -Simo
>>>>> 
>>>>> http://people.apache.org/~simonetripodi/
>>>>> http://simonetripodi.livejournal.com/
>>>>> http://twitter.com/simonetripodi
>>>>> http://www.99soft.org/
>>>> 
>> 
> 


Re: changing the DM behavior at runtime

Posted by Michael André Pearce <mi...@me.com>.
Haha i knew i remember seeing something, we can take insperation for key locking from how concurrenthashmap achieves it.

http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/ConcurrentHashMap.java



On 26 Feb 2012, at 01:14, Michael André Pearce wrote:

> Doug Lee and using hashes, though i still cant remember for the life of me where ive seen this atm. (it cant be too distant past if i remember the guys name)
> 
> 
> On 26 Feb 2012, at 01:06, Simone Tripodi wrote:
> 
>> +1 concurrency is still an open issue in DM
>> 
>> best,
>> -Simo
>> 
>> http://people.apache.org/~simonetripodi/
>> http://simonetripodi.livejournal.com/
>> http://twitter.com/simonetripodi
>> http://www.99soft.org/
>> 
>> 
>> 
>> On Sun, Feb 26, 2012 at 1:33 AM, Michael André Pearce
>> <mi...@me.com> wrote:
>>> Also can i suggest locking on the key for put/updates/deletes? avoids someone getting a key whilst it is in transitive state of being updated by another, ive seen before a fancy way of doing this, avoiding a lock for every key, will have to try remember.
>>> 
>>> On 26 Feb 2012, at 00:24, Simone Tripodi wrote:
>>> 
>>>> Hi all guys,
>>>> 
>>>> I had a chat with Benoit in another thread and I realized no one of
>>>> our class is Thread safe - what do you think of actual behavior that
>>>> every component accepts a setter for any member - that could cause
>>>> strange behaviors at runtime?
>>>> 
>>>> I would analyze wich components can be converted to immutable - IIUC
>>>> Benoit agreed with me on having some PointerImpl members as immutable,
>>>> i.e. CacheService#setMap( ConcurrentMap<K, Pointer<V>> map ) means
>>>> dropping all the already stored data :)
>>>> 
>>>> Thoughts?
>>>> best,
>>>> -Simo
>>>> 
>>>> http://people.apache.org/~simonetripodi/
>>>> http://simonetripodi.livejournal.com/
>>>> http://twitter.com/simonetripodi
>>>> http://www.99soft.org/
>>> 
> 


Re: changing the DM behavior at runtime

Posted by Michael André Pearce <mi...@me.com>.
Doug Lee and using hashes, though i still cant remember for the life of me where ive seen this atm. (it cant be too distant past if i remember the guys name)


On 26 Feb 2012, at 01:06, Simone Tripodi wrote:

> +1 concurrency is still an open issue in DM
> 
> best,
> -Simo
> 
> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/
> 
> 
> 
> On Sun, Feb 26, 2012 at 1:33 AM, Michael André Pearce
> <mi...@me.com> wrote:
>> Also can i suggest locking on the key for put/updates/deletes? avoids someone getting a key whilst it is in transitive state of being updated by another, ive seen before a fancy way of doing this, avoiding a lock for every key, will have to try remember.
>> 
>> On 26 Feb 2012, at 00:24, Simone Tripodi wrote:
>> 
>>> Hi all guys,
>>> 
>>> I had a chat with Benoit in another thread and I realized no one of
>>> our class is Thread safe - what do you think of actual behavior that
>>> every component accepts a setter for any member - that could cause
>>> strange behaviors at runtime?
>>> 
>>> I would analyze wich components can be converted to immutable - IIUC
>>> Benoit agreed with me on having some PointerImpl members as immutable,
>>> i.e. CacheService#setMap( ConcurrentMap<K, Pointer<V>> map ) means
>>> dropping all the already stored data :)
>>> 
>>> Thoughts?
>>> best,
>>> -Simo
>>> 
>>> http://people.apache.org/~simonetripodi/
>>> http://simonetripodi.livejournal.com/
>>> http://twitter.com/simonetripodi
>>> http://www.99soft.org/
>> 


Re: changing the DM behavior at runtime

Posted by "Raffaele P. Guidi" <ra...@gmail.com>.
Well, the concurrency approach was an erlang-ish "fail fast, fail safely"
which helped to speed up things but also sometimes led to inconsistency and
random errors. Maybe it's time to change.

Ciao,
    R
Il giorno 26/feb/2012 02:06, "Simone Tripodi" <si...@apache.org> ha
scritto:

> +1 concurrency is still an open issue in DM
>
> best,
> -Simo
>
> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/
>
>
>
> On Sun, Feb 26, 2012 at 1:33 AM, Michael André Pearce
> <mi...@me.com> wrote:
> > Also can i suggest locking on the key for put/updates/deletes? avoids
> someone getting a key whilst it is in transitive state of being updated by
> another, ive seen before a fancy way of doing this, avoiding a lock for
> every key, will have to try remember.
> >
> > On 26 Feb 2012, at 00:24, Simone Tripodi wrote:
> >
> >> Hi all guys,
> >>
> >> I had a chat with Benoit in another thread and I realized no one of
> >> our class is Thread safe - what do you think of actual behavior that
> >> every component accepts a setter for any member - that could cause
> >> strange behaviors at runtime?
> >>
> >> I would analyze wich components can be converted to immutable - IIUC
> >> Benoit agreed with me on having some PointerImpl members as immutable,
> >> i.e. CacheService#setMap( ConcurrentMap<K, Pointer<V>> map ) means
> >> dropping all the already stored data :)
> >>
> >> Thoughts?
> >> best,
> >> -Simo
> >>
> >> http://people.apache.org/~simonetripodi/
> >> http://simonetripodi.livejournal.com/
> >> http://twitter.com/simonetripodi
> >> http://www.99soft.org/
> >
>

Re: changing the DM behavior at runtime

Posted by Simone Tripodi <si...@apache.org>.
+1 concurrency is still an open issue in DM

best,
-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/



On Sun, Feb 26, 2012 at 1:33 AM, Michael André Pearce
<mi...@me.com> wrote:
> Also can i suggest locking on the key for put/updates/deletes? avoids someone getting a key whilst it is in transitive state of being updated by another, ive seen before a fancy way of doing this, avoiding a lock for every key, will have to try remember.
>
> On 26 Feb 2012, at 00:24, Simone Tripodi wrote:
>
>> Hi all guys,
>>
>> I had a chat with Benoit in another thread and I realized no one of
>> our class is Thread safe - what do you think of actual behavior that
>> every component accepts a setter for any member - that could cause
>> strange behaviors at runtime?
>>
>> I would analyze wich components can be converted to immutable - IIUC
>> Benoit agreed with me on having some PointerImpl members as immutable,
>> i.e. CacheService#setMap( ConcurrentMap<K, Pointer<V>> map ) means
>> dropping all the already stored data :)
>>
>> Thoughts?
>> best,
>> -Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://simonetripodi.livejournal.com/
>> http://twitter.com/simonetripodi
>> http://www.99soft.org/
>

Re: changing the DM behavior at runtime

Posted by Michael André Pearce <mi...@me.com>.
Also can i suggest locking on the key for put/updates/deletes? avoids someone getting a key whilst it is in transitive state of being updated by another, ive seen before a fancy way of doing this, avoiding a lock for every key, will have to try remember.

On 26 Feb 2012, at 00:24, Simone Tripodi wrote:

> Hi all guys,
> 
> I had a chat with Benoit in another thread and I realized no one of
> our class is Thread safe - what do you think of actual behavior that
> every component accepts a setter for any member - that could cause
> strange behaviors at runtime?
> 
> I would analyze wich components can be converted to immutable - IIUC
> Benoit agreed with me on having some PointerImpl members as immutable,
> i.e. CacheService#setMap( ConcurrentMap<K, Pointer<V>> map ) means
> dropping all the already stored data :)
> 
> Thoughts?
> best,
> -Simo
> 
> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/