comp.lang.ada
 help / color / mirror / Atom feed
From: "A.J." <ianozia@gmail.com>
Subject: Re: Broadcast / iterate to all Connection objects via Simple Components?
Date: Sat, 18 Feb 2023 17:27:02 -0800 (PST)	[thread overview]
Message-ID: <aabea618-3be7-4257-aad7-5fde634c3090n@googlegroups.com> (raw)
In-Reply-To: <k54n43FiafrU1@mid.individual.net>

Thank you for all of the responses and discussion, it pointed me in the right direction!  The "chat server"[1] (if you could call it that) does work, and my friends and I were able to telnet into it and chat.  One of my friends even tried throwing things at the server to break it, but it didn't crash!

Dmitry, maintaining a list of clients was the vital part I was missing.  I played around with using synchronized queues and tasks, but ended up defaulting to an ordered map with a UID as the key and wrapped it in a protected type.  I couldn't get Send() to send more data than Available_To_Send (after calling it, Available_To_Send ended up returning 0, and continued to do so despite wrapping Send() in a loop), but increasing the send buffer to 8kb per connection worked fine.  I would simply loop through that ordered map each time I needed to send something to all of the clients.

I really like simple components, and it would be neat if the GNAT maintainers implement epoll in the backend for linux systems, kqueue for BSD and MacOS.  Any server I write will be for linux though anyway.  I'm also interested in trying to benchmark Simple Component's connections server (both pooled and standard) against epoll to see how it fares.  Perhaps the clever tasking that the Connections Server utilizes can keep up with epoll despite what GNAT.Sockets utilizes!

Regarding coroutines vs tasks, I think at a high level it's hard to differentiate, but at a lower level, when I think of tasks vs what a coroutine would be, I think of Go, and their "goroutines."[2]  Creating a task in Ada, at least on linux, ends up creating a pthread, and you get all of the overhead that comes with threading (it's initialized in the kernel).  coroutines are managed by the go runtime (I believe in user space) and have much less overhead to create or manage, since it's not creating a specific thread.

Ada 202x supports the "parallel" block[3] though I understand no runtime has utilized it yet-- would that end up being a coroutine or is it meant for something else?

[1] https://github.com/AJ-Ianozi/protohackers/tree/main/budget_chat/src
[2] https://www.geeksforgeeks.org/golang-goroutine-vs-thread/
[3] http://www.ada-auth.org/standards/22rm/html/RM-5-6-1.html

Kind regards,
AJ.

  reply	other threads:[~2023-02-19  1:27 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-07 20:29 Broadcast / iterate to all Connection objects via Simple Components? A.J.
2023-02-08  8:55 ` Dmitry A. Kazakov
2023-02-08  9:55 ` Jeffrey R.Carter
2023-02-13  7:28   ` Emmanuel Briot
2023-02-13  8:30     ` Dmitry A. Kazakov
2023-02-13  8:44       ` Emmanuel Briot
2023-02-13 10:55         ` Dmitry A. Kazakov
2023-02-13 11:07           ` Emmanuel Briot
2023-02-13 11:57             ` Dmitry A. Kazakov
2023-02-13 13:22               ` Niklas Holsti
2023-02-13 15:10                 ` Dmitry A. Kazakov
2023-02-13 16:26                   ` Niklas Holsti
2023-02-13 19:48                     ` Dmitry A. Kazakov
2023-02-15  9:54                       ` Niklas Holsti
2023-02-15 10:57                         ` Dmitry A. Kazakov
2023-02-15 18:37                           ` Niklas Holsti
2023-02-19  1:27                             ` A.J. [this message]
2023-02-19  8:29                               ` Dmitry A. Kazakov
2023-02-19 14:37                               ` Niklas Holsti
2023-02-13 15:43                 ` J-P. Rosen
2023-02-13 16:40             ` Jeremy Grosser <jeremy@synack.me>
2023-02-13 20:33 ` Daniel Norte de Moraes
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox