# When the timestamp period is 0.1s, the deployment becomes stuck

**URL:** <https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949>\
**Category:** General\
**Created:** [5 June 2023 08:13 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949 "2023-06-05T08:13:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![baishu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/baishu/32/72830_2.png) [@baishu](https://discourse.nodered.org/u/baishu)\
**Post date:** [5 June 2023 08:13 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/1 "2023-06-05T08:13:00Z")

</div>

When the timestamp period is 0.1s, the deployment becomes stuck. How can I optimize it

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 June 2023 08:22 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/2 "2023-06-05T08:22:46Z")

</div>

Sorry, but I'm confused.

So you have an `inject` node that injects the `timestamp` every 0.1 seconds - yes?

---

<div class="post-metadata">

**Author:** ![baishu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/baishu/32/72830_2.png) [@baishu](https://discourse.nodered.org/u/baishu)\
**Post date:** [5 June 2023 08:29 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/3 "2023-06-05T08:29:19Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/a/6a3665c611c02633d25d7f9c2cd888b75c73ad43.png)

---

<div class="post-metadata">

**Author:** ![baishu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/baishu/32/72830_2.png) [@baishu](https://discourse.nodered.org/u/baishu)\
**Post date:** [5 June 2023 08:30 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/4 "2023-06-05T08:30:59Z")

</div>

node-red is a single thread. Can I configure multiple threads?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 June 2023 08:37 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/5 "2023-06-05T08:37:59Z")

</div>

I am not the right person to ask that.

But having the `inject` node injecting every 0.1 seconds shouldn't be a problem.  
Unless you are doing a lot of things from that.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 June 2023 08:42 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/6 "2023-06-05T08:42:18Z")

</div>

What are you doing in the flow you trigger every 0.1 second?

---

<div class="post-metadata">

**Author:** ![baishu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/baishu/32/72830_2.png) [@baishu](https://discourse.nodered.org/u/baishu)\
**Post date:** [5 June 2023 08:51 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/8 "2023-06-05T08:51:39Z")

</div>

Business Scenario  
There are many nodes in a business flow. If you inject 0.1s, it will cause a lag.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [5 June 2023 09:02 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/9 "2023-06-05T09:02:49Z")

</div>

Why are you injecting every 0.1 seconds:  
Do you need a fast response to an occasional event or are you processing a large number of events?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 June 2023 09:21 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/10 "2023-06-05T09:21:59Z")

</div>

I don't mean what is the end purpose, I mean what sort of actions are you performing? Depending what they are, it may be possible to spawn some work into other processes.  
Is there lots of database activity for example, or network activity? or what?

If you run the inject at, say, 0.2 seconds, and look at the processor usage, what does it show?

---

<div class="post-metadata">

**Author:** ![baishu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/baishu/32/72830_2.png) [@baishu](https://discourse.nodered.org/u/baishu)\
**Post date:** [5 June 2023 09:50 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/12 "2023-06-05T09:50:03Z")

</div>

The nodes include camera and image processing nodes.  
The camera returns some pictures during the process of collecting the robot motion.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 June 2023 10:04 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/13 "2023-06-05T10:04:00Z")

</div>

Yeah, there is almost zero chance node will be able grab an image and process it in 100ms. You are just creating a bottleneck.

Instead of hitting it every 100ms, can you not identify when a new image is created and simply run it once instead of running it 10× per second?

---

<div class="post-metadata">

**Author:** ![baishu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/baishu/32/72830_2.png) [@baishu](https://discourse.nodered.org/u/baishu)\
**Post date:** [5 June 2023 10:16 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/14 "2023-06-05T10:16:30Z")

</div>

Even if it is 300ms, there will be a lag problem. There are other services for image processing.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [5 June 2023 10:21 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/15 "2023-06-05T10:21:34Z")

</div>

If your Node-red server cannot cope with the workload then you have to use a more powerful computer or else find a way to distribute the work among multiple devices.

One way might be:

Create images in a directory.  
A Node-red instance or OS utility can watch that directory and send the image to another device which is currently free (MQTT to send the data and busy/free status messages)

How often are images created (maximum)?  
How long on average does it take to process one image?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 June 2023 10:24 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/16 "2023-06-05T10:24:24Z")

</div>

> [@baishu](#):
>
> Even if it is 300ms, there will be a lag problem

I am not surprised. However, you have not provided any details so cannot give you concrete advice.

- How are you currently processing images (what nodes?)
- What processing are you doing (resizing?, cropping?, colour adjustments? ML routines?)
- What size are these images (wxh)?

As I said before, cant you detect when an image needs processing instead of blindly processing every 100ms or 300ms?

Have you timed the flow to see how long it actually takes? Something like [this simple flow timer](https://flows.nodered.org/flow/63f29373e826a9fd4943d679d43e725f) will tell you how long it takes.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [5 June 2023 10:33 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/17 "2023-06-05T10:33:09Z")

</div>

> [@Steve-Mcl](#):
>
> As I said before, cant you detect when an image needs processing instead of blindly processing every 100ms or 300ms?

But presumaby it takes very little time to process an image which doesn't exist yet.

@baishu really needs to give us some statistics.  
How big are the images, how frequent, how soon **must** an image be processed, etc, etc.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [5 June 2023 11:40 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/18 "2023-06-05T11:40:39Z")

</div>

> [@baishu](#):
>
> Can I configure multiple threads?

Not using Node-RED directly though you can certainly spawn other threads using Node.js capabilities.

> [@baishu](#):
>
> There are many nodes in a business flow. If you inject 0.1s, it will cause a lag.

That is highly dependent on what the flow is doing. The actual execution order of things in a Node.js flow can get very complex. While Node.js is essentially single-threaded, it manages multiple actions using a loop mechanism and well defined asynchronous functions. So being single-threaded is a lot less of an issue than might be assumed. Node.js manages the queue of actions and allows the loop to continue while waiting for long-running tasks.

As others have said, if you want help, you need to describe more about the flow so that we can help unpick it.

In addition, a constant, rapid trigger is often a sign of faulty design that might possibly be replaced with an event-driven flow. But without knowing details, it is impossible to say.

---

<div class="post-metadata">

**Author:** ![baishu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/baishu/32/72830_2.png) [@baishu](https://discourse.nodered.org/u/baishu)\
**Post date:** [5 June 2023 23:56 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/19 "2023-06-05T23:56:21Z")

</div>

Thanks alot  
The scene we encountered: during the shooting process of the camera, the collection speed is about 1 second and 10 times, and the pictures collected by the camera reach a node (containing some parameters of image processing, this node sends the image parameter content to another processing service, and the processed image will flow to its own stream for other processing.  
I tested it. There are two function following. The trigger cycle is set to 0.1, 0.3 or 0.5. In order to test whether the processing can be normal at high frequencies without lagging (the so-called user lagging: long deployment time-the interface mask layer takes a long time during deployment). When an event is triggered, click deploy.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/d/ddb3492d553c775138ea3a8ea85af67752a25feb.png)

I think there is a problem with the setting of our business scenario. I will reset it here. In fact, what I want to confirm is inject Node. Is it reasonable to set the period execution time to 0.1 or less than 1s?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/1/f1f6d7e3092249b40493b2e04145f71362164eb5.png)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [6 June 2023 00:43 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/20 "2023-06-06T00:43:42Z")

</div>

I've no idea what camera node you are using but I strongly suspect that is the limitation. I've not tested the inject node at those speeds but I can't think of any reason it wouldn't be able to cope just fine. That is easily tested of course.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 June 2023 06:51 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/21 "2023-06-06T06:51:39Z")

</div>

> [@baishu](#):
>
> I think there is a problem with the setting of our business scenario. I will reset it here. In fact, what I want to confirm is inject Node. Is it reasonable to set the period execution time to 0.1 or less than 1s

Yes, it is possible, but not desirable.

As others have said several times, triggering continuously on an event based system is likely due to flawed design.

If you answer the questions we have asked we can likely instruct you on how to improve your flows.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 August 2023 06:52 UTC](https://discourse.nodered.org/t/when-the-timestamp-period-is-0-1s-the-deployment-becomes-stuck/78949/22 "2023-08-05T06:52:12Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
