librelist archives

« back to archive

calling parser from Goliath gives "stack level too deep"

calling parser from Goliath gives "stack level too deep"

From:
David Jenkins
Date:
2011-11-26 @ 20:32
I have an app that uses Parslet and works fine in "normal" circumstances.
 But the same code, when called called from Goliath.response, gives me
"error: stack level too deep".

Any ideas?

I'll try and whittle down the code to a reasonable repro size in the
meantime.

Thanks

David Jenkins

Re: [ruby.parslet] calling parser from Goliath gives "stack level too deep"

From:
Nigel Thorne
Date:
2011-11-27 @ 11:54
As no-one has responded, I thought I would chip in...

I'm sure you probably know this... but just in-case,

"Stack too deep" literally means you have too many functions calling onto
other function, detected by the virtual machine (or OS) to prevent you from
getting run away recursion.

So.. causes..

Either someone is monkey patching something that Parslet is relying on, so
the code that is executing is different somehow,

OR

You are just unlucky, and were running near the stack limit with your
existing code but didn't know it and running it from within another calling
mechanize has just pushed you over the edge (as it would add it's own calls
to the stack).

Parsing can be a very stack intensive activity depending on the
implementation and the complexity of the document. I believe Parslet will
be creating another call on the stack for each sub-entity it starts
parsing... so if you have expressions that contains expressions that
contain expressions.. etc...
then at some point you'll hit the limit..

Solution?

I'd suggest trying to set your stack depth a little deeper  (
http://dalibornasevic.com/posts/5-ruby-stack-level-too-deep-systemstackerror)
first.. and see if that's the problem. If you still hit it, then you
probably have some run away recursion.. so the code is somehow different in
the Goliath environment. If it starts working, then you just have a deep
stack.

Either you can make this your default stack depth setting, or change your
grammar to reduce the number of rules and hence the stack depth.

These are just my suppositions, so I hope they are of some help.


Cheers
Nigel
---
"No man is an island... except Philip"


On 27 November 2011 07:32, David Jenkins <djenkins.ny@gmail.com> wrote:

> I have an app that uses Parslet and works fine in "normal" circumstances.
>  But the same code, when called called from Goliath.response, gives me
> "error: stack level too deep".
>
> Any ideas?
>
> I'll try and whittle down the code to a reasonable repro size in the
> meantime.
>
> Thanks
>
> David Jenkins
>

Re: calling parser from Goliath gives "stack level too deep"

From:
Kaspar Schiess
Date:
2011-11-28 @ 08:42
Hi,

Thanks for the really competent answer, you did better than I would've, 
Nigel ;)

One thing I would like to add is that I am looking at developing a 
'stackless' parslet; this is mainly for speed reasons but would also 
benefit folks that use fibers. If you guys are interested I could 
outline the plans on the list.

But don't hold your breath just yet...

regards,
kaspar

Re: [ruby.parslet] Re: calling parser from Goliath gives "stack level too deep"

From:
David Jenkins
Date:
2011-11-28 @ 14:10
Well, fwiw, I'm certainly all for it!


On Mon, Nov 28, 2011 at 3:42 AM, Kaspar Schiess <eule@space.ch> wrote:

> Hi,
>
> Thanks for the really competent answer, you did better than I would've,
> Nigel ;)
>
> One thing I would like to add is that I am looking at developing a
> 'stackless' parslet; this is mainly for speed reasons but would also
> benefit folks that use fibers. If you guys are interested I could
> outline the plans on the list.
>
> But don't hold your breath just yet...
>
> regards,
> kaspar
>
>

Re: [ruby.parslet] Re: calling parser from Goliath gives "stack level too deep"

From:
Nigel Thorne
Date:
2011-11-29 @ 02:06
I'd love to hear the plans :)

---
"No man is an island... except Philip" <-- only makes sense in australia


On 29 November 2011 01:10, David Jenkins <djenkins.ny@gmail.com> wrote:

> Well, fwiw, I'm certainly all for it!
>
>
> On Mon, Nov 28, 2011 at 3:42 AM, Kaspar Schiess <eule@space.ch> wrote:
>
>> Hi,
>>
>> Thanks for the really competent answer, you did better than I would've,
>> Nigel ;)
>>
>> One thing I would like to add is that I am looking at developing a
>> 'stackless' parslet; this is mainly for speed reasons but would also
>> benefit folks that use fibers. If you guys are interested I could
>> outline the plans on the list.
>>
>> But don't hold your breath just yet...
>>
>> regards,
>> kaspar
>>
>>
>

Re: calling parser from Goliath gives "stack level too deep"

From:
Kaspar Schiess
Date:
2011-11-29 @ 08:27
> I'd love to hear the plans :)

I've hacked something together that illustrates this:
https://github.com/kschiess/parslet/blob/master/experiments/compile.rb

I'll keep at it and when I have something that works (instead of failing 
in interesting ways), I'll benchmark this against the current version. I 
guess this might buy us some speed and control. Might even make the 
parser less complex.

And the important bit: totally stackless. Since the stack will be on the 
heap...

my 2 cents ;)
kaspar

Re: [ruby.parslet] calling parser from Goliath gives "stack level too deep"

From:
David Jenkins
Date:
2011-11-27 @ 15:47
Thanks for getting back to me, Nigel.  I also posted the problem in the
Goliath google group, and its creator, Ilya Grigorik, posted that ruby
fibers, on which Goliath relies, "have a *much* smaller stack, so this is
not a bug.. you're likely simply  hitting that limit" (his words and
emphasis). So it could be that I was well within "normal" (i.e., non-fiber)
stack limits when not calling my code from Goliath, but with Goliath/fibers
in the equation, I ran out of room.

