5 ms·
So a Mars Rover is much closer to a browser/backbone/node.js app than I could ever imagine. The basic structure is surprisingly similar to javascript apps these
by ricardobeat 14y ago
So a Mars Rover is much closer to a browser/backbone/node.js app than I could ever imagine. The basic structure is surprisingly similar to javascript apps these days: isolated modules, message passing/event loop, fault tolerance.
- taybin 14y agoIf a function call in a node.js blocks, doesn't the app hang while waiting for it? A single process with event callbacks is almost the opposite of what is described here.
- jeremiep 14y agoIn node.js operation that would normally block are performed in a worker thread. For example to read a file you specify a filename and a callback function that will be called when the file is in memory. After the call the execution of the current thread will eventually return to the event loop and other events will be processed until the file is read, such as requests or other callbacks. Once the file is read, a call to the specified callback is queued on the event loop and then executed, resuming your code.
- ricardobeat 14y agoMy comment was specifically about module isolation and message-passing, the design patterns, not language implementation, preemptive vs cooperative or whatever.
- taybin 14y agoI hate to harp on this, since you were downvoted to oblivion, but node.js doesn't have module isolation, as a crash in one function will stop the entire program. And it doesn't have message-passing since it doesn't have multiple processes. There's nothing to pass messages to. The only design pattern it shares is splitting code into subsets, and every language (that matters) has that.
- ricardobeat 14y agoOn node.js: not if you use domains (0.8+) to isolate module exceptions, and you do (should) have multiple processes. On the client, a module throwing an error won't crash the browser either. Finally, events are a form of message-passing.
- jlouis 14y agoNode.js is cooperatively multitasked. VxWorks (and Erlang) are preemptively multitasked. So the basic structure is quite different. If one of your node.js events infinite loops, it is game over. Be it web server or rover. Not so here.
- dllthomas 14y agoThough, with the coding standards forbidding any recursion (direct or indirect) and requiring statically bounded loops, you're not going to have an infinite loop anyway (or, incidentally, write a UTM).
- jeremiep 14y agoNode.js is preemptive, there's only one thread running JavaScript but multiple C++ worker threads doing work on behalf of the script. vibe.d on the other hand is cooperative since it uses coroutines for concurrency.
- malkia 14y agoPlease, explain what do you mean by that - "pre-emptive"? My understanding (coming from C and OS terms) is that pre-emptive means taken over. e.g. if I have a real OS thread it is being temporarily "paused" and the resources (CPU/mem/io) are given to something else. At some point control is restored back. But this is without the knowledge or instructions from the thread itself. So things like priority inversions are hard to battle with pre-emptive multitasking - for example thread A with low priority holding a mutex, while thread B with higher priority waits for it. (and no need for mutexes, if only message passing is to be used).
- jeremiep 14y agoThe node.js worker threads are native threads, which are preemptive on all current platforms. The JavaScript context is running an event loop which most likely must perform locking on its message queue and callbacks to async operations are queued for execution on a future tick of this event loop. All of this seems very preemptive to me. What seems like cooperation in node.js is really just async operations queuing up on the event loop. Since requests are also async events, they get interlocked with callbacks from existing requests. To me, cooperation is when you yield the thread to another coroutine. This saves the state of the call stack, the registers, everything; meaning you don't force your user to keep that state in closures. The user code in a cooperative environment feels sequential and blocking and results are passed by return values, not by calling continuations. Its also friendlier to exceptions since it doesn't lose the entire call stack; with node.js you only get the stack since the beginning of the current event loop's tick.
- malkia 14y agoFrom the JPL coding standard: "Callbacks should be avoided"
- ricardobeat 14y agoThanks for the hate. I know it's worlds apart and there extreme implementation differences, but from a design pattern/code organization perspective it sounds similar, I just thought that was curious. A javascript programmer's view on the Rover's software. (and I feel stupid having to apologize for a harmless comment. way to go HN)