Creative Reality Pty Ltd

Creating a new reality

  • Increase font size
  • Default font size
  • Decrease font size
Creative Reality Pty Ltd

MVCC STM GC'd Ref History

E-mail Print PDF

When writing an MVCC-based STM I found that managing the value history on the Ref object was an issue. I needed to keep just enough history in memory for all transactions to access the appropriate values. This initially seemed to be an annoying problem to solve as the garbage collector would potentially GC too much of the history list. But after some thought I designed a way to have the garbage collector GC the right amount of the history list.

Other than being an interesting problem solved, I didn't think much more of it until I saw that the Clojure STM implementation manually tries to manage it's Ref history list. If the list is too small the transaction is retried and the list for that Ref is lengthened. A guess is made as to how long lists should be, so it's likely that the lists are a bit longer than required. I didn't look in to the implementation to see exactly what they are doing or how much extra code is required to get it to work, but either way it sounds unnecessarily complicated and inefficient. The GC is the best system to manage these sorts of lists.

The GC-based solution is very simple, doesn't require much code or memory overhead and more importantly, it's just correct. What needs to be in memory is in memory, what isn't needed is removed.

Last Updated on Wednesday, 26 May 2010 00:38 Read more...
 

Creative Reality Pty Ltd provides the following services. Contact us for information on availability.

Consulting

December 2010: Field trials of animal management system v1.2

Creative Reality provides consulting services for a wide range of computer, embedded and Internet technologies.

Our background is in reliable efficient multi-threaded real-time embedded systems; from the software running in fighter aircraft computers to multi-media fiber-optic digital switches and telecommunications equipment. A lot of this work was done in C++/C.

More recently we have been working on Internet-based solutions; including participation on one of the international web standards committees. A lot of recent work has been done on the Java platform using Scala, JavaFX, Groovy and Java.

Creative Reality generally works on R&D projects and has been involved in more mathematical areas like image processing, weapon trajectory calculations, signal processing and combinatorial optimizations.

Currently we are developing a fast combinatorial optimization solution for useful scheduling and an animal management system suitable for Australian conditions.

See the technologies page for more details.


Tutoring

December 2010: Currently available.

Creative Reality provides tutoring services for high school maths, physics and computer related studies.

 

Language Teaching    中英文家教

December 2010: Mostly full, book soon if you are interested.

Creative Reality provides teaching services for Chinese/Mandarin and English (ESL).

更多信息,请点击




Recent Articles

 

Samsung Galaxy Note N7000

E-mail Print PDF

This is a review of the Samsung Galaxy Note N7000 after owning it for a few months.

I'm assuming you've read a number of reviews and have seen some video of the Note. This review is incremental to the general reviews of the Note that already exist.

The following is a quick summary of my view after using the Note:

  • The device is not too large; it could be larger.

  • It's a phone, not a tablet.

  • The hardware is top-of-the-line.

  • The screen is amazing.

  • Every smartphone should have a stylus attached to it.

Now for some more detail...

Last Updated on Sunday, 05 February 2012 13:09 Read more...
 

JavaFX Issues

E-mail Print PDF

JavaFX will probably have a good future but at the moment you have to be very careful when using it. Having worked on a project in JavaFX we have seen a number of issues, one of which is a show-stopper. These comments are for JavaFX 1.2.3. We hope the new release will work better.

Suggestions

When writing JavaFX, treat it as alpha quality. In particular, do small changes/additions to your code and compile regularly to make sure it works and doesn't crash.

Last Updated on Tuesday, 18 May 2010 16:16 Read more...
 

Super-fast GC STM Value History

E-mail Print PDF

Such a simple and efficient approach. Just use a history list of WeakReference to previous values. Remember, the head of the list is a strong-reference, so the current value will always be in memory. We are only talking about the history.

You need to make sure that you retry any transaction when you can't find enough history, but you have to do this in most other solutions anyway.

Between garbage collection (GC) cycles, your history list will grow vey long until something triggers another GC. So you will have lots of history in memory and should not expect any transaction that started after the GC to have a problem getting the correct snapshot value from history. Then at around the time of GC, some transactions may have to retry, but only if they need history values and not the latest value.

This is really nice on the GC as it can just forget all the history (that isn't being used by a transaction that has a strong-reference to the value) and you end up with lots of free memory again. Compare this to holding a buffer-per-Ref of old values, the GC has to look through all those buffers and then copy the values etc... before it can complete. More work for the GC to end up with less free memory.

If you know you have a thread that runs long-running transactions, then you can do a System.gc() to try to force a GC so your long-running transaction will have a good chance of completing before the next GC runs.

Interestingly, if you have to retry a transaction because you could not find enough history, then you know a GC has occurred after you started the transaction, so if you retry immediately without waiting, you are likely to have started just after a GC anyway. Nice... So maybe forcing a System.gc() isn't much of an advantage after all.

For some reason it has taken a long time for me to warm to this idea. Not having strong references to history values just seems wrong. But the more I think about it and the improvement in STM performance I see, the happier I am. Such a simple idea, almost no code and letting the GC do all the work.

The issue is whether future GC implementations will play nicely with this idea or whether they are likely to throw out history data more often. You may have to choose a particular GC implementation or set some options to improve performance.

Interestingly, you could still use this approach with existing buffer-per-Ref type ideas. You just add WeakReference pointing to the previous value - like we described above - then you use your existing buffer approach as normal. When you get to the end of the buffer and you haven't found the value, you start following the WeakReference pointers. It might be simpler to just follow the WeakReference pointers from the start - and maintaining the buffer when new values are added to keep your strong references to the history values. The result is you get another chance at getting more history just by adding a WeakReference to each of your value elements.

Ideally I'd like to do a hybrid solution. You just use the basic WeakReference history list for all your transactions. But if you get a transaction that has retried n times due to lack of history, you dynamically switch to a different approach for a while. Maybe something as simple as blocking other transactions until this troublesome transaction completes. But more probably, a buffer-based approach - probably the global STM buffer approach described in my previous post - or set up large per-Ref buffers. Then some time after that transaction has completed, you can switch back to the faster approach.

The blocking other transaction approach will work fine since it will only want to read the Ref.head and GC will not be an issue as no other transaction will be running. It also means that a transaction will never fail due issues like never being able to commit successfully or not being able to get enough Ref history. It would mean that the Ref's history management code will remain very simple and it will ensure that a transaction can read/write as many Refs as it wants because the fallback for this approach is to grant exclusive access to the transaction. It will mean a period of time where other transactions have to stop, but it is not likely you will get this type of transaction often I guess. If you do then you will have other performance issues with your system anyway.

OK, a 3 stage approach. The pure WeakReference approach. Then if it keeps failing, global buffer approach so we can still have other transactions running. Then if the transaction keeps on failing, just give it exclusive access so it can complete. Then back to the pure WeakReference approach again.

Last Updated on Sunday, 05 February 2012 14:10
 
  • «
  •  Start 
  •  Prev 
  •  1 
  •  2 
  •  3 
  •  Next 
  •  End 
  • »


Page 1 of 3