What I learned from sockets - Filipp Gelman - Meeting C++ 2023

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ก.ย. 2024
  • What I learned from sockets - Filipp Gelman - Meeting C++ 2023
    Slides: meetingcpp.com...
    Take the survey: survey.meeting...
    This talk will discuss how socket concepts like select or poll can be used when composing all kinds of concurrent operations in C++.
    Unix systems implement a rich set of primitives for working concurrently with file descriptors. Interfaces like select, poll, epoll, and kqueue allow the caller to wait until an event occurs on any of the specified file descriptors - that is, until at least one of them becomes "ready" for some operation. The Go programming language has a "select" statement with similar semantics. It may be used to wait for any of several "channels" to become ready.
    This talk will demonstrate to attendees that such an approach is also viable for solving problems that involve concurrent operations. It will also how C++ concurrency mechanisms could support similar semantics. By the end, it will provide answers to questions like: "How can I .get() the first of several futures?" and "How can I co_await the first of several coroutines?"

ความคิดเห็น • 11

  • @BenBarney
    @BenBarney 8 หลายเดือนก่อน +6

    Amazing talk and very informative!! Good stuff.

  • @chmod0644
    @chmod0644 8 หลายเดือนก่อน +4

    I like this structure of async code. Keep the evented subsystem tiny, and then react with synchronous routines. The low-level APIs are not that bad, to be honest.

  • @mrudo8663
    @mrudo8663 8 หลายเดือนก่อน +1

    I imagine this concept is used for near real-time applications to mitigate the lack of real time features of network protocols?

  • @justcurious1940
    @justcurious1940 8 หลายเดือนก่อน

    Interesting.

  • @wolpumba4099
    @wolpumba4099 8 หลายเดือนก่อน +8

    *Summary*
    *Introduction and Overview*
    - 00:00:00 Filipp Gelman from Bloomberg discusses lessons learned from Sockets.
    - 00:00:19 Focus on 'select', a powerful tool in Sockets for managing multiple activities.
    - 00:00:47 Select's unique approach is not widely used outside Sockets.
    - 00:01:02 Possibility of implementing a 'select'-like mechanism in pure C++.
    - 00:01:14 Discussion on different methods of handling asynchronous tasks and waiting in concurrent programming.
    *Handling Multiple Futures and Awaitables*
    - 00:01:52 Questions addressed in the talk include handling multiple futures and awaitables in C++.
    - 00:02:03 Challenges with standard library futures and alternatives like boost or folly.
    - 00:03:09 Emphasis on the need for cooperation in the mechanisms used for notifications.
    *Detailed Agenda and Socket Mechanics*
    - 00:03:29 Agenda Introduction to sockets, usage of select, C++ implementation, and centers and receivers.
    - 00:04:10 Explaining sockets, their similarity to files, and the read/write operations.
    - 00:07:19 Difference between blocking and non-blocking operations in socket communication.
    - 00:09:03 Kernel's role in managing in-memory buffers for sockets.
    *Challenges and Solutions in Socket Programming*
    - 00:10:33 Challenges of handling multiple sockets and the role of select in managing them.
    - 00:13:14 How select allows for efficient management of multiple file descriptors and actions based on their state.
    - 00:13:57 Highlighting the power and versatility of the select mechanism in socket programming.
    *Advanced Select and Poll Mechanisms*
    - 00:14:17 Select is a blocking operation without side effects, allowing for a separation of concerns.
    - 00:14:46 Limitation of select due to fixed size of the bit set.
    - 00:15:02 Introduction of `poll` as a solution, handling an array of file descriptors dynamically.
    - 00:15:38 Difference in handling file descriptors between select and poll.
    - 00:17:01 Efficiency issues with poll when dealing with a large number of file descriptors.
    - 00:17:42 Introduction of `Epoll` as a solution for efficient handling of large numbers of file descriptors.
    - 00:18:05 Explanation of how Epoll maintains a kernel-level data structure for tracking events.
    - 00:19:01 Use of Epoll to efficiently manage file descriptors and events.
    *Practical Application in Web Browsing*
    - 00:20:00 General pattern in async programming setup, wait for events, react, and repeat.
    - 00:20:46 Real-life example using these concepts in the context of a web browser connecting to a website.
    - 00:21:10 Explaining the process of resolving domain names into addresses for connection.
    - 00:22:10 Challenges in connecting to multiple IP addresses and the solution using the happy eyeballs algorithm.
    - 00:23:48 Implementation of the happy eyeballs algorithm using select, poll, or epoll.
    *Demonstrations and User Interaction*
    - 00:24:30 Details on non-blocking socket connection and monitoring it with epoll.
    - 00:26:03 Handling multiple connection attempts and waiting for a successful connection.
    - 00:27:18 Demonstration of compiling and running the connection code.
    - 00:27:49 Testing the connection under artificially delayed network conditions.
    - 00:28:44 Discussion of a potential issue in the connect function during user interaction changes.
    *Enhancements and Communication Strategies*
    - 00:29:10 Discussing limitations in communication when a separate thread is establishing a connection.
    - 00:29:24 Using sockets to communicate the result instead of returning it directly.
    - 00:29:46 Describing the capability of Unix domain sockets to send a socket over another socket.
    - 00:30:03 The possibility of transferring socket ownership between processes.
    - 00:30:41 Adjusting the code to monitor an additional 'out socket' for early shutdown.
    - 00:31:10 Handling different events in the loop established connections, failed connections, or output being shut.
    - 00:31:52 Modifying the surrounding function to put results in the output instead of returning directly.
    *Advanced Select Object Implementation*
    - 00:33:02 Explaining the modified event-driven loop in the updated code.
    - 00:33:37 Demonstrating the ability to interrupt the process and handle cancellations cleanly.
    - 00:34:20 Discussing the use of Timer FD in Linux for adding timeouts to asynchronous operations.
    - 00:35:10 Introducing the concept of abstracting kernel-level mechanisms into user-space C++ classes.
    - 00:35:40 Describing a select object class to manage arbitrary operations similar to EPUL.
    - 00:36:23 Explaining the flexibility of the abstraction for various operations, including sockets and GPU computation.
    *C++ Implementation and Extensions*
    - 00:37:17 Imagining the implementation of select-like functionality in C++ using handles and a select object.
    - 00:39:00 Demonstrating how C++ abstractions can mimic POSIX behavior in event-driven programming.
    - 00:39:26 Discussing the potential to convert the implementation into coroutines or senders.
    - 00:39:44 Beginning to implement a pipe-like structure in pure C++ for selectable operations.
    - 00:40:17 Describing the shared state for a C++ implemented pipe with reference counting.
    - 00:41:26 Using C++ type safety and variants to represent read and write results.
    - 00:42:30 Implementing reference counting for read and write handles to manage end-of-file states.
    - 00:43:10 Creating a function to capitalize characters passing through a hypothetical pipe.
    - 00:43:43 Detailing the structures of read and write handles with shared state and thread safety.
    - 00:44:25 Explaining the basic operations of reading, writing, and shutting in the custom pipe implementation.
    *Cooperation and Event Management*
    - 00:44:55 For select to work, it requires cooperation from the objects it's monitoring.
    - 00:45:29 Select class manages relationships between shared states and handles.
    - 00:46:23 Select object uses a single data structure for managing subscriptions and notifications.
    - 00:46:57 Shared states notify select objects of events, using intrusive doubly linked lists.
    - 00:47:55 Notify object in shared state alerts interested links about changes.
    - 00:48:45 Subscribe and unsubscribe methods handle thread safety and immediate notification if the event has already occurred.
    - 00:49:53 Select object can be treated like E-Poll, managing relationships with different handles.
    *Select Object Mechanisms and Demonstrations*
    - 00:50:37 Select object contains intrusive link lists for efficient event subscription and notification.
    - 00:51:56 Wait function in select object blocks until a notified event occurs.
    - 00:52:57 Next call to wait immediately returns if an event happened in between waits.
    - 00:53:44 Fairness is ensured in handling events from multiple handles.
    - 00:54:58 Controlling the awakening mechanism in select object allows flexibility, such as using coroutines or senders.
    - 00:56:07 Updated function using select object for efficient CPU usage, without busy waiting.
    - 00:57:02 Read and write handles can be templatized for different types or work on spans of characters.
    - 00:57:36 Presenter's project successfully uses these concepts for simple and reactive operations.
    - 00:57:48 Presenter unable to cover centers due to time constraints, refers to other talks for more information.
    - 00:58:34 Discussing the possibility of composing select objects, similar to composing ePOL file descriptors.
    - 00:59:18 Briefly touching on the essence of center-receiver stuff, mapping operations between handles and centers.
    *Conclusion and Final Thoughts*
    - 01:00:28 Discussion about handling 'no data to read' scenario using a condition variable in the select object.
    - 01:00:39 Storing a pointer to an abstract operation state in the select object for center specialization.
    - 01:00:47 Notified changes are similar, with slight modifications for different contexts.
    - 01:00:56 Possibility of treating a coroutine continuation as a center, allowing it to call wait select.
    - 01:01:04 Conclusion of the presentation.
    Disclaimer I used chatgpt4 to summarize the video transcript.
    I created the transcript with whisper base model.

    • @thelatestartosrs
      @thelatestartosrs 8 หลายเดือนก่อน +8

      i think watching the video is faster than reading this summary

    • @depralexcrimson
      @depralexcrimson 8 หลายเดือนก่อน

      this is crazy it can do that... how much time did it take? does it need crystal clear audio, does it analyze the audio to transcribe what the person is saying, etc? Or does this only work if the author uploads the full transcript themselves (or does yt auto-generate it)>??? this is craaaaazy.

    • @MeetingCPP
      @MeetingCPP  8 หลายเดือนก่อน +1

      Not sure what this bot is based on, might be the auto-generated subtitles from youtube used here with chatgpt.

    • @wolpumba4099
      @wolpumba4099 8 หลายเดือนก่อน

      ​@@MeetingCPP I wouldn't call myself a bot. I downloaded the audio track from youtube, ran it through whisper base model to create a transcript (as an srt file):
      ./main -l english -t 12 -m ~/src/whisper.cpp/models/ggml-base.bin -f output.wav -otxt -nt -osrt transcript
      Then I simplified the timestamps using awk and split the text file into segments and asked chatgpt4 to create a summary with timestamps.
      I see that the video now has subtitles in youtube. I guess I should have waited for a day for them to appear, then I could have saved the step with whisper.

  • @vladimiro3059
    @vladimiro3059 8 หลายเดือนก่อน

    Another bicycle was shown without any pros and con why you needed it, and why with so many mutexes. In my option concept of channel is much clear.

  • @sjswitzer1
    @sjswitzer1 7 หลายเดือนก่อน

    Yeah, std::future was a massive fail