下载没看上去这么简单

下载没看上去这么简单 动机 如今,我们实际上并不关心网络下载的内部结构或细节。大多数情况下,我们单击浏览器上的链接并等待进度条完成。 如果我们觉得下载时间太长,通常是以太网速度受到指责。但是,我们从未想过该进度条下方使用的协议。即使对于实际需要实现某种下载代码的程序员,每种语言也总是有高级库。需要HTTPS吗?在您的 URL 前添加 https://,想要多个连接?轻触那个开关,库会为你做所有肮脏的工作。 好吧,直到最近,我也是这些人中的一员。在工作中,我们需要为一个大项目下载数百个依赖项。由于开发速度很快,每个人每天至少需要更新一次。由于依赖项的数量庞大且每个项的发布频率很高,同事抱怨公司聊天室的更新时间过长并不是一个不寻常的景象。我应该调查为什么它需要这么长时间并尝试优化。 现在我们不想更换基础设施,所以如果有的话,所有的优化都会发生在软件方面。使用的下载模式为HTTPS+并行下载。所以通常情况下,我对下载模型性能的不同组合进行了一些测试,我将在下面尝试重新创建。 TCP/IP 模型有四层:链路层、互联网层、传输层和应用层。但是由于我们不希望对基础架构进行任何更改,因此三个低级别层不在考虑范围中。对于应用层,我们可以控制 SSL 和并行/串行下载。 测试环境搭建 对于服务器,我使用我的一台笔记本电脑和 Apache 网络服务器。 首先,我们需要为我们的服务器启用 https。 通常情况下,ssl 证书的价格为数百美元。 但是为了测试,我们将使用自定义的 openssl。 笔记本电脑安装的ArchLinux自带了 openssl。 要生成证书,请运行 openssl req -new -x509 -nodes -out /srv/http/ssl.crt -keyout /srv/http/ssl.key -days 365 是的,我们将密钥和证书都存储在服务器根目录中,但这不是生产环境,只是为了测试。 之后我们将会删除这个目录。 在/etc/httpd/conf/httpd.conf里取消注释这些行之后: LoadModule ssl_module modules/mod_ssl.so LoadModule socache_shmcb_module modules/mod_socache_shmcb.so Include conf/extra/httpd-ssl.conf 在/etc/httpd/conf/extra/httpd-ssl.conf里增加 SSLCertificateFile和SSLCertificateKeyFile的配置, 服务器就已经准备好相应HTTPS和HTTP的请求了。 对于相关的测试文件,我们将使用一些生成的文件。 为了生成这些文件,我编写了这个方便的脚本: #!/bin/bash for ((i=0; i<=$3; i++)) do dd if=/dev/zero of=$1$i.img bs=1024 count=0 seek=$2 done ./dd_create.sh large 10000 100 将会生成100个大小为10000KB的文件,命名为: large1.img, large2.img … 在我运行 ./dd_create.sh small 1 100 和 ./dd_create.sh large 10000 100 后我就有了100个1KB和100个9.8MB的文件,我们可以开始测试了! ...

August 28, 2021

在ArchLinux上使用Btrfs硬盘矩阵

在ArchLinux上使用Btrfs硬盘矩阵 前言 几年来,越来越多的东西占据了我的硬盘空间。 视频,烧录的音乐,离线的ArchLinux镜像源… 只是其中的一小部分。我之前的储存方案是一块128GB的SSD做系统盘,1TB的机械硬盘做储存盘。不过因为那块机械硬盘时间有点久了,感到不是很安全。我加了一块1TB的移动硬盘,和之前的那块组成RAID1的硬盘矩阵。 不久之后,1TB 对我来说已经不够用了。 由于缺少合适的硬盘,我将 2 TB便携式USB硬盘连接到计算机。 并将所有可重新下载的数据移动过去。 游戏、Linux 镜像……就这样使用了3年。 现在,剩下的空间再次处于危险的程度。 留给我的唯一选择是将最少使用的数据传输到我的两台笔记本电脑,每台笔记本电脑都有 500 GB 的空间。 但这显得很不方便和尴尬。 此外,我的家人没有 NAS 或云存储解决方案。 所以是时候进行适当的 Raid 构建了,来存储我自己的所有东西和家庭视频。 基本上把我的电脑变成 NAS。 硬盘 虽然很多人选择像 redwolf 这样的企业级硬盘,我选择了普通的希捷硬盘。 专业 NAS 硬盘的主要优势是高工作负载容量和持久性。 但是,就我而言,我不需要这些。 大部分数据大部分是静态的,没有太多负载。 而对于寿命问题,根据我之前的经验,普通的硬盘就可以了。 此外,我将使用 Raid 10,这意味着我可以在 4 个 HDD 阵列中承受 2 次故障。 最后我选了四个 4TB 的,这将给我在 Raid 10 下的 8TB 存储。 安装 安装本身很简单,拿一把螺丝刀和一些电源线,就装成了。 但是有一个意外的延迟。 我虽然已经检查过我有足够的板载 sata 端口和电源插槽,但是忘了检查机箱是否有足够的槽地方装硬盘。 装了一张盘后,发现硬盘仓用完了! 幸运的是,机箱确实有两个未使用的 CD 驱动器托架,所以我在网上订购了其中一个扩展仓。 带有三个驱动器托架和一个前置风扇,此扩展箱可装入两个 CD 驱动器托架。 我的电脑机箱只有两个驱动器托架,加上这三个,我的硬盘空间刚好够用(4 个新的和 1 个旧的)。 ...

August 22, 2021

Delete the QQmlApplicationEngine?

How I tried to delete QQmlApplicationEngine for less memory usage Qml Qml manages to separate UI and backend logic, one can adjust c++ code without breaking UI, or develop different front end without implementing same logic twice. As plasma mobile developers, we can utilize the flexibility of Qml and Kirigami framework. Making apps that look equally beautiful on mobile and desktop platform. However, the high memory usage is its major drawback. On a device like pinephone which only has 2 Gigs of ram, low memory consumption is crucial. ...

August 31, 2020

Plasmoid with C++

Plasmoid with C++ the screenshot is at the end of this post I’m developing a Plasmoid for Plasma Mobile. Called KClock-Plasmoid, as its name suggests, it’s a plasmoid for KClock. The goal is to display time, next alarm and stay at system top panel to indicate KClock is running in background. KClock side So the goal is pretty simple, and all I have to do is to find a way to share information from KClock to the plasmoid. However the solution isn’t that trivia. As it turned out, DBus is perferred for IPC(Inter-process communication). Before start working on plasmoid, I need to expose some of the class of KClock to DBus first. Since KClock is built upon Qt, I choose to using Q-DBus as it will save a lot of effort than using low level interface. Now the problem is - I don’t know how to use Q-DBus. As usual, I went to the Qt documentation and to my surprise, it spent most content to describe the concept of DBus and compared to Qt’s signal/slot machinism. Although useful as it is, lack of examples meaning I still didn’t know how I can use it in my code. Thankfully, KDE has its own tutorial about DBus and it provides multiple examples. You can find it here. ...

August 12, 2020