Re-use a Stream?

18 views
Skip to first unread message

dave mobley

unread,
Sep 6, 2019, 9:54:19 PM9/6/19
to JSDB
So I'm speculating here, and not quite sure how long Streams actually take to create and to execute,  but wondering if it is possible to take an existing Stream and re-use it (for exec):

Something like this:

// get the Stream //
stream
= new Stream("exec://ls -al");


// read the results //
writeln
(stream.readText())


// reuse the stream?? //
stream
.writeln("exec://ls -A");


// read the results again //
writeln
(stream.readText())

I tried this, and doesn't work.  Is there a way to use a stream so I don't have to spin a new one up each time (maybe to save resources, or time required to spin it up?)

Shanti Rao

unread,
Sep 6, 2019, 11:28:36 PM9/6/19
to js...@googlegroups.com
They take a few hundred lines of C code to create. Not worth reusing.

Shanti
--
You received this message because you are subscribed to the Google Groups "JSDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsdb+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsdb/3aad9967-2172-48e2-99ab-05b6d4beafbd%40googlegroups.com.

dave mobley

unread,
Sep 7, 2019, 7:50:58 AM9/7/19
to JSDB
I just didn't know if spooling up a new Stream was costing performance for my program.  I'll do some tests today.  I think it is actually load(file) that is taking all the time on my EV3.  I'm going to look at combining all my JS into a single monolithic file and just load one at the start and see if that runs faster.


On Friday, September 6, 2019 at 11:28:36 PM UTC-4, Shanti Rao wrote:
They take a few hundred lines of C code to create. Not worth reusing.

Shanti

On 09/06/2019 06:54 PM, dave mobley wrote:
So I'm speculating here, and not quite sure how long Streams actually take to create and to execute,  but wondering if it is possible to take an existing Stream and re-use it (for exec):

Something like this:

// get the Stream //
stream
= new Stream("exec://ls -al");


// read the results //
writeln
(stream.readText())


// reuse the stream?? //
stream
.writeln("exec://ls -A");


// read the results again //
writeln
(stream.readText())

I tried this, and doesn't work.  Is there a way to use a stream so I don't have to spin a new one up each time (maybe to save resources, or time required to spin it up?)

--
You received this message because you are subscribed to the Google Groups "JSDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to js...@googlegroups.com.

dave mobley

unread,
Sep 7, 2019, 9:50:02 AM9/7/19
to JSDB
After testing, I've found that Stream seems very fast and load seems very slow.  Probably just due to the fact the IO on a lightweight device like an ARM5 is slow in general.  I'm thinking of trying the .zip approach to packaging and see how that performs on a small linux device, since it only has to read 1 file.

Shanti Rao

unread,
Sep 7, 2019, 10:40:06 AM9/7/19
to js...@googlegroups.com
It's an interpreter, so load() has to parse and compile source code. You might try concatenating all the libraries into a single js file.

shanti
To unsubscribe from this group and stop receiving emails from it, send an email to jsdb+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsdb/e2ca354e-c085-4f00-8615-df64cb8b1bd4%40googlegroups.com.

Anderson Wiese

unread,
Sep 8, 2019, 1:19:44 PM9/8/19
to js...@googlegroups.com
Dave,
Pardon me for offering advice you didn’t ask for and probably don’t need. 
I do a lot of similar work running javascript as a controller on ARMv5. I find that “exec://“, is comparatively expensive on a tiny single core, and any process that I need to fork regularly I am better off creating a continuous process that will pipe its output to my JS process when needed. 

Do you need to load() javascript files on a regular basis? or is it just at startup that you are concerned about load times? Either way I find that it loads remarkably faster if you use grunt or its ilk to concatenate and minify into a single small file. 

I’m really glad to see you using JSDB. I miss it, and SpiderMonkey too. A huge value to JSDB that I miss often—you can hook up GDB, step through it, and if you’re paying attention you can actually tell what’s going on. Don’t bother trying that with v8.


Anderson



dave mobley

