Send message to specific go routine based on keyGoroutines or locks for concurrent clientsgolang idiomatic way to stop a forGo deadlock all goroutines asleepall go routines are asleep deadlockExplain: Don't communicate by sharing memory; share memory by communicatinggolang dispatcher using map and channelsGoroutines and messages de-duplicatioinReading values from a different threadAvoiding deadlocks in bidirectional communication between goroutinesRunning another instance of the same program with a goroutine?

Is Fourier series a sampled version of Fourier transform?

Duplicate and slide edge (rip from boundary)

Is the Microsoft recommendation to use C# properties applicable to game development?

Airline power sockets shut down when I plug my computer in. How can I avoid that?

May the tower use the runway while an emergency aircraft is inbound?

Why do we use low resistance cables to minimize power losses?

How does the ability of Bloodthirsty Aerialist resolve with other life link creatures?

Can anyone help me what's wrong here as i can prove 0 = 1?

What would cause a nuclear power plant to break down after 2000 years, but not sooner?

How do I ask for 2-3 days per week remote work in a job interview?

Would molten tin solidify and coat an organic horn?

Resource is refusing to do a handover before leaving

What is the question mark?

Is there any official ruling on how characters go from 0th to 1st level in a class?

6502: is BCD *fundamentally* the same performance as non-BCD?

Why don't modern jet engines use forced exhaust mixing?

What are the advantages of this gold finger shape?

Knights and Knaves on a (Not So) Deserted Island

Weird resistor with dots around it on the schematic

Can I use my OWN published papers' images in my thesis without Copyright infringment

Are there any cons in using rounded corners for bar graphs?

Generating Error when data size is larger then max text repl size

Will Force.com stop working on salesforce Lightning?

How would armour (and combat) change if the fighter didn't need to actually wear it?



Send message to specific go routine based on key


Goroutines or locks for concurrent clientsgolang idiomatic way to stop a forGo deadlock all goroutines asleepall go routines are asleep deadlockExplain: Don't communicate by sharing memory; share memory by communicatinggolang dispatcher using map and channelsGoroutines and messages de-duplicatioinReading values from a different threadAvoiding deadlocks in bidirectional communication between goroutinesRunning another instance of the same program with a goroutine?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4















I would like to implement the following:



  • Multiple worker goroutines running, each executing some business logic.

  • Different Http handlers distributes work to these workers.

  • Input (via a channel) to each goroutine will be some data (State) which will have one Key in it.

  • Multiple data with same key is also possible.

Our requirement is that processing for a specific Key has to be serialised. e.g. goroutine 1 is processing data related to Key:1234 then other goroutines should not process other data for the same key before goroutine 1 does its job.



Can anybody suggest best approach to do that?










share|improve this question





















  • 2





    What have you tried so far? Do you already have something?

    – Abdullah
    Mar 27 at 12:38







  • 4





    Just make a map[Key]chan State.

    – Peter
    Mar 27 at 12:43






  • 3





    The pattern you're trying to implement is called fan-out (usually coupled with fan-in). I suggest searching for this. There are different specific ways to implement it with goroutines. There is no single "right answer".

    – Flimzy
    Mar 27 at 12:45












  • a possible solution, give lock for every key, map[key]sync.Mutex

    – nail fei
    Mar 27 at 13:35


















4















I would like to implement the following:



  • Multiple worker goroutines running, each executing some business logic.

  • Different Http handlers distributes work to these workers.

  • Input (via a channel) to each goroutine will be some data (State) which will have one Key in it.

  • Multiple data with same key is also possible.

Our requirement is that processing for a specific Key has to be serialised. e.g. goroutine 1 is processing data related to Key:1234 then other goroutines should not process other data for the same key before goroutine 1 does its job.



Can anybody suggest best approach to do that?










share|improve this question





















  • 2





    What have you tried so far? Do you already have something?

    – Abdullah
    Mar 27 at 12:38







  • 4





    Just make a map[Key]chan State.

    – Peter
    Mar 27 at 12:43






  • 3





    The pattern you're trying to implement is called fan-out (usually coupled with fan-in). I suggest searching for this. There are different specific ways to implement it with goroutines. There is no single "right answer".

    – Flimzy
    Mar 27 at 12:45












  • a possible solution, give lock for every key, map[key]sync.Mutex

    – nail fei
    Mar 27 at 13:35














4












4








4








I would like to implement the following:



  • Multiple worker goroutines running, each executing some business logic.

  • Different Http handlers distributes work to these workers.

  • Input (via a channel) to each goroutine will be some data (State) which will have one Key in it.

  • Multiple data with same key is also possible.

Our requirement is that processing for a specific Key has to be serialised. e.g. goroutine 1 is processing data related to Key:1234 then other goroutines should not process other data for the same key before goroutine 1 does its job.



Can anybody suggest best approach to do that?










share|improve this question
















I would like to implement the following:



  • Multiple worker goroutines running, each executing some business logic.

  • Different Http handlers distributes work to these workers.

  • Input (via a channel) to each goroutine will be some data (State) which will have one Key in it.

  • Multiple data with same key is also possible.

Our requirement is that processing for a specific Key has to be serialised. e.g. goroutine 1 is processing data related to Key:1234 then other goroutines should not process other data for the same key before goroutine 1 does its job.



Can anybody suggest best approach to do that?







go concurrency goroutine






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 6:40







Girdhar Sojitra

















asked Mar 27 at 12:31









Girdhar SojitraGirdhar Sojitra

5323 silver badges13 bronze badges




