Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #40041 > unrolled thread

Node.js: asynchronous input, and sequential processing

Started byAnton Shepelev <anton.txt@g{oogle}mail.com>
First post2021-05-12 11:05 +0300
Last post2021-05-13 09:53 -0700
Articles 12 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  Node.js: asynchronous input, and sequential processing Anton Shepelev <anton.txt@g{oogle}mail.com> - 2021-05-12 11:05 +0300
    Re: Node.js: asynchronous input, and sequential processing Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-05-12 10:28 +0000
      Re: Node.js: asynchronous input, and sequential processing Anton Shepelev <anton.txt@g{oogle}mail.com> - 2021-05-12 14:26 +0300
        Re: Node.js: asynchronous input, and sequential processing Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-05-12 11:30 +0000
    Re: Node.js: asynchronous input, and sequential processing The Natural Philosopher <tnp@invalid.invalid> - 2021-05-12 12:56 +0100
      Re: Node.js: asynchronous input, and sequential processing Anton Shepelev <anton.txt@g{oogle}mail.com> - 2021-05-13 18:59 +0300
        Re: Node.js: asynchronous input, and sequential processing The Natural Philosopher <tnp@invalid.invalid> - 2021-05-13 17:35 +0100
        Re: Node.js: asynchronous input, and sequential processing Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-05-13 16:45 +0000
          Re: Node.js: asynchronous input, and sequential processing The Natural Philosopher <tnp@invalid.invalid> - 2021-05-13 17:49 +0100
            Re: Node.js: asynchronous input, and sequential processing Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-05-13 17:20 +0000
              Re: Node.js: asynchronous input, and sequential processing The Natural Philosopher <tnp@invalid.invalid> - 2021-05-14 09:15 +0100
    Re: Node.js: asynchronous input, and sequential processing "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-05-13 09:53 -0700

#40041 — Node.js: asynchronous input, and sequential processing

FromAnton Shepelev <anton.txt@g{oogle}mail.com>
Date2021-05-12 11:05 +0300
SubjectNode.js: asynchronous input, and sequential processing
Message-ID<20210512110556.f2eb1917c4c2897f137dac40@g{oogle}mail.com>
Hello, all

I hope questions about Node.js are allowed in this group. Is
it possible in Node.js to write a server that will accept
incoming packets asynchronously and at maximum speed, save
them in a queue (say in a database), and process that queue
sequentially in the order of packet arrival. That is, I seem
to need two processes: one to store packets in the queue, and
the other to process that queue. But since JavaScript is all
asynchronous and single-threaded, I do not understand
whether and how it this architecture implementable in Node.js .

-- 
()  ascii ribbon campaign - against html e-mail
/\  http://preview.tinyurl.com/qcy6mjc [archived]

[toc] | [next] | [standalone]


#40042

FromJon Ribbens <jon+usenet@unequivocal.eu>
Date2021-05-12 10:28 +0000
Message-ID<slrns9nbdj.6lk.jon+usenet@raven.unequivocal.eu>
In reply to#40041
On 2021-05-12, Anton Shepelev <anton.txt@g{oogle}mail.com> wrote:
> Hello, all
>
> I hope questions about Node.js are allowed in this group. Is
> it possible in Node.js to write a server that will accept
> incoming packets asynchronously and at maximum speed, save
> them in a queue (say in a database), and process that queue
> sequentially in the order of packet arrival. That is, I seem
> to need two processes: one to store packets in the queue, and
> the other to process that queue. But since JavaScript is all
> asynchronous and single-threaded, I do not understand
> whether and how it this architecture implementable in Node.js .

Yes. You don't need two processes. You would set an event handler
which would receive the packets and append them to a queue, and
you would have a loop taking them off the queue and processing them.

Try searching for "javascript producer consumer queue".

[toc] | [prev] | [next] | [standalone]


#40043

FromAnton Shepelev <anton.txt@g{oogle}mail.com>
Date2021-05-12 14:26 +0300
Message-ID<20210512142651.7947f42e07edc7743b51bdf6@g{oogle}mail.com>
In reply to#40042
Jon Ribbens:

> Yes. You don't need two processes. You would set an event
> handler which would receive the packets and append them to
> a queue, and you would have a loop taking them off the
> queue and processing them.

Would that work if the processing part is strictly
synchronous, blocking code until the entire packet has been
processed? I feared that would lock the entire server on the
receiving end, because the there is only one thread.

> Try searching for "javascript producer consumer queue".

I will, thanks.  In my case, the whole purpose of the queue
is to decouple the asynchrnonous server from the synchronous
processor.

-- 
()  ascii ribbon campaign - against html e-mail
/\  http://preview.tinyurl.com/qcy6mjc [archived]

[toc] | [prev] | [next] | [standalone]


#40044

FromJon Ribbens <jon+usenet@unequivocal.eu>
Date2021-05-12 11:30 +0000
Message-ID<slrns9nf1r.6lk.jon+usenet@raven.unequivocal.eu>
In reply to#40043
On 2021-05-12, Anton Shepelev <anton.txt@g{oogle}mail.com> wrote:
> Jon Ribbens:
>
>> Yes. You don't need two processes. You would set an event
>> handler which would receive the packets and append them to
>> a queue, and you would have a loop taking them off the
>> queue and processing them.
>
> Would that work if the processing part is strictly
> synchronous, blocking code until the entire packet has been
> processed? I feared that would lock the entire server on the
> receiving end, because the there is only one thread.

Yes. You don't want a synchronous part and you will have to write
the code to not do that. It tends not to be hard with async/await
these days anyway.

[toc] | [prev] | [next] | [standalone]


#40045

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2021-05-12 12:56 +0100
Message-ID<s7gfop$r9h$2@dont-email.me>
In reply to#40041
On 12/05/2021 09:05, Anton Shepelev wrote:
> But since JavaScript is all
> asynchronous and single-threaded

Is it?

seems you need multiple threads to do asynch at all.


-- 
Gun Control: The law that ensures that only criminals have guns.

[toc] | [prev] | [next] | [standalone]


#40047

FromAnton Shepelev <anton.txt@g{oogle}mail.com>
Date2021-05-13 18:59 +0300
Message-ID<20210513185907.882edb65b45a9c0317f19b08@g{oogle}mail.com>
In reply to#40045
The Natural Philosopher:

> seems you need multiple threads to do asynch at all.

Why not?  Cannot the same thread execute JavaScript-code,
state-machine code, and I/O-code?

-- 
Anton Shepelev

-- 
()  ascii ribbon campaign - against html e-mail
/\  http://preview.tinyurl.com/qcy6mjc [archived]

[toc] | [prev] | [next] | [standalone]


#40048

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2021-05-13 17:35 +0100
Message-ID<s7jkfq$brh$1@dont-email.me>
In reply to#40047
On 13/05/2021 16:59, Anton Shepelev wrote:
> The Natural Philosopher:
> 
>> seems you need multiple threads to do asynch at all.
> 
> Why not?  Cannot the same thread execute JavaScript-code,
> state-machine code, and I/O-code?
> 
depends what you mean by thread.... to me its a lightweight 
*asynchronous* ...er thread.

-- 
The lifetime of any political organisation is about three years before 
its been subverted by the people it tried to warn you about.

Anon.

[toc] | [prev] | [next] | [standalone]


#40049

FromJon Ribbens <jon+usenet@unequivocal.eu>
Date2021-05-13 16:45 +0000
Message-ID<slrns9qlsq.59j.jon+usenet@raven.unequivocal.eu>
In reply to#40047
On 2021-05-13, Anton Shepelev <anton.txt@g{oogle}mail.com> wrote:
> The Natural Philosopher:
>> seems you need multiple threads to do asynch at all.
>
> Why not?  Cannot the same thread execute JavaScript-code,
> state-machine code, and I/O-code?

Pay no attention to this idiot, he has no clue at all what he's on about.

[toc] | [prev] | [next] | [standalone]


#40050

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2021-05-13 17:49 +0100
Message-ID<s7jlbk$vco$1@dont-email.me>
In reply to#40049
On 13/05/2021 17:45, Jon Ribbens wrote:
> On 2021-05-13, Anton Shepelev <anton.txt@g{oogle}mail.com> wrote:
>> The Natural Philosopher:
>>> seems you need multiple threads to do asynch at all.
>>
>> Why not?  Cannot the same thread execute JavaScript-code,
>> state-machine code, and I/O-code?
> 
> Pay no attention to this idiot, he has no clue at all what he's on about.
> 
Ok, what is a thread,. in *your* grammar?

If I say
asynch function ... I create a thread.



-- 
"I guess a rattlesnake ain't risponsible fer bein' a rattlesnake, but ah 
puts mah heel on um jess the same if'n I catches him around mah chillun".

[toc] | [prev] | [next] | [standalone]


#40052

FromJon Ribbens <jon+usenet@unequivocal.eu>
Date2021-05-13 17:20 +0000
Message-ID<slrns9qnv5.59j.jon+usenet@raven.unequivocal.eu>
In reply to#40050
On 2021-05-13, The Natural Philosopher <tnp@invalid.invalid> wrote:
> On 13/05/2021 17:45, Jon Ribbens wrote:
>> On 2021-05-13, Anton Shepelev <anton.txt@g{oogle}mail.com> wrote:
>>> The Natural Philosopher:
>>>> seems you need multiple threads to do asynch at all.
>>>
>>> Why not?  Cannot the same thread execute JavaScript-code,
>>> state-machine code, and I/O-code?
>> 
>> Pay no attention to this idiot, he has no clue at all what he's on about.
>
> Ok, what is a thread,. in *your* grammar?

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Concepts

[toc] | [prev] | [next] | [standalone]


#40053

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2021-05-14 09:15 +0100
Message-ID<s7lbjm$dbf$1@dont-email.me>
In reply to#40052
On 13/05/2021 18:20, Jon Ribbens wrote:
> On 2021-05-13, The Natural Philosopher <tnp@invalid.invalid> wrote:
>> On 13/05/2021 17:45, Jon Ribbens wrote:
>>> On 2021-05-13, Anton Shepelev <anton.txt@g{oogle}mail.com> wrote:
>>>> The Natural Philosopher:
>>>>> seems you need multiple threads to do asynch at all.
>>>>
>>>> Why not?  Cannot the same thread execute JavaScript-code,
>>>> state-machine code, and I/O-code?
>>>
>>> Pay no attention to this idiot, he has no clue at all what he's on about.
>>
>> Ok, what is a thread,. in *your* grammar?
> 
> https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Concepts
> 
So, what I said...

-- 
Climate is what you expect but weather is what you get.
Mark Twain

[toc] | [prev] | [next] | [standalone]


#40051

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2021-05-13 09:53 -0700
Message-ID<974def74-b27e-4945-9a34-6a0eb72b3bdbn@googlegroups.com>
In reply to#40041
On Wednesday, May 12, 2021 at 3:06:07 AM UTC-5, Anton Shepelev wrote:
> Hello, all 
> 
> I hope questions about Node.js are allowed in this group. Is 
> it possible in Node.js to write a server that will accept 
> incoming packets asynchronously and at maximum speed, save 
> them in a queue (say in a database), and process that queue 
> sequentially in the order of packet arrival. That is, I seem 
> to need two processes: one to store packets in the queue, and 
> the other to process that queue. But since JavaScript is all 
> asynchronous and single-threaded, I do not understand 
> whether and how it this architecture implementable in Node.js . 

Perhaps this is relevant:

<https://thewebdev.info/2020/08/12/how-to-build-a-job-queue-with-node-js/>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web