node.js - 求问nw.js开发桌面版,其js计算性能如何?
高洛峰
高洛峰 2017-04-17 14:51:41
0
3
841

1.现在我需要开发通用平台(mac,windows)的桌面程序,但是程序需要涉及到前端大文件(百兆左右)加密功能。我们知道node.js做计算密集型性能是很差的,那nw.js计算性能是否也很差?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
迷茫

I don’t know exactly how the computing performance is, and I’ve never done anything so awesome. But since you said nodejs is not suitable for processing computationally intensive tasks, then I think nw is the same. If you don’t believe me, take a look:

nw.jsIntegrated is nodejs

Peter_Zhu

You can try atom/vscode to open 100M files first. They are based on electron, the same as nw.
The bad news is that node can only load 1.4G files at a time. The good news is that node modules can be written in C/C++.
I don’t know much about the underlying things, so I can only provide this information.

迷茫

As long as each function is designed to be executed separately, I think there should be no problem.
For example, I start a single-process HTTP server locally and then call the system browser to access it.
php -S 127.0.0.1:8080 -t /www
Server and Client are developed separately. Even if the Server is stuck, the JS in the Client can still run.
For encrypted files of about 100MB, the Server and Client must not be stuck.
You can consider this at this time The local server side proc_open asynchronously opens a process to perform time-consuming encryption operations.
The browser side uses JS to poll at 10-second intervals to learn the task progress.
I have not used NW.js, but the idea is similar.

I used PHP7’s mcrypt_blowfish to encrypt and decrypt 10MB data on Ubuntu (i5-3230), which took less than 0.2 seconds and occupied about 40MB of memory.

<?php
header('Content-Type: text/plain;charset=utf-8');

// 加密数据 mcrypt_generic
// 解密数据 mdecrypt_generic
// http://php.net/manual/zh/function.mdecrypt-generic.php
// 加密描述符 $td
// 密钥 $key
// 初始向量 $iv

/* 数据 */
$key = 'a39d0d0e2e8c360205d105f9edcc51fdf5a780ce'; // sha1( uniqid(getmypid().'_'.mt_rand().'_', true) )
$plain_text = file_get_contents('/home/eechen/note/file.txt');

/* 打开加密模块,并且创建初始向量 */
//打开算法和模式对应的模块,成功则返回加密描述符(资源类型),发生错误则返回FALSE.
//算法类型MCRYPT_BLOWFISH,模式MCRYPT_MODE_ECB
$td = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_ECB, '');
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$starttime = microtime(true);
/* 初始化加密句柄 */
if (mcrypt_generic_init($td, $key, $iv) != -1) {

    /* 加密数据 */
    $c_t = mcrypt_generic($td, $plain_text);
    mcrypt_generic_deinit($td);
    // 密文是二进制数据
    //echo '密文: '.bin2hex($c_t)."\n";

    /* 为解密重新初始化缓冲区 */
    mcrypt_generic_init($td, $key, $iv);
    $p_t = mdecrypt_generic($td, $c_t);
    // 解密数据,请注意,由于存在数据补齐的情况,返回的字符串的长度可能和明文的长度不相等.
    //echo '明文: '.$p_t."\n";
    /* 执行清理工作 */
    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);
}
echo microtime(true) - $starttime."\n";
if (strncmp($p_t, $plain_text, strlen($plain_text)) == 0) {
    echo "OK\n";
} else {
    echo "Error\n";
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template