5323 silver badges13 bronze badges










  • 2





    What have you tried so far? Do you already have something?

    – Abdullah
    Mar 27 at 12:38







  • 4





    Just make a map[Key]chan State.

    – Peter
    Mar 27 at 12:43






  • 3





    The pattern you're trying to implement is called fan-out (usually coupled with fan-in). I suggest searching for this. There are different specific ways to implement it with goroutines. There is no single "right answer".

    – Flimzy
    Mar 27 at 12:45












  • a possible solution, give lock for every key, map[key]sync.Mutex

    – nail fei
    Mar 27 at 13:35













  • 2





    What have you tried so far? Do you already have something?

    – Abdullah
    Mar 27 at 12:38







  • 4





    Just make a map[Key]chan State.

    – Peter
    Mar 27 at 12:43






  • 3





    The pattern you're trying to implement is called fan-out (usually coupled with fan-in). I suggest searching for this. There are different specific ways to implement it with goroutines. There is no single "right answer".

    – Flimzy
    Mar 27 at 12:45












  • a possible solution, give lock for every key, map[key]sync.Mutex

    – nail fei
    Mar 27 at 13:35








2




2





What have you tried so far? Do you already have something?

– Abdullah
Mar 27 at 12:38






What have you tried so far? Do you already have something?

– Abdullah
Mar 27 at 12:38





4




4





Just make a map[Key]chan State.

– Peter
Mar 27 at 12:43





Just make a map[Key]chan State.

– Peter
Mar 27 at 12:43




3




3





The pattern you're trying to implement is called fan-out (usually coupled with fan-in). I suggest searching for this. There are different specific ways to implement it with goroutines. There is no single "right answer".

– Flimzy
Mar 27 at 12:45






The pattern you're trying to implement is called fan-out (usually coupled with fan-in). I suggest searching for this. There are different specific ways to implement it with goroutines. There is no single "right answer".

– Flimzy
Mar 27 at 12:45














a possible solution, give lock for every key, map[key]sync.Mutex

– nail fei
Mar 27 at 13:35






a possible solution, give lock for every key, map[key]sync.Mutex

– nail fei
Mar 27 at 13:35













1 Answer
1






active

oldest

votes


















0














I am using map[Key]chan State Map to store mapping for Key to Channel.Creating Go Routine for each Key.



var keymap sync.Map
func handle_webservice(req WebReq) {
val, ok := keymap.Load(req.Key)
if ok
val1, _ := val.(chan Event)
val1 <- EventData: req
else
ch := make(chan Event, 5)
go Worker(ch)
keymap.Store(req.Key, ch)
ch <- EventSource: WEBSERVICE, Data: req


func sendToWorker(event Event)
val, ok := keymap.Load(event.Key)
if ok
val1, _ := val.(chan Event)
select
case val1 <- event:
default:









share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55377282%2fsend-message-to-specific-go-routine-based-on-key%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I am using map[Key]chan State Map to store mapping for Key to Channel.Creating Go Routine for each Key.



    var keymap sync.Map
    func handle_webservice(req WebReq) {
    val, ok := keymap.Load(req.Key)
    if ok
    val1, _ := val.(chan Event)
    val1 <- EventData: req
    else
    ch := make(chan Event, 5)
    go Worker(ch)
    keymap.Store(req.Key, ch)
    ch <- EventSource: WEBSERVICE, Data: req


    func sendToWorker(event Event)
    val, ok := keymap.Load(event.Key)
    if ok
    val1, _ := val.(chan Event)
    select
    case val1 <- event:
    default:









    share|improve this answer





























      0














      I am using map[Key]chan State Map to store mapping for Key to Channel.Creating Go Routine for each Key.



      var keymap sync.Map
      func handle_webservice(req WebReq) {
      val, ok := keymap.Load(req.Key)
      if ok
      val1, _ := val.(chan Event)
      val1 <- EventData: req
      else
      ch := make(chan Event, 5)
      go Worker(ch)
      keymap.Store(req.Key, ch)
      ch <- EventSource: WEBSERVICE, Data: req


      func sendToWorker(event Event)
      val, ok := keymap.Load(event.Key)
      if ok
      val1, _ := val.(chan Event)
      select
      case val1 <- event:
      default:









      share|improve this answer



























        0












        0








        0







        I am using map[Key]chan State Map to store mapping for Key to Channel.Creating Go Routine for each Key.



        var keymap sync.Map
        func handle_webservice(req WebReq) {
        val, ok := keymap.Load(req.Key)
        if ok
        val1, _ := val.(chan Event)
        val1 <- EventData: req
        else
        ch := make(chan Event, 5)
        go Worker(ch)
        keymap.Store(req.Key, ch)
        ch <- EventSource: WEBSERVICE, Data: req


        func sendToWorker(event Event)
        val, ok := keymap.Load(event.Key)
        if ok
        val1, _ := val.(chan Event)
        select
        case val1 <- event:
        default:









        share|improve this answer













        I am using map[Key]chan State Map to store mapping for Key to Channel.Creating Go Routine for each Key.



        var keymap sync.Map
        func handle_webservice(req WebReq) {
        val, ok := keymap.Load(req.Key)
        if ok
        val1, _ := val.(chan Event)
        val1 <- EventData: req
        else
        ch := make(chan Event, 5)
        go Worker(ch)
        keymap.Store(req.Key, ch)
        ch <- EventSource: WEBSERVICE, Data: req


        func sendToWorker(event Event)
        val, ok := keymap.Load(event.Key)
        if ok
        val1, _ := val.(chan Event)
        select
        case val1 <- event:
        default:










        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 5 at 12:33









        Girdhar SojitraGirdhar Sojitra

        5323 silver badges13 bronze badges




        5323 silver badges13 bronze badges



















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55377282%2fsend-message-to-specific-go-routine-based-on-key%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현