<commit_before>// Accounting and limiting reader

package fs

import (
	"bytes"
	"fmt"
	"io"
	"sort"
	"strings"
	"sync"
	"time"

	"github.com/VividCortex/ewma"
	"github.com/tsenart/tb"
)

// Globals
var (
	Stats           = NewStats()
	tokenBucketMu   sync.Mutex // protects the token bucket variables
	tokenBucket     *tb.Bucket
	prevTokenBucket = tokenBucket
	currLimitMu     sync.Mutex // protects changes to the timeslot
	currLimit       BwTimeSlot
)

// Start the token bucket if necessary
func startTokenBucket() {
	currLimitMu.Lock()
	currLimit := bwLimit.LimitAt(time.Now())
	currLimitMu.Unlock()

	if currLimit.bandwidth > 0 {
		tokenBucket = tb.NewBucket(int64(currLimit.bandwidth), 100*time.Millisecond)
		Log(nil, "Starting bandwidth limiter at %vBytes/s", &currLimit.bandwidth)

		// Start the SIGUSR2 signal handler to toggle bandwidth.
		// This function does nothing in windows systems.
		startSignalHandler()
	}
}

// startTokenTicker creates a ticker to update the bandwidth limiter every minute.
func startTokenTicker() {
	ticker := time.NewTicker(time.Minute)
	go func() {<commit_msg>Only start bandwidth ticker when necessary.<commit_after>// Accounting and limiting reader

package fs

import (
	"bytes"
	"fmt"
	"io"
	"sort"
	"strings"
	"sync"
	"time"

	"github.com/VividCortex/ewma"
	"github.com/tsenart/tb"
)

// Globals
var (
	Stats           = NewStats()
	tokenBucketMu   sync.Mutex // protects the token bucket variables
	tokenBucket     *tb.Bucket
	prevTokenBucket = tokenBucket
	currLimitMu     sync.Mutex // protects changes to the timeslot
	currLimit       BwTimeSlot
)

// Start the token bucket if necessary
func startTokenBucket() {
	currLimitMu.Lock()
	currLimit := bwLimit.LimitAt(time.Now())
	currLimitMu.Unlock()

	if currLimit.bandwidth > 0 {
		tokenBucket = tb.NewBucket(int64(currLimit.bandwidth), 100*time.Millisecond)
		Log(nil, "Starting bandwidth limiter at %vBytes/s", &currLimit.bandwidth)

		// Start the SIGUSR2 signal handler to toggle bandwidth.
		// This function does nothing in windows systems.
		startSignalHandler()
	}
}

// startTokenTicker creates a ticker to update the bandwidth limiter every minute.
func startTokenTicker() {
	// If the timetable has a single entry or was not specified, we don't need
	// a ticker to update the bandwidth.
	if len(bwLimit) <= 1 {
		return
	}

	ticker := time.NewTicker(time.Minute)
	go func() {
{'fraction_non_alphanumeric': 0.10129761406446212, 'fraction_numerical': 0.006278777731268313, 'mean_word_length': 3.760956175298805, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6091819', 'n_tokens_mistral': 822, 'n_tokens_neox': 780, 'n_words': 227}