I plan to write code to encrypt files in javascript locally. For large files and large key sizes, CPU usage is (naturally) quite large. In one script design, this often freezes the browser until the task is completed.
To improve responsiveness and allow users to do something else, I want to try to make the script βfriendlierβ on the user's PC. The encryption process will read the file as a binary string, and then encrypt the string in pieces (something like 1KB / chunk - needs to be tested). I want to try to make HTML5-based users do their best as incremental as possible. Something like:
- Spawn worker
- Send an employee a block of binary data
- Worker completes encryption, transfers a new fragment
- The worker is dying.
It can also help with multi-core processors, immediately, having several workers at once.
Anyway, did anyone look at the intentional slowdown of the script to reduce CPU usage? Something like dividing the task of working encryption into separate operations and introducing a delay between them.
Timer interval callback every 100 ms (example).
Is the worker busy?
Yes - Wait another interval
No - Run next letter encryption
Advice / thoughts?
Does anyone have experience using workers? If you separate the main user interface from the intensification of work, making it work, does the reaction increase?
javascript cpu-usage
Oliver Jul 27 '11 at 15:08 2011-07-27 15:08
source share