Support pubsub methodology in SSE requests#5
Support pubsub methodology in SSE requests#5gadisr wants to merge 22 commits intokinecosystem/masterfrom
Conversation
There was a problem hiding this comment.
use log fields for the "topic" field like in logrus. check usage throughout the codebase
There was a problem hiding this comment.
redundant line is redundant. use git add -p
There was a problem hiding this comment.
channel is a generic name. call this ssePumped or something more verbose
There was a problem hiding this comment.
comment is confusing:
- what do you mean by "get an if from requests"?
- what is "q topic"?
There was a problem hiding this comment.
does it make sense to use a switch {} block instead? or do you need to evaluate all conditions all every on call to this function?
There was a problem hiding this comment.
why do you have to create a new goroutine here? doesn't it just overcomplicate things?
There was a problem hiding this comment.
"Horizon" database instead of "History"
There was a problem hiding this comment.
will using this function work properly if there are multiple subscribers to the same topic?
There was a problem hiding this comment.
Fixed to use different pubsub implementation
There was a problem hiding this comment.
just make two select blocks instead of an infinitie for loop. the first blook will continue successfully if channel_a returns, and then just run the select again and succeed if 2 seconds pass.
There was a problem hiding this comment.
are you going to test specific functions along with testing the entire flow?
6e9c29b to
613a098
Compare
There was a problem hiding this comment.
is it ok for the switch to not catch any catch any condition?
There was a problem hiding this comment.
channel name doesn't convey any information beside its type, and makes it hard to follow your flow down the road. better give it a meaningful name like topicMessage or something
There was a problem hiding this comment.
- rephrasing and small typo fixes: putting result before the condition for better readability:
Subscribe this handler to the topic if the SSE request is related to a specific topic (tx_id, account_id, etc.).
This causes the request to only be triggered by this topic. Unsubscribe when done.
- Also, to which request are you referring on "request will be triggered" - HTTP or database query?
There was a problem hiding this comment.
why int32 --> int --> string instead of just straight to string?
There was a problem hiding this comment.
package name is already pubsub, no need to rename to pubsub again
There was a problem hiding this comment.
i don't understand this func doc. if it's from another file why not just import it?
There was a problem hiding this comment.
where is the New function coming from? from the . import? if so, can you not rely on the . import? confusing
There was a problem hiding this comment.
similar to comment in the test above, duplicate this test to another one that publishes more than one value
a4a9da5 to
0b51059
Compare
There was a problem hiding this comment.
need to check for if !ok first, otherwise this would crash the program. if !ok then action == null. Replace this condition with the one coming just after it.
There was a problem hiding this comment.
why are you doing this stahp this unnecessary diff noise
There was a problem hiding this comment.
also another one like this in the import section at the top of this file
There was a problem hiding this comment.
why not action.GetString(..) like all other implementations? there are other functions like this in this pr
There was a problem hiding this comment.
There is no value for ledger there, just "ledger" hardcoded itself
There was a problem hiding this comment.
There is no value in this action for specific ledger_id, so registration topic is a general change in the ledger.
There was a problem hiding this comment.
are you sure the arg here should be account_id? it's already used in func (action *DataShowAction) GetTopic()
There was a problem hiding this comment.
avoid calling GetString() twice:
func (action *EffectIndexAction) GetTopic() (res string) {
if res := action.GetString(...); res != "" {
return
}
if res := ...; res != "" { return } // repeat for other fields
return // res == ""There was a problem hiding this comment.
apply this to other functions in this pr
There was a problem hiding this comment.
spaghetti code: instead of doing a select inside a select, just have two select blocks one after the other. i already wrote this comment here somewhere look it up
There was a problem hiding this comment.
what are these magic address and kahuna?
There was a problem hiding this comment.
bug: if the time.After returns before subscription the wait at the bottom will hang indefinitely
968878d to
51dafea
Compare
Every connection subscribes only to related data and get notified on changes accordingly. This optimizes Horizon<->History DB throughput and make flow more effiecient.
… after data is written on DB.
Also changed sse channel from struct{} to interface{} to be easily used with pubsub solution.
Changed tests by pr and added undubscribe when each test is done
c8c631c to
5280130
Compare
In order to optimize horizon<->DB throughput, avoid running sse procedures if no change happen in ledger state.
…ecify number of db connections to use.
NOTE This only happens only healthy HTTP 2xx responses. This is a hacky solution that tries to solve the case where clients have an unwanted behavior: They already have an account open and just want to poll their account balance but retry too quickly, according to default retry value (a few seconds usually). This causes them to spam the server right after disconnecting the SSE stream. This change will cause them to receive the preamble over and over again on every SSE tick, practically turning it into a keepalive message. This would lower the reconnection amount and in turn (most importantly) the amount of queries sent to the Horizon database. This has a cost though - it keeps SSE connections alive and also causes "junk" keep alive traffic to be sent over and over again.
This reverts commit 34ea97e.
|
cleaning this up and closing in favor of #14 |
Every connection subscribes only to related data and get notified on changes accordingly.
This optimizes Horizon<->History DB throughput and make flow more effiecient.