A
A
Alino4ka2016-10-12 09:30:38
Node.js
Alino4ka, 2016-10-12 09:30:38

What is the best way to process and record a large amount of data?

Good day Colleagues.
I am writing one service for processing incoming data.
The data looks like:
{sip:"1.1.1.1:11233", title:"test", value:"log"}
sip: this is the source of the data.
title: title, with one title several data can come for a specific sip
value: the data itself (string)
data I will store unique for each sip+title
let's say:

sip:1.1.1.1:11233, title:block, value:wr3333333333
sip:1.1.1.1:11233, title:block, value:wefwefwfwefew
sip:1.1.1.1:11233, title:view, value:ppppppp

that is, for a specific sip, the title with the same name may contain different data (value).
I only need unique data! no repeats.
In php, I would choose the following logic: Upon
receipt, the data is written to a multidimensional array, example:
$data_ara[$sip][$title][]=$value;
further, it would simply process the array before recording, removing duplicates for each title, form an insert query and write the data to mysql.

But I don’t know how to enter node.js, as I understand it, this method doesn’t work at all, well, it didn’t work out for me, at least in a multidimensional array, I can’t write data like in php.
Prompt knowledgeable people how to be?
ps: I’ll clarify, I don’t write the data right away due to the fact that they can come in for example 30-40 per second, this is a lot to write them somewhere indiscriminately, it’s more logical to process them and write them down in one action every 5 seconds (let’s say) .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VoidVolker, 2016-10-12
@Alino4ka

For example like this:

var myDataObject = {}
    , dataExample1 = { sip:"1.1.1.1:11233", title:"block", value:"val 1"}
    , dataExample2 = { sip:"1.1.1.1:11233", title:"block", value:"val 2"}
    , dataExample3 = { sip:"1.1.1.1:11233", title:"view", value:"val 3"}
;

addMyData = function(data){
    var exData = myDataObject[data.sip]
        , exTitle 
    ;

    if( !exData ){
        exData = myDataObject[data.sip] = { title: {} }
    }

    exTitle = exData.title[data.title];

    if( !exTitle ){
        exTitle = exData.title[data.title] = []
    }

    exTitle.push( data.value );
}

addMyData(dataExample1);
addMyData(dataExample2);
addMyData(dataExample3);

console.log(myDataObject);
console.info(JSON.stringify(myDataObject, null, 4));

If there can be only one value and the old values ​​are not needed, then the array is not needed, but immediately write it to the title.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question