-->
Page 1 of 1

Questions for Sprite_tm

PostPosted: Sun May 15, 2016 12:04 pm
by jhinkle
First - thanks for the RTOS implementation.

I'm new to the ESP8266 but not new to embedded.

I'm using the ESP as a wireless slave micro communicating with a master (ARM).

I never need a Web Server until now -- spent several days trying to make one myself but was unhappy with my implementation.

I searched for Web Server code examples but found everything was based on the no-os SDK and I wanted RTOS.

I then found yours -- thanks again.

By reading many of the posts in this forum -- your web server started out as a no-os implementation and then you converted it to RTOS.

My questions are all related to your RTOS implementation.

Q1: When you create the web server's task you ask for a fairly large stack. In looking over your code, you make some large local arrays which I suspect leads to the large stack. Was there a reason you stayed with local array vs acquiring heap memory?

Q2: Do you see a downside to not using local and acquiring all the large arrays from the heap?

I'm use to monitoring used stack space during development to properly set the stack size for release ... but it appears that can't be done too easy in the ESP.

Q3: Does the ESP network stack hold incoming messages waiting for an active socket receive to be issued or are they discarded if no active receive is in place?

Q4: If the answer to Q3 is they are discarded, then do you see a benefit to creating a separate task for each connection thereby allowing multiple receives to be active at one time?

Q4: Do you know if the ESP's FreeRtos implementation for multiple tasks of the same priority is self-yielding or are they time-sliced? If time-sliced - is it 10msec?

Thanks in advance for your reply.

Re: Questions for Sprite_tm

PostPosted: Mon May 16, 2016 10:31 am
by Sprite_tm
Let me see what I can answer off the top of my head - kinda busy to look at stuff in-depth:
jhinkle wrote:Q1: When you create the web server's task you ask for a fairly large stack. In looking over your code, you make some large local arrays which I suspect leads to the large stack. Was there a reason you stayed with local array vs acquiring heap memory?

Mostly a remainder from non-os days, where you basically have the entire unused bit of heap as a stack, so you can freely allocate huge-ass things there; it's quick and convenient. FreeRTOS kinda threw a wrench in those works :) It's gotten better, though; I think the stacks defined in the example are too big.

Q2: Do you see a downside to not using local and acquiring all the large arrays from the heap?

Speed. For small bits of memory, I'd say it's not worth it. Also the can't-be-arsed-to-rewrite-it-cus-it-works-now factor.

I'm use to monitoring used stack space during development to properly set the stack size for release ... but it appears that can't be done too easy in the ESP.

Mmm, you can theoretically fill the stack space with a known value, run the program, then see how much of that known value filled space is left.

Q3: Does the ESP network stack hold incoming messages waiting for an active socket receive to be issued or are they discarded if no active receive is in place?

Afaik the underlying mechanism are FreeRTOS queues. They'll buffer some data but will probably discard incoming packets if they're not serviced quickly enough.

Q4: If the answer to Q3 is they are discarded, then do you see a benefit to creating a separate task for each connection thereby allowing multiple receives to be active at one time?

No. The webserver isn't supposed to spend lots of time servicing a request anyway - if you're doing heavy processing in a cgi body, imo you're doing it wrong.

Q4: Do you know if the ESP's FreeRtos implementation for multiple tasks of the same priority is self-yielding or are they time-sliced? If time-sliced - is it 10msec?

Time-sliced round robin, iirc. It's the same as vanilla FreeRTOS. Dunno about the timeslice - iirc it's defined as 1/portRICK_RATE_MS or something.

Re: Questions for Sprite_tm

PostPosted: Mon May 16, 2016 2:03 pm
by jhinkle
Thanks for your reply.

Just to note .. my questions were not intended to ask you to do a rewrite.

I'm considering doing that myself. I was looking to see if you had any insight I did not know about or understand before I made the decision.

Thanks again.

Re: Questions for Sprite_tm

PostPosted: Fri May 20, 2016 3:23 am
by Sprite_tm
jhinkle wrote:Thanks for your reply.

Just to note .. my questions were not intended to ask you to do a rewrite.

I'm considering doing that myself. I was looking to see if you had any insight I did not know about or understand before I made the decision.

Thanks again.


Sure. If you decide to improve the existing project instead, you're always welcome to send patches my way :)