Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Multithreading


  • Please log in to reply
8 replies to this topic

#1 poschi8

poschi8

    Member

  • Members
  • PipPip
  • 15 posts

Posted 16 December 2012 - 12:00 PM

Hello. Does anyone know how many Threads a Netduino Plus 2 can handle at the same Time? greets, poschi8

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 16 December 2012 - 12:20 PM

The most I once did was 50, but it became quite slow. Keep in mind, it's multithreading, but in the way a single-core computer does, it devides cpu time over all threads. I think the amount of threads is virtually unlimited, but performance will become a pain eventually.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 Nicky

Nicky

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts
  • LocationDenmark

Posted 16 December 2012 - 02:14 PM

I have switched to single threaded programming on my Netduino Go, because when theres 4-5 concurrent threads running, one or two of them never gets CPU cycles after a minute of operation. Then if I reboot, it might work for two minutes, next time maybe five, next time maybe not at all. Everything shared is thread safe, minimal writing/reading to SD/ethernet due to buffers. And also... with 4-5 threads, it can take up to almost 14 seconds write 100 bytes to a SD card... the exact same code, when only 1 thread runs, it takes only a few milliseconds to write 1-2 kb. When that said, thats when my uploader should be working constantly, and saving every few second. But compared to single threaded mode, those few threads has an insane impact on performance... Sometimes a it can also take a few seconds, or maybe a minute, before the Netduio changes to a specific thread. They all have the same thread priority, but some threads get skipped when cycling!

ntools
TCP Listener (Beta) · FTP Server (Alpha)
Netduino Plus Go Module · Xml Parser
http://ntools.codeplex.com/


#4 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 16 December 2012 - 02:51 PM

thank you Nicky for that hint, and i wondered why my sd card is so slow. with threads it took me 2.5!! seconds to read 128 bytes. without just 0.6 seconds (all same code, iam just calling all threads now from main loop) when leaving all other threads but the sd card read in main loop, i got 1.5 secs on an empty project its 0.4secs, so not much difference

#5 firestar

firestar

    Member

  • Members
  • PipPip
  • 15 posts

Posted 16 December 2012 - 03:35 PM

thank you Nicky for that hint, and i wondered why my sd card is so slow.
with threads it took me 2.5!! seconds to read 128 bytes. without just 0.6 seconds (all same code, iam just calling all threads now from main loop)
when leaving all other threads but the sd card read in main loop, i got 1.5 secs

on an empty project its 0.4secs, so not much difference


Are you sure its just the threading? I'm running 4 - 5 threads at the same time, UDP listener, webserver, serial server, main thread and sometimes a background worker to store data, I notice no (big) performance disadvantages on a standard ND+.
You know you can set priorities on your thread? I assume you have something going on in your main thread (the starting one) that keeps the other from executing.

#6 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 16 December 2012 - 03:49 PM

i know what iam doing. ofc i know how to set thread priorites. and for me its as i said, i not just write this down, i tested it before.

#7 Nicky

Nicky

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts
  • LocationDenmark

Posted 16 December 2012 - 03:59 PM

Are you sure its just the threading? I'm running 4 - 5 threads at the same time, UDP listener, webserver, serial server, main thread and sometimes a background worker to store data, I notice no (big) performance disadvantages on a standard ND+.
You know you can set priorities on your thread? I assume you have something going on in your main thread (the starting one) that keeps the other from executing.


Sounds like me and Noom are experiencing the same, so I can tell:

- Main-thread: Idle
- Every second, an event raises, refreshing sensors + screen and saves data (writes 100 bytes of json (automatic parsing)) if enough time has passed.
- When ever theres data to be sent, an uploader worker sends the file with a lightweight http request (1 request line, 3 line header, 100 bytes payload).

That is basicly whats killing my NGo ... singlethreaded, it can refresh, save and send data in less than a second. Multithreaded, it kills it self.

ntools
TCP Listener (Beta) · FTP Server (Alpha)
Netduino Plus Go Module · Xml Parser
http://ntools.codeplex.com/


#8 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 17 December 2012 - 11:44 PM

Hi Nicky, We have some commercial projects which use several threads, with good response times, and run for months on end. So in theory, at least, threading should work well in NETMF :) Most of our multi-threading issues that we've run into over the years are high MCU utilization (i.e. threads which don't give up much time for other threads to execute frequently) and garbage collection (due to thread objects and threads' objects going out of scope). Is there any chance that you have a small sample app (perhaps one thread blinking the white led, one blinking the blue led, one blinking an LED on a digital port) which exhibits this behavior? If we can reproduce it, we can dig into the IL interpreter and coordinate with Microsoft on a fix (or determine why it's behaving as .NET is supposed to behave--there are always the garbage collection issues, etc.) Chris

#9 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 18 December 2012 - 05:33 AM

are high MCU utilization


that could be my problem, i do a lot of bitshifting (need native function for shiffting bits in Byte / Byte[] arrays :P ) and calculating




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.