PageRenderTime 24ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/blog/draft/stm-apr2012.rst

https://bitbucket.org/pypy/extradoc/
ReStructuredText | 84 lines | 72 code | 12 blank | 0 comment | 0 complexity | b6585798b4c965e5d81212e88e50a365 MD5 | raw file
  1. STM update (and thanks everybody)
  2. =================================
  3. A short update on the Software Transactional Memory (STM) side. Let me
  4. remind you that the work is to add STM internally into PyPy, with the
  5. goal of letting the user's programs run on multiple cores after a minor
  6. adaptation. (The goal is not to expose STM to the user's program.) I
  7. will soon write some official documentation that explains in more
  8. details exactly what you get. For now you can read the previous blog__
  9. posts__, and you can also find technical details in the `call for
  10. donation`_ itself; or directly look at how I adapted the examples linked
  11. to later in this post.
  12. .. _`call for donation`: http://pypy.org/tmdonate.html
  13. .. __: http://morepypy.blogspot.com/2012/03/call-for-donations-for-software.html
  14. .. __: http://morepypy.blogspot.com/2012/01/transactional-memory-ii.html
  15. I have now reached the point where the basics seem to work. There is no
  16. integration with the JIT so far; moreover the integration with the
  17. Garbage Collection subsystem is not finished right now, but at least it is
  18. "not crashing in my simple tests and not leaking memory too quickly".
  19. (It means that it is never calling ``__del__`` so far, although it
  20. releases memory; and when entering transactional mode or when going to
  21. the next transaction, all live objects become immortal. This should
  22. still let most not-too-long-running programs work.)
  23. If you want to play with it, you can download `this binary`_ (you need to
  24. put it in a place with the paths ``lib-python`` and ``lib_pypy``, for
  25. example inside the main directory from a regular `nightly tarball`_
  26. or from a full checkout).
  27. This version was compiled for Linux x86 32-bit from the `stm-gc`_ branch
  28. on the 25th of April. It runs e.g. the modified version of richards_.
  29. This branch could also be translated for Linux x86-64, but not for
  30. other OSes nor other CPUs for now.
  31. .. _`this binary`: http://wyvern.cs.uni-duesseldorf.de/~arigo/pypy-stm-22fccf3c9b5e.tar.bz2
  32. .. _`nightly tarball`: http://buildbot.pypy.org/nightly/trunk/
  33. .. _`stm-gc`: https://bitbucket.org/pypy/pypy/src/stm-gc
  34. .. _richards: https://bitbucket.org/pypy/pypy/raw/stm-gc/pypy/translator/stm/test/richards.py
  35. The resulting ``pypy-stm`` exposes the same interface as the pure Python
  36. transaction_ module, which is an emulator (running on CPython or any
  37. version of PyPy) which can be used to play around and prepare your
  38. programs. See the comments in there. A difference is that the real
  39. ``pypy-stm`` doesn't support epoll right now, so it cannot be used yet
  40. to play with `a branch of Twisted`_ that was already adapted (thanks
  41. Jean-Paul Calderone); but that's coming soon. For now you can use it to
  42. get multi-core usage on purely computational programs.
  43. I did for example adapt PyPy's own ``translate.py``: see the tweak `in
  44. rpython/rtyper.py`_. Lines 273-281 are all that I needed to add, and
  45. they are mostly a "simplification and parallelization" of the lines
  46. above. There are a few more places in the whole ``translate.py`` that
  47. could be similarly modified, but overall it is just that: a few places.
  48. I did not measure performance, but I checked that it is capable of using
  49. multiple cores in the RTyping step of translation, with --- as expected
  50. --- some still-reasonable number of conflicts, particularly at the
  51. beginning when shared data structures are still being built.
  52. .. _transaction: https://bitbucket.org/pypy/pypy/raw/stm-gc/lib_pypy/transaction.py
  53. .. _`a branch of Twisted`: svn://svn.twistedmatrix.com/svn/Twisted/branches/stm-5526
  54. .. _`in rpython/rtyper.py`: https://bitbucket.org/pypy/pypy/src/stm-gc/pypy/rpython/rtyper.py#cl-249
  55. On a few smaller, more regular examples like richards_, I did measure
  56. the performance. It is not great, even taking into account that it has
  57. no JIT so far. Running pypy-stm with one thread is roughly 5 times
  58. slower than running a regular PyPy with no JIT (it used to be better in
  59. previous versions, but they didn't have any GC; nevertheless, I need to
  60. investigate). However, it does seem to scale. At least, it scales
  61. roughly as expected on my 2-real-cores, 4-hyperthreaded-cores laptop
  62. (i.e. for N between 1 and 4, the N-threaded pypy-stm performs similarly
  63. to N independent pypy-stm's running one thread each).
  64. And finally...
  65. ...a big thank you to everyone who contributed some money to support
  66. this! As you see on the PyPy_ site, we got more than 6700$ so far in
  67. only 5 or 6 weeks. Thanks to that, my contract started last Monday, and
  68. I am now paid a small salary via the `Software Freedom Conservancy`_
  69. (thanks Bradley M. Kuhn for organizational support from the SFC).
  70. Again, thank you everybody!
  71. .. _PyPy: http://pypy.org/
  72. .. _`Software Freedom Conservancy`: http://sfconservancy.org/