I've researched the ruby fiber stack a bit, and found this:
http://redmine.ruby-lang.org/issues/3187, so it seems that 1) there are
other folks running up against this limit and 2) changing the system stack
size might not make a difference -- but I'm gonna give it a try, anyway!

Thanks again.


On Sun, Nov 27, 2011 at 6:54 AM, Nigel Thorne <rspec@nigelthorne.com> wrote:

> As no-one has responded, I thought I would chip in...
>
> I'm sure you probably know this... but just in-case,
>
> "Stack too deep" literally means you have too many functions calling onto
> other function, detected by the virtual machine (or OS) to prevent you from
> getting run away recursion.
>
> So.. causes..
>
> Either someone is monkey patching something that Parslet is relying on, so
> the code that is executing is different somehow,
>
> OR
>
> You are just unlucky, and were running near the stack limit with your
> existing code but didn't know it and running it from within another calling
> mechanize has just pushed you over the edge (as it would add it's own calls
> to the stack).
>
> Parsing can be a very stack intensive activity depending on the
> implementation and the complexity of the document. I believe Parslet will
> be creating another call on the stack for each sub-entity it starts
> parsing... so if you have expressions that contains expressions that
> contain expressions.. etc...
> then at some point you'll hit the limit..
>
> Solution?
>
> I'd suggest trying to set your stack depth a little deeper  (
> http://dalibornasevic.com/posts/5-ruby-stack-level-too-deep-systemstackerror)
> first.. and see if that's the problem. If you still hit it, then you
> probably have some run away recursion.. so the code is somehow different in
> the Goliath environment. If it starts working, then you just have a deep
> stack.
>
> Either you can make this your default stack depth setting, or change your
> grammar to reduce the number of rules and hence the stack depth.
>
> These are just my suppositions, so I hope they are of some help.
>
>
> Cheers
> Nigel
> ---
> "No man is an island... except Philip"
>
>
>
> On 27 November 2011 07:32, David Jenkins <djenkins.ny@gmail.com> wrote:
>
>> I have an app that uses Parslet and works fine in "normal" circumstances.
>>  But the same code, when called called from Goliath.response, gives me
>> "error: stack level too deep".
>>
>> Any ideas?
>>
>> I'll try and whittle down the code to a reasonable repro size in the
>> meantime.
>>
>> Thanks
>>
>> David Jenkins
>>
>
>

Re: [ruby.parslet] calling parser from Goliath gives "stack level too deep"

From:
Nigel Thorne
Date:
2011-11-27 @ 21:33
Good to know.

Thanks
---
"No man is an island... except Philip"


On 28 November 2011 02:47, David Jenkins <djenkins.ny@gmail.com> wrote:

> Thanks for getting back to me, Nigel.  I also posted the problem in the
> Goliath google group, and its creator, Ilya Grigorik, posted that ruby
> fibers, on which Goliath relies, "have a *much* smaller stack, so this is
> not a bug.. you're likely simply  hitting that limit" (his words and
> emphasis). So it could be that I was well within "normal" (i.e., non-fiber)
> stack limits when not calling my code from Goliath, but with Goliath/fibers
> in the equation, I ran out of room.
>
> I've researched the ruby fiber stack a bit, and found this:
> http://redmine.ruby-lang.org/issues/3187, so it seems that 1) there are
> other folks running up against this limit and 2) changing the system stack
> size might not make a difference -- but I'm gonna give it a try, anyway!
>
> Thanks again.
>
>
> On Sun, Nov 27, 2011 at 6:54 AM, Nigel Thorne <rspec@nigelthorne.com>wrote:
>
>> As no-one has responded, I thought I would chip in...
>>
>> I'm sure you probably know this... but just in-case,
>>
>> "Stack too deep" literally means you have too many functions calling onto
>> other function, detected by the virtual machine (or OS) to prevent you from
>> getting run away recursion.
>>
>> So.. causes..
>>
>> Either someone is monkey patching something that Parslet is relying on,
>> so the code that is executing is different somehow,
>>
>> OR
>>
>> You are just unlucky, and were running near the stack limit with your
>> existing code but didn't know it and running it from within another calling
>> mechanize has just pushed you over the edge (as it would add it's own calls
>> to the stack).
>>
>> Parsing can be a very stack intensive activity depending on the
>> implementation and the complexity of the document. I believe Parslet will
>> be creating another call on the stack for each sub-entity it starts
>> parsing... so if you have expressions that contains expressions that
>> contain expressions.. etc...
>> then at some point you'll hit the limit..
>>
>> Solution?
>>
>> I'd suggest trying to set your stack depth a little deeper  (
>> http://dalibornasevic.com/posts/5-ruby-stack-level-too-deep-systemstackerror)
>> first.. and see if that's the problem. If you still hit it, then you
>> probably have some run away recursion.. so the code is somehow different in
>> the Goliath environment. If it starts working, then you just have a deep
>> stack.
>>
>> Either you can make this your default stack depth setting, or change your
>> grammar to reduce the number of rules and hence the stack depth.
>>
>> These are just my suppositions, so I hope they are of some help.
>>
>>
>> Cheers
>> Nigel
>> ---
>> "No man is an island... except Philip"
>>
>>
>>
>> On 27 November 2011 07:32, David Jenkins <djenkins.ny@gmail.com> wrote:
>>
>>> I have an app that uses Parslet and works fine in "normal"
>>> circumstances.  But the same code, when called called from
>>> Goliath.response, gives me "error: stack level too deep".
>>>
>>> Any ideas?
>>>
>>> I'll try and whittle down the code to a reasonable repro size in the
>>> meantime.
>>>
>>> Thanks
>>>
>>> David Jenkins
>>>
>>
>>
>