Skip to content

Stream background job results to MPSC channel not ending #266

Answered by PainOchoco
PainOchoco asked this question in Q&A
Discussion options

You must be logged in to vote

What I've finally done is create a global hashmap that links job ids to senders.

When a client makes a request, the server :

  • Creates a MPSC channel (tx, rx)

  • Creates a Job

  • Add tx to the global hashmap with the job id

  • Add job to storage

  • Workers receives the job

  • Get the tx sender from the global hashmap and clone it

  • Work on the job and send the results with the cloned tx

It seems to work pretty well, tho i've not tested it at big scale, I wonder if the hashmap mutex will bottleneck when trying to lock it in multiple threads at the same time.

Replies: 7 comments 17 replies

Comment options

You must be logged in to vote
8 replies
@PainOchoco
Comment options

@PainOchoco
Comment options

@geofmureithi
Comment options

@PainOchoco
Comment options

@geofmureithi
Comment options

Comment options

You must be logged in to vote
2 replies
@PainOchoco
Comment options

@geofmureithi
Comment options

Comment options

You must be logged in to vote
1 reply
@PainOchoco
Comment options

Comment options

You must be logged in to vote
1 reply
@PainOchoco
Comment options

Comment options

You must be logged in to vote
1 reply
@PainOchoco
Comment options

Comment options

You must be logged in to vote
3 replies
@geofmureithi
Comment options

@PainOchoco
Comment options

Answer selected by PainOchoco
@PainOchoco
Comment options

Comment options

You must be logged in to vote
1 reply
@PainOchoco
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants