Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

RangeError: Invalid string lenght #24

Open
pontarolli opened this issue Jan 17, 2020 · 3 comments
Open

RangeError: Invalid string lenght #24

pontarolli opened this issue Jan 17, 2020 · 3 comments

Comments

@pontarolli
Copy link

Hello, I am a graduate student in electrical engineering from the State University of São Paulo, Brazil - SP and we are using the molecular framework as the basis for our project.

We would like to do the orchestration and choreography of microservices applied in an industrial plant to control a level mesh comparing the total execution time as well as the time of each route.

To do this we saw that you have the molecular-console-tracer module, we created a basic orchestration service to call each node's hello services sequentially:

// services/ orchestration.service.js

"use strict";

module.exports = {
	name: "orchestration", 
	actions: {   
		async start(ctx){			
			await ctx.call("greeter.hello",{},{nodeID: "node-12"})
			await ctx.call("greeter.hello",{},{nodeID: "node-13"})
			await ctx.call("greeter.hello",{},{nodeID: "node-21"})
	   }
	},
};

We did 2 tests before we ran our application to understand it better. The provision of services was distributed as follows in the tests:

Test 1:
image

Result 1
image

Test 2:
image

Result 2

image

As you can see in our test 2 when calling node-21's greeter.hello service that is on raspberry we got an error (RangeError: Invalid string lenght) show in the figure above in results.

Could you help me remedy this mistake?

Taking advantage of the post I would like to better understand how these times are measured, ie when the time starts and when it ends, and know where these values ​​are stored if you want to build a mean and standard deviation graph. I say this because I got a little confused in test 1, because we have two api.rest in the result should not be just one, api.rest gives two different times api.rest 28ms and api.rest 3ms.

@AndreMaz
Copy link
Member

AndreMaz commented Jan 17, 2020

@icebob can explain this much better than me but I can give some hints about how metrics are measured.

where these values ​​are stored

Doing some quick look at console-tracer source code, it seems to have an object called request that stores the metrics.

created() {
this.requests = {};
chalk.enabled = this.settings.colors;

The console-tracer service stores the metrics data, that it receives via events, in request object.

"metrics.trace.span.start"(payload) {
this.requests[payload.id] = payload;
payload.spans = [];
if (payload.parent) {
let parent = this.requests[payload.parent];
if (parent)
parent.spans.push(payload.id);
}
},
"metrics.trace.span.finish"(payload) {
let item = this.requests[payload.id];
Object.assign(item, payload);
if (!payload.parent) {
this.printRequest(payload.id);
// TODO: remove old printed requests
}
}
},

This means that you can extend console-tracer service and add and action that can access the request object and, therefore, you can do some processing and compute the desired data.

Regarding the actual content of metrics, you can see it here

I would like to better understand how these times are measured, ie when the time starts and when it ends

The metrics are registered as a middleware, i.e., they wrap action calls. So the metrics middleware is called right before executing an action and after the response is received back.

The metrics start function looks like this:
https://github.com/moleculerjs/moleculer/blob/9a9a7bd88defbfc3e9a2071b6a36b883effc488e/src/middlewares/metrics.js#L40-L49

Stop looks like this:
https://github.com/moleculerjs/moleculer/blob/9a9a7bd88defbfc3e9a2071b6a36b883effc488e/src/middlewares/metrics.js#L99-L123

And finally here is how they are called:
https://github.com/moleculerjs/moleculer/blob/9a9a7bd88defbfc3e9a2071b6a36b883effc488e/src/middlewares/metrics.js#L163-L206

Regarding the error. Can you please create a reproduction repo ?

@pontarolli
Copy link
Author

I will study the code a little more calmly to understand everything you have informed me. Because basically I need this time data always being recorded in a spreadsheet and then plotting it on a chart having the mean and standard deviation.

Regarding the error follows my repository:
https://github.com/RicardoPasquati/moleculer-console-tracer-RangeError

@pontarolli
Copy link
Author

@AndreMaz

I believe that the error I was giving was due to the console-tracer module trying to print a very large value, so RangeError, something very long:

[...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................[|||||||||].................................................................................]

This still needs to be resolved, perhaps more calmly.

I was able to run Tracer on two devices now, just using the request object that stores all the data.

Practically I disabled all printing in the console, and left only the functionality of the request object and used this.logger.info to print the request in the console. In the future I will make these records in a database.

You can close the topic.

Thank you very much for the explanation and help.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants