# Local context storage not intended for large data arrays?

**URL:** https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377
**Category:** General
**Created:** [8 November 2021 13:38 UTC](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377 "2021-11-08T13:38:25Z")
**Posts on this page:** 13
**Page:** 2

<div class="post-metadata">

### Author: ![metter](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@metter](https://discourse.nodered.org/u/metter)
#### Post date: [8 November 2021 18:24 UTC](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377/21 "2021-11-08T18:24:24Z")

</div>

My server is a new fanless built. I repeatedly had it freezing over the past 2 months. The case was super hot every time that happened. Seems like this very issue must have hogged my CPU and overheated the system beyond what heatpipes could handle.

---

<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: [8 November 2021 21:31 UTC](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377/22 "2021-11-08T21:31:21Z")

</div>

Node red will only hog one core so that on its own should not overheat it, also a modern processor will cut its frequency down if it gets too hot, so again it should not overheat. If it is stopping then something else is going on.

---

<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: [8 November 2021 21:35 UTC](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377/23 "2021-11-08T21:35:50Z")

</div>

In order to find a better solution to your overall problem, the first question is whether you actually need to store all that data in the first place. What is in the data and why do you need to keep it?

---

<div class="post-metadata">

### Author: ![metter](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@metter](https://discourse.nodered.org/u/metter)
#### Post date: [9 November 2021 10:21 UTC](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377/24 "2021-11-09T10:21:59Z")

</div>

It's historic market data. I run simulations through the array, which gives me roughly a month of data to play with.  
I once had it set up with s SQL database, but that was such an incredible pain in node red. Everything was do much easier once I used globalcontext storage instead.

---

<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: [9 November 2021 10:39 UTC](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377/25 "2021-11-09T10:39:02Z")

</div>

Have you been watching the issue I linked to? Context is not going to work with such a huge amount of data. Not at the moment at least.

---

<div class="post-metadata">

### Author: ![metter](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@metter](https://discourse.nodered.org/u/metter)
#### Post date: [9 November 2021 10:54 UTC](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377/26 "2021-11-09T10:54:54Z")

</div>

Just read through it now. Thanks for raising the issue by the way.  
Didn't understand quite all of it 😃, but I am glad to at least know that the way I have things setup, it will never survive a reboot.  
I have learned a lot while using the disk stores, so I feel optimistic I can amend my flows with "flushing" to SQL for backup, while retaining memory context store workflows.

---

<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: [9 November 2021 12:53 UTC](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377/27 "2021-11-09T12:53:58Z")

</div>

> [@metter](#):
>
> My server is a new fanless built. I repeatedly had it freezing over the past 2 months. The case was super hot every time that happened. Seems like this very issue must have hogged my CPU and overheated the system beyond what heatpipes could handle.

> [@Colin](#):
>
> Node red will only hog one core so that on its own should not overheat it, also a modern processor will cut its frequency down if it gets too hot, so again it should not overheat. If it is stopping then something else is going on.

It is possible that such large in-memory data may be causing paging - that would happen on different threads/cpu's. Also possilbe that the large-scale changes may be triggering sudden large garbage-collection activities.

You would need to run some system monitoring to see what is happening.

> [@Colin](#):
>
> Have you been watching the issue I linked to? Context is not going to work with such a huge amount of data. Not at the moment at least.

Unfortunately, it has to be said that Python is much better at handling this than Node.js is. In Python with suitable libraries, this would be trivial.

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [9 November 2021 13:19 UTC](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377/28 "2021-11-09T13:19:33Z")

</div>

Now 1/2 G is a heavy chunk to shuffle. I haven't tried but what if you save it via MQTT and the retention flag set? Would that kill the broker??

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [9 November 2021 13:20 UTC](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377/29 "2021-11-09T13:20:49Z")

</div>

That would not be a good idea - it really is not what a broker is optimised for.

---

<div class="post-metadata">

### Author: ![jmorris644](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jmorris644/32/31964_2.png) [@jmorris644](https://discourse.nodered.org/u/jmorris644)
#### Post date: [9 November 2021 14:36 UTC](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377/30 "2021-11-09T14:36:45Z")

</div>

I have a similar use case. Every 5 minutes I get 4 different status messages from each remote device that I am keeping track of. Through an update query I save all 4 to the same row using an "ON DUPLICATE KEY UPDATE" SQL syntax. Because I have a date/time field it is very easy to delete the oldest row when I add a new one. The SQL ends up being fairly easy. I can share through DM if you wish. I think this would eliminate any issues you may be having by trying to keep such large arrays in memory.

---

<div class="post-metadata">

### Author: ![metter](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@metter](https://discourse.nodered.org/u/metter)
#### Post date: [10 November 2021 07:52 UTC](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377/31 "2021-11-10T07:52:07Z")

</div>

That would be very useful, thank you. Yes please. I already have postgres running for something entirely different. Played around yesterday with storing JSON's and had some initial successes. Your example will be super helpful.

---

<div class="post-metadata">

### Author: ![jmorris644](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jmorris644/32/31964_2.png) [@jmorris644](https://discourse.nodered.org/u/jmorris644)
#### Post date: [10 November 2021 14:42 UTC](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377/32 "2021-11-10T14:42:38Z")

</div>

The code below is a little cryptic because I do some JSON extracts into variables before the SQL. We have 4 different update status' coming from our remote devices every 5 minutes. the first 3 characters of the JSON string is the update type. So I extract that into the variable strJsonTopicType. and that matches the field names in the table. The table key is the device serial number "SN" plus the device datetime. So when an update occurs and no key is found it creates a new row. If the key is found it then does an update. So eventually I get all 4 updates into a single row by using this method. I hope this all makes sense.

```auto
msg.topic = "INSERT INTO tblRawJson_v2 (" + strJsonTopicType + ",stickSN,stickDateTime) VALUES ('";
msg.topic = msg.topic + (msg.payload) + "','" + jsonTmp["DeviceSN"] + "','" + jsonTmp["DeviceDT"];
msg.topic = msg.topic + "') ON DUPLICATE KEY UPDATE " + strJsonTopicType + " = '" + (msg.payload) + "';";

```

---

<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: [24 November 2021 14:43 UTC](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377/33 "2021-11-24T14:43:36Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/local-context-storage-not-intended-for-large-data-arrays/53377.md?page=1)
