FileInput should have own limiter algorithm

This commit is contained in:
Leonid Bugaev
2014-10-26 15:00:00 +03:00
parent aae57733a8
commit f2cf81c5bf
3 changed files with 28 additions and 6 deletions
+12 -2
View File
@@ -36,10 +36,20 @@ func NewLimiter(plugin interface{}, options string) io.ReadWriter {
l.plugin = plugin
l.currentTime = time.Now().UnixNano()
// FileInput have its own rate limiting. Unlike other inputs we not just dropping requests, we can slow down or speed up request emittion.
if fi, ok := l.plugin.(*FileInput); ok && l.isPercent {
fi.speedFactor = float64(l.limit) / float64(100)
}
return l
}
func (l *Limiter) isLimited() bool {
// File input have its own limiting algorithm
if _, ok := l.plugin.(*FileInput); ok {
return false
}
if l.isPercent {
return l.limit <= rand.Intn(100)
}
@@ -71,9 +81,9 @@ func (l *Limiter) Write(data []byte) (n int, err error) {
func (l *Limiter) Read(data []byte) (n int, err error) {
n, err = l.plugin.(io.Reader).Read(data)
if l.isLimited() {
if l.isLimited() {
return 0, nil
}
}
return
}