-
Notifications
You must be signed in to change notification settings - Fork 272
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
feat(upload): Add transfer_speed for downloading and uploading files #1797
feat(upload): Add transfer_speed for downloading and uploading files #1797
Conversation
Package Changes Through aa7b4c3There are 7 changes which include upload with minor, upload-js with minor, sql-js with patch, clipboard-manager with patch, sql with patch, fs-js with patch, log-plugin with patch Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
Thanks for the PR! I think this is a pretty solid start. My 2 main issues here are
For 2) i think a better approach would again come down to the performance.now() suggestion in the issue (of course meaning an equivalent in rust). You don't really need to know how much data was sent in a whole second, knowing how much data was send in X miliseconds (or how long Y chunks took) should be enough. |
Yaa, let me try this |
yes, |
use std::time::Instant;
use std::collections::VecDeque;
fn main() {
let mut time_list: VecDeque<u128> = VecDeque::with_capacity(10);
let mut start_time = Instant::now();
while next_chunk() { // Assuming next_chunk() is defined elsewhere
let now = Instant::now();
let it_took = now.duration_since(start_time).as_millis();
start_time = now;
time_list.push_back(it_took);
if time_list.len() == 10 {
let avg_time: u128 = time_list.iter().sum::<u128>() / 10;
// Report the average time
send(avg_time); // Assuming send() is defined elsewhere
// Reset the time list
time_list.clear();
}
}
} Here is a rough pseudocode that I have in mind. I'm just suggesting it. |
…ing the download speed
e5f29da
to
3a7da7b
Compare
@FabianLars I've rewritten the logic for the transfer_speed payload field. I've created a new struct that decouples the Transfer Speed calculation from the download and upload function.
Existing issues
Feel free to suggest better naming |
Thank you! And sorry for the delay (i was out sick the whole last month) A few last small things and then we can merge this:
The |
@FabianLars Okay I am making these changes. Can you please clarify what is a changefile ? You have mentioned in the first point ... |
Check the .changes folder for examples. Don't sweat over it though, I can add this when I merge the pr :) |
2. Convert ProgressPayload fields to camel case 3. Added the transferSpeed field in the ProgressPayload type in typescript
@FabianLars I've made the changes. Works fine in my current downloader application made with tauri 💯 . 2024-11-05.01-05-36.mp4 |
Also, I also tried to do this same thing in the js side, with equivalent code: export class TransferStats {
accumulatedChunkLen: number; // Total length of chunks transferred in the current period
accumulatedTime: number; // Total time taken for the transfers in the current period (in ms)
transferSpeed: number; // Calculated transfer speed in bytes per second
startTime: number; // Time when the current period started (in ms)
granularity: number; // Time period (in milliseconds) over which the transfer speed is calculated
constructor(granularity: number) {
this.accumulatedChunkLen = 0;
this.accumulatedTime = 0;
this.transferSpeed = 0;
this.startTime = performance.now();
this.granularity = granularity;
}
// Records the transfer of a data chunk and updates the transfer speed if the granularity period has elapsed.
recordChunkTransfer(chunkLen: number): void {
const now = performance.now();
const timeElapsed = now - this.startTime;
this.accumulatedChunkLen += chunkLen;
this.accumulatedTime += timeElapsed;
// If the accumulated time exceeds the granularity, calculate the transfer speed.
if (this.accumulatedTime >= this.granularity) {
this.transferSpeed = Math.floor(
this.accumulatedChunkLen / (this.accumulatedTime / 1000)
); // bytes per second
this.accumulatedChunkLen = 0;
this.accumulatedTime = 0;
}
// Reset the start time for the next period.
this.startTime = now;
}
// Provides a default instance of TransferStats with a granularity of 500 milliseconds.
static default(): TransferStats {
return new TransferStats(500); // Default granularity is 500ms
}
} And it worked fine as expected, I think it's also important for us to know. This problem of transfer_speed could've been solved from the JS side also ... |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks again :)
closes #1784