unread,
Sep 8, 2019, 1:38:44 PM9/8/19
to JSDB
So I'm using JSDB on the EV3 (which is an ARM5 running Debian Stretch).

I've been modelling a "new" Javascript API based on the existing Java API (since it is fairly easy to match the OOP from Java->Javascript).  Java has a tendency to push everything out into single files for classes.  Because of this, my new API is also in many classes.  I did a test where I actually concatenated everything into a single file, and it runs blazingly fast (in people-time).  Stream, even on the ARMv5, calling regular system functions (cat, ls, etc..) is very fast, but loading files (with "load") is very slow.  I suspect this is a hardware issue due to the micro-SD used in the EV3.  It probably has a similar internal architecture for storage like that of a Raspberry Pi, making any IO to the disk costly.  I even bet, if there was a way I could make the original Python library a single monolithic file, it'd probably run very fast too (something worth looking into).

For the API, to answer your question, all the load()'s are happening at startup and are very costly getting things going.

The only downside I've had with JSDB is the fact that it is still on ES5 (with a few small gaps, like missing some of Object).  I'd love to see a newer version that could run ES6, and maybe even the proposed ES7 that'll come in 2020.   Eclipse hooks for debugging would also be a really nice addition, but alas, all of that takes lots of time from experienced people, and my knack is at transcoding APIs, not writing interpreters.  So for now, I'll continue using ES5 on JSDB on EV3Dev for Lego and hopefully our team will continue doing well when the compete .  I'm just trying to get them onto a platform that is both competitive and non block-programming (like the mindstorms environment).

--
You received this message because you are subscribed to the Google Groups "JSDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to js...@googlegroups.com.

Anderson Wiese

unread,
Sep 8, 2019, 2:36:21 PM9/8/19
to js...@googlegroups.com
In the unlikely event I ever get a chance to play with it, are the ARM5 build sources for JSDB available? 

You might try transpiling ES6 into ES5 to run on SpiderMonkey. Lots of browser code is still transpiled. I can attest that works well on Node 0.10, and that I am able to run many node modules written in ES6 on Node 0.10. I found a simple Grunt howto that worked off the shelf for me. 

It was a long time ago, but I thought we had an interactive debugger for JSDB back in the day. If you do a little archive diving, you might find a way to connect firebug to JSDB. I’m sorry that my memory isn’t better and my archives are not well organized. 


To unsubscribe from this group and stop receiving emails from it, send an email to jsdb+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsdb/19144cb6-b31b-41ac-aa21-0b8386323d11%40googlegroups.com.

scprotz

unread,
Sep 8, 2019, 3:00:15 PM9/8/19
to js...@googlegroups.com
Babel does a good job of transpiling (and have used it in a couple spots).  Actually almost everything (except for keywords) is do-able from ES6->ES5, so no real complaints (just looking up old ES5 documentation can be difficult though).

I've tried the debugger, and it typically wants to crash on me, so think it may need a revamp (or I'm not using it correctly).  It definitely does not like the EV3 which doesn't have firefox installed, and tends to hang on my desktop when i try it there.  I'll dig through the source some day and see if I can troubleshoot it.

Anderson Wiese

unread,
Sep 8, 2019, 4:19:02 PM9/8/19
to js...@googlegroups.com
A bit of history just for fun. In 2007 I was hired to rescue a struggling small home automation system written in php and quasi c++ for freebsd on a small x86 box. The team needed to maintain so many “driver” interfaces to all the different external systems (security, thermostats, lighting, the usual…) needed a friendlier programming environment than c++, so I chose JSDB, and then I wrote a simple real-time database in c++, with JSON documents and a simple JSON property matching query language, which I called CXDB. In hindsight it looks like I totally ripped off Nodejs and MongoDB, except neither existed in any form I was aware of back then. 

The technical architecture was fun and promising. A junior programmer managed to write a fairly complete Z-Wave driver in Javascript, which I considered to be quite an accomplishment. On the business side, well we’ve all heard that old story many times. 


Reply all
Reply to author
Forward
0 new messages