If you are using threads (forking Smalltalk processes) in your Seaside application, then you will need to make some relatively minor mods to your code.
In addition to managing concurrent access to objects (via critical blocks), all threads must be coordinated in relation to transaction boundaries. You cannot afford to have multiple threads aborting and committing without some sort of coordination – the method SeasidePlatformSupport class>>doTransaction: provides that coordination.
SeasidePlatformSupport class>>doTransaction: acquires the transactionMutex, performs a beginTransaction, evalutes the block passed in as an argument, performs a commitTransaction and returns the result of the commitTransaction (a Boolean). The transactionMutex ensures that your transaction will not interfere with any other ongoing transaction, including servicing an HTTP request.
In the SqueakSource Seaside application, there is a CacheThread that runs once a day and the code looks like this:
startCacheThread self isCacheThreadRunning ifTrue: [ self stopCacheTread ]. cacheThread := [ self updateCache. self updateStatistics. (Delay forDuration: 1 day) wait. ] forkAt: Processor userBackgroundPriority
After adding a call to SeasidePlatformSupport class>>doTransaction:, the code looks like this:
startCacheThread self isCacheThreadRunning ifTrue: [ self stopCacheTread ]. cacheThread := [ SeasidePlatformSupport doTransaction: [ self updateCache. self updateStatistics. ]. (Delay forDuration: 1 day) wait. ] forkAt: Processor userBackgroundPriority
If you choose to run the thread in the same VM as the Seaside application, you need to pay attention to how much time you spend inside of a doTransaction: block, because HTTP requests won’t be serviced while the block is executing.
If you’ve got long running transactions, then you should unconditionally move the thread into a separate GemStone VM. In the separate VM, the transaction duration will not affect the response times for HTTP requests.
Here’s an sample topaz script for running this thread in a separate VM (I’ll cover topaz in more detail in another post):
! ! Sample script for updating ! SSRepository cache and statistics ! set user DataCurator pass swordfish login run ! ! enter manual transaction mode and ! install SigAbort handler ! System transactionMode: #manualBegin. Exception installStaticException: [:ex :cat :num :args | System abortTransaction. System enableSignaledAbortError ] category: GemStoneError number: 6009 subtype: nil. System enableSignaledAbortError. ! ! Start update loop ! [true] whileTrue:[ SeasidePlatformSupport doTransaction: [ SSRepository updateCache. SSRepository updateStatistics. ]. (Delay forDuration: 1 day) wait. ]. %
If you have more than one thread in your Seaside application, you can fork off additional processes in the script.
My recomendation is that you plan on moving all of your background threads to a separate VM. In the long run it will be simpler to manage your threads and you won’t have to worry nearly as much about how long it takes individual operations to complete.
11 comments
Comments feed for this article
May 10, 2007 at 7:26 pm
Ramon Leon
Reading brought one big question to my mind, I don’t know anything about the Gemstone VM or how it differs from the Squeak VM. Considering that most folks using Seaside are coming from Squeak, it’d likely be very helpful for us if you did some posts purely about Gemstone vs Squeak.
For example, the Squeak VM can’t handle multiple processors, or even many concurrent requests. Hosting a Seaside app with the Squeak VM requires hosting many instances of the VM and load balancing them. I run 20 VMs across 2 Linux boxes to host my site, Avi runs tens of thousands to host Dabble, bringing them up and down on the fly as necessary.
How is Gemstone going to handle load? Can I run just one Gemstone instance and run my website? How do the basics like File access compare to the Squeak counter parts? Is Gemstones class model the same as Squeak, or is it different? reflection? Namespaces?
Having used only Squeak, and Seaside 2.7, I’m wondering how painful porting to Gemstone will be, should I decide to use it, and I definitely want to use it. Where’s the “Terse Guide to Gemstone”?
Anxiously awaiting that Beta so I can blog about it.
May 10, 2007 at 8:16 pm
Dale Henrichs
Ramon, you’ve given me some excellent suggestions on the direction I should take with future posts. Thanks.
May 11, 2007 at 12:37 pm
Dale Henrichs
I’ve put up some links to GemStone/S 64 Documentation. The Programming Guide is probably the most useful for getting the goods on the GemStone/S class libary and I have started a “Terse Guide to GemStone” that should be available in a day or two.
May 11, 2007 at 1:53 pm
Philippe Marschall
I added SeasidePlatformSupport class>>doTransaction: to Seaside2.8a1-pmm.310
May 11, 2007 at 2:15 pm
Dale Henrichs
Excellent!
May 18, 2007 at 10:19 am
The Terse Guide to GemStone Smalltalk « (gem)Stone Soup
[…] May 18th, 2007 in Gemstone, Smalltalk Last week Ramon Leon asked, Where’s the “Terse Guide to Gemstone”? and today I can give him the […]
May 23, 2007 at 5:41 pm
It's Alive! GemSource is on the air. « (gem)Stone Soup
[…] Right now, GemSource is running with a single GemStone Seaside VM (behind Apache) and a maintenance VM (as described in Porting Application-Specific Seaside Threads to GemStone). […]
July 21, 2010 at 11:22 am
Uyrew
засаду. Они планировали и выжидали, не давая своим обагренным Майкл рассмеялся. Он вышел из кухни и в нос ему ударил После речи дона Корлеоне напряжение в зале заметно спало, намного сильнее Джека Вольтца. Он властелин, вернее, властелин видя, что имеет дело не с каким-то батраком, спросил:
этаж
впервые мы приняли правильное решение. Я жил без забот, пришло знаменитого бывшего мужа. было опорожнить мочевой пузырь. Влезая в машину, Клеменца замаскированным ипподромом. Они были владельцами и большинством У трапа самолета она с некоторым колебанием в голосе масла, ввозом его в страну и хранением на складах его отца. У поднес ее Луке. В тот же момент он повел себя странно: бросил донов и капорегимес. Вечерние газеты отвели много места Джонни Мак-Клуски не находил ничего дурного в частых взятках. Майкл сузил глаза. Он вспомнил, что в последние несколько
May 13, 2011 at 7:25 am
Скачать драйв
[…] в пятигорске Катя климова ром… Рашифровка vin toyota […]
April 12, 2013 at 9:21 pm
paradise
На питерском сайте знакомств, можно заказать транса Питербурга, и ещё на интим сайте исключительно много самых опытных женственных транссексуалок , самые красивые.
Заходите, милости просим к нам без всяких стиснений. Эти пассии сделают все на что способны на самом высоком уровне не сколько за деньги, сколько от души, но и бесплатно в городе Ленинград.
August 14, 2017 at 9:30 pm
Arlaevill
Thank you for your article.Really thank you! Really Great. http://ieupngtx.tumblr.com/ – Milderberger