(2012/07/21 1:23), brixen (Brian Ford) wrote:
I object to this API for setting stack size from Ruby for at least the two following reasons:
- Stack size is an implementation detail and coupling Ruby code to details of a particular implementation is undesirable. Applications may be developed on one implementation and deployed on another. Or details affecting stack size may change between versions of a single implementation.
- Stack size may depend on code not in the application or library (eg a library using Thread.new that calls application code or application code that different versions or implementations of a library).
This setting should be a VM configuration option, not a Ruby method API.
Thank you for your comment.
This issue was started from Feature #3187 "Allow dynamic Fiber stack
size" by mperham (sorry, I had needed to show it).
mperham wants to specify fiber size per fiber because current fiber's
default size is too small to do complicated procedures and no way to
change this size.
Current default fiber's machine stack is small because of two reasons.
- On the 32bit CPU, there are address space restriction and
Only a few thousand of fibers (and threads) can be made
if we allocate 1MB per fibers.
On the Fiber's usage, it is too small in some cases.
- 1MB memory allocation hit performance in little.
(It is very weak reason for Rubyist)
To specify stack size, there are several way.
(1) VM configuration option (as Brian say)
(2) Global config by method (Thread.stack_size=) (as mperham proposed)
(3) Per-thread configuration (as I proposed)
I don't make any objection. It is acceptable.
However, we can't mix "small" and "large" size stack size in same
program. (2) is not perfect because it is not thread-safe.
BTW, the following API is thread-safe. Is it acceptable?
Thread.stack_size(size){
# only in this block, the stack size will be `size'
Thread.new(...){
...
}
}
On the #3187 thread, nagachika proposed more high level specifier
"factor" >https://bugs.ruby-lang.org/issues/3187#note-6>
Fiber.stacksize = 2.0 # => twice the size of default stack size
I think using factor is also acceptable (the method name should be
changed, I guess). But we need to specify.
I also think more rough specifiers such as :small, :medium, :large are
also acceptable.
Fiber.new(size: :small){...}
(for example, at VM configuration with each sizes,
ruby -Xsmall_ss=4KB -Xmedium_ss=128KB -Xlarge_ss=1MB script
)
I don't care low-level or high-level specifier. But I think we need per
thread/fiber specifier.
From developer's perspective: We will increase default stack size for
Fiber (maybe same as Thread) after we introduce this feature. Most
case, larger stack size doesn't make problem (small stack size makes
problems such as mperham's situation).
If application or library needs huge number of Fibers, then this will
feature help.
Thread#name doesn't need a new Thread.new API.
Yes. Thread#name and Thread#name= is enough if specify a name after
creation like:
Thread.new{
Thread.current.name = 'foo' # Thread.name may be also okay
...
}
But I want to specify a name at or before thread creation.
Is it only for me?
--
// SASADA Koichi at atdot dot net