Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bytes counter] when use EwmaSpeed ,speed and remain time calculate is wrong? #120

Closed
lixd opened this issue Jan 18, 2023 · 4 comments
Closed
Labels

Comments

@lixd
Copy link

lixd commented Jan 18, 2023

the bar like this:

1.89 GiB / 2.00 GiB 95 % [======================================================>---]  ] 0s8.06 GiB/s

time is 0s,speed is 8.06 GiB/s,but really speed is less than 600MiB/s

when use AverageSpeed,is ok,bar like this:

1.94 GiB / 2.00 GiB 97 % [=======================================================>--]  ] 548.14 MiB/s

and test bytes counter example ,is ok.

my code like this

        // create a tmp file to read
	file, err := os.Create("./tmp.txt")
	if err != nil {
		return
	}
	data := make([]byte, 1024*1024*1024*2)
	file.Write(data)
	file.Close()
	defer func() {
		os.Remove("./tmp.txt")
		os.Remove("./tmp2.txt")
	}()

	p := mpb.New(
		mpb.WithWidth(60),
		mpb.WithRefreshRate(180*time.Millisecond),
	)

	bar := p.New(0,
		mpb.BarStyle(),
		mpb.PrependDecorators(
			decor.CountersKibiByte("% .2f / % .2f"),
			decor.Percentage(decor.WCSyncSpace),
		),
		mpb.AppendDecorators(
			decor.Name(" ] "),
			decor.EwmaETA(decor.ET_STYLE_GO, 90),
			decor.EwmaSpeed(decor.UnitKiB, "% .2f", decor.DSyncSpace),
			//decor.AverageSpeed(decor.UnitKiB, "% .2f", decor.WCSyncWidth),
		),
	)

	// file to reader
	open, err := os.Open("./tmp.txt")
	if err != nil {
		panic(err)
	}
	stat, err := open.Stat()
	if err != nil {
		panic(err)
	}
	// set total as file size
	fmt.Println("size: ", stat.Size())
	bar.SetTotal(stat.Size(), false)

	// create proxy reader
	proxyReader := bar.ProxyReader(open)
	//defer proxyReader.Close()


	// copy from proxyReader, ignoring errors
	create, err := os.Create("./tmp2.txt")
	if err != nil {
		panic(err)
	}
	defer create.Close()

	n, _ := io.Copy(create, proxyReader)


	// triggering complete event now
	bar.SetTotal(-1, true)
@vbauerster
Copy link
Owner

vbauerster commented Jan 18, 2023

Please refer to documentation of ewma lib.

TLDR
You have to pick correct weight parameter. If you choose anything than 30, ewma lib will need to collect 10 samples before any result. In your code sample you've chosen 90 and got 0 result, which means there were less than 10 samples.

@lixd
Copy link
Author

lixd commented Jan 18, 2023

@vbauerster thanks for your replay,but why this example bytes counter example it ok, params in my code is same with this. what need i do to fix my code? help~

@vbauerster
Copy link
Owner

vbauerster commented Jan 18, 2023

use 0 as arg to ewma, that will default to implementation that doesn't require prerequisite samples.

if age == 0 {

@lixd
Copy link
Author

lixd commented Jan 19, 2023

Thanks,but unfortunately,i tried use 0 as arg to ewma,,but not work too.

@lixd lixd closed this as completed Jan 25, 2023
@vbauerster vbauerster added the ewma label Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants