Priority for threads
MatsGard opened this issue · comments
I think it would be nice to be able to set the priority for threads just like you can do for processes.
It is possible using "thr.priority= integer", like below.
The value of the integer is however different compared to process, so therefore it might be better to use something else than the :nice option.
Regards Mats
def thread_it(options)
# clean up stale connections from previous threads
ActiveRecord::Base.verify_active_connections!()
thr = Thread.new do
# run the long-running code block
yield
end
thr.priority = options[:nice] if options[:nice]
return SpawnId.new(:thread, thr)
end
I'll look into that when I have time... thanks for the suggestion.
Mats, I set the thread priority like this:
thr.priority = -options[:nice] if options[:nice]
I used the negative value of 'nice' since we want nice processes to have lower priority. It's on the edge branch if you want to try it out.