Comments (4)
no plans to implement it in the near future, but would certainly be open for a discussion on how it might be designed.
from hystrix-go.
I was able to isolate those calls in another library just fine. It would be cool if this library had everything Hystrix provides. I was initially thinking to create an interface with IsCacheable()
and GroupKey()
and something like DoWork()
for the main callback and Fallback()
for the fallback function. DoWork()
would return an interface{}
and if IsCacheable()
is true
, it can be stored in an LRU cache. Next time DoWork()
is called, it would check the cache. GroupKey()
would be to wrap DoWork()
with AddRequest()
in the following:
type requestPool struct {
pendingRequests map[string][]chan interface{}
pendingRequestsLock sync.Mutex
}
// Groups requests in a queue and only call the callback of the first request.
// The result of that first request will be sent to the waiting requests.
func (r *requestPool) AddRequest(key string, callback func() interface{}) chan interface{} {
ch := make(chan interface{})
r.pendingRequestsLock.Lock()
r.pendingRequests[key] = append(r.pendingRequests[key], ch)
requestNumber := len(r.pendingRequests[key])
r.pendingRequestsLock.Unlock()
// Call callback if it's first request
if requestNumber == 1 {
go func() {
resp := callback()
r.sendResponse(key, resp)
}()
}
return ch
}
// Send response to all waiting requests in the same group
func (r *requestPool) sendResponse(key string, res interface{}) {
go func() {
r.pendingRequestsLock.Lock()
for _, ch := range r.pendingRequests[key] {
ch <- res
}
delete(r.pendingRequests, key)
r.pendingRequestsLock.Unlock()
}()
}
from hystrix-go.
avoiding the run/fallback functions returning an empty interface is done on purpose, and is why they make no attempt to handle responses. requiring users to constantly cast results to their expected type is not a good API. an early version of hystrix-go took this approach and was awful to use.
i'm open to adopting these features from java hystrix, but not at the expense of the usability of the library when trying to copy java's use of generics.
from hystrix-go.
closing this issue, but still open to ideas around collapsing commands and caching results
from hystrix-go.
Related Issues (20)
- Callback on Circuit State Change HOT 1
- Does the project have a maintainer? HOT 4
- How to update config an runtime? HOT 1
- function trap
- can this package update to go mod?
- A little confusion of Lock
- A few questions...
- High memory usage issues
- can hystrix-go add config at runtime? hystrix.ConfigureCommand HOT 1
- Get the original error? HOT 1
- circuit may open even though ErrorPercentThreshold is bigger than 100
- method executed within hystrix behaving weiredly
- Incorrect build instructions
- Prometheus support for metric collection HOT 1
- How to not set MaxConcurrentRequests?
- Provide context for runFunc which is cancelled during timeouts HOT 2
- Panic when Timeout if setup output variable in function
- metricExchange.Monitor and poolMetrics.Monitor goroutine leak
- I need name info in Update func Callback
- I find the hystrix has an erro, I use hystrix.Do method in my code, once the hystrix circuit is open, it will runs the runFunc and fallbackFunc forever. In my understanding, once the circuit is open, the code will run fallbackFunc unless the SleepWindow is open. I find another question is the code will lead to memory leak
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hystrix-go.