Giter Site home page Giter Site logo

Comments (3)

tagomoris avatar tagomoris commented on August 22, 2024

This problem will last even after merging #82

from fluent-logger-golang.

akerouanton avatar akerouanton commented on August 22, 2024

@tagomoris Are you already working on this? 🙂

About the implementation details, I have the following solution in mind that would be lock-free:

  1. Start an ackRecv() goroutine in newWithDialer when Ack == true
  2. Use a dedicated channel (eg. named acksCh) to communicate between write() and ackRecv()
  3. Create an ack channel for each message in write() to communicate back from ackRecv() to write()
  4. Send a struct containing the ack ID, the ack channel and bool (with true value) from write() to ackRecv() (before actually writing to the connection, to avoid race conditions)
  5. Block the write() until either the ack channel or a timeout channel got triggered
    i. If the the timeout channel got triggered, resend the same struct as 4. but with the bool turned false.
  6. Concurrently read from the acksCh and the socket
    i. When an "ack request" is received from acksCh put it in a local map[string]struct{} if the bool is true or remove it if the bool is false.
    ii. When an ack response is received from the socket, check if there's a matching ID in the local map and send a struct{} to the appropriate channel and remove it from the local map.
  7. When Close() is called, acksCh got closed
    i. Set a local shouldClose bool to true in acksRecv()
    ii. When the last ackMessage is received or removed from the local map (cf. 6.) and shouldClose is true, exit from acksRecv()

My only concern with this solution is regarding #104.

from fluent-logger-golang.

tagomoris avatar tagomoris commented on August 22, 2024

I've not worked on this yet - no plans for now.
@akerouanton Your idea was an alternative. I don't have enough knowledge about the creation cost of dedicated channels, so I can't evaluate which is better - but the idea of using channels seems a golang-ish solution.

from fluent-logger-golang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.