当前位置: 首页 > news >正文

百度网盘电脑版官网企业网站seo方案案例

百度网盘电脑版官网,企业网站seo方案案例,免费空间网址,广州手机建设网站1.开发背景 Linux 系统提供了各种外设的控制方式,其中包括文件的读写,存储文件的介质可以是 SSD 固态硬盘或者是 EMMC 等。 其中常用的写文件方式是同步写操作,但是如果是写大文件会对 CPU 造成比较大的负荷,采用异步写的方式比较…

1.开发背景

        Linux 系统提供了各种外设的控制方式,其中包括文件的读写,存储文件的介质可以是 SSD 固态硬盘或者是 EMMC 等。

        其中常用的写文件方式是同步写操作,但是如果是写大文件会对 CPU 造成比较大的负荷,采用异步写的方式比较合适,并且需要直接越过内核,直接通过 IO 访问,直接访问磁盘,关键词 O_DIRECT。可以有效降低 CPU 的使用率。

#ifdef __USE_GNU
# define O_DIRECT	__O_DIRECT	/* Direct disk access.  */
# define O_NOATIME	__O_NOATIME	/* Do not set atime.  */
# define O_PATH		__O_PATH	/* Resolve pathname but do not open file.  */
# define O_TMPFILE	__O_TMPFILE	/* Atomically create nameless file.  */
#endif

        添加宏定义,否者 O_DIRECT 显示未定义

#define _GNU_SOURCE

2.开发需求

设计实验:

        1)使用同步写硬盘的方式连续 100MB 的数据 10 次并统计每次写入的时间和速度

        2)使用异步写硬盘的方式连续 100MB 的数据 10 次并统计每次写入的时间和速度

3.开发环境

        ubuntu20.04 + RK3568 + Linux4.19.232 + 金士顿 SSD

4.实现步骤

4.1 实现代码

#define _GNU_SOURCE#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <linux/fs.h>
#include <sys/time.h>#include "com_file.h"
#include "app_log.h"#define BUFFER_SIZE (1024 * 1024 * 100) // 100MB
#define TEST_FILE_PATH "/run/media/sata/output.dat"/* 同步写测试 */
static void test_write_sync(char *file_path, char *buffer)
{/* 创建文件和路径 */common_file_create(file_path);/* 打开文件 */int fd = open(file_path, O_WRONLY | O_CREAT, 0644);if (fd < 0) {alog_error("open failed\r\n");return;}/* 写数据 */if (write(fd, buffer, BUFFER_SIZE) != BUFFER_SIZE) {alog_error("write failed\r\n");close(fd);return;}/* 关闭文件 */close(fd);
}/* 异步写测试 */
static void test_write_async(char *file_path, char *buffer)
{/* 创建文件和路径 */common_file_create(file_path);/* 打开文件 */int fd = open(file_path, O_WRONLY | O_CREAT | O_DIRECT, 0644);if (fd < 0) {alog_error("open failed\r\n");return;}/* 写数据 */if (write(fd, buffer, BUFFER_SIZE) != BUFFER_SIZE) {alog_error("write failed\r\n");close(fd);return;}/* 关闭文件 */close(fd);
}/* 主程序 */
int main()
{alog_info("%s start\r\n", __func__);char file_path[] = TEST_FILE_PATH;char *pdata_sync = NULL;char *pdata_async = NULL;/* 初始化同步内存 */pdata_sync = (char *)malloc(BUFFER_SIZE);if (pdata_sync == NULL){alog_error("malloc failed\r\n");return 1;}alog_info("sync memory init ok\r\n");/* 初始化异步内存 */if (posix_memalign((void **)&pdata_async, 512, BUFFER_SIZE) != 0)    // 512 4096{alog_error("posix_memalign failed\r\n");return 1;}alog_info("async memory init ok\r\n");/* 填充数据 */for (long long int i = 0; i < BUFFER_SIZE; i++){pdata_sync[i] = i & 0xFF;pdata_async[i] = i & 0xFF;}alog_info("data init ok\r\n");/* 计时*/struct timeval start_time;struct timeval end_time;/* 同步写测试 */for (int i = 0; i < 10; i++){gettimeofday(&start_time, NULL);test_write_sync(file_path, pdata_sync);gettimeofday(&end_time, NULL);int usec_sync = (end_time.tv_sec - start_time.tv_sec) * 1000000 + (end_time.tv_usec - start_time.tv_usec);double speed_sync = (double)BUFFER_SIZE / ((double)usec_sync / 1000 / 1000);alog_info("sync[%d] write test time: %d ms, speed: %lf MB/s\r\n", i, usec_sync / 1000, speed_sync / (1024 * 1024));}/* 异步写测试 */for (int i = 0; i < 10; i++){gettimeofday(&start_time, NULL);test_write_async(file_path, pdata_async);gettimeofday(&end_time, NULL);int usec_async = (end_time.tv_sec - start_time.tv_sec) * 1000000 + (end_time.tv_usec - start_time.tv_usec);double speed_async = (double)BUFFER_SIZE / ((double)usec_async / 1000 / 1000);alog_info("async[%d] write test time: %d ms, speed: %lf MB/s\r\n", i, usec_async / 1000, speed_async / (1024 * 1024));}/* 释放内存 */free(pdata_sync);free(pdata_async);return 0;
}

4.2 测试结果

        异步写硬盘速度更快,并且 CPU 占用更低,只有不到 20%,同步写硬盘 CPU 占用超过 90%

http://www.yayakq.cn/news/497106/

相关文章:

  • 阳朔网站建设公司家具网站开发报告
  • 陕西网站建设报价wordpress 一栏
  • 容桂网站制作值得信赖做网站的销售团队
  • 做网站排名收益无锡网站制作计划
  • 建网站内容网页设计素材 旅游
  • 网站的基础知识学做饼干网站
  • 嘉兴优化网站公司哪家好seo的内容有哪些
  • 广州做企业网站哪家好电子商务和网络购物网站
  • 一个公司可以有两个网站吗字母logo设计生成器
  • 有没有做.net面试题的网站一个企业网站文章多少适合
  • 做财经类新闻的网站长春有微信网站一起整的吗
  • 文具网站建设策划书浙江公司响应式网站建设推荐
  • 无锡建网站网站备案的要求是什么情况
  • 那个企业建网站好管理平台
  • 搭建本地网站嵊州网站建设
  • 取消网站备案制度现在公司一般用什么邮箱
  • 推广网站的图片怎么做哪个网站建设公司比较好
  • 医院招聘网站建设和维护人员成功的网站设计
  • 企业型网站中的文章更新是指什么做微商有卖鞋子的网站吗
  • 旅游网站的设计与实现开题报告有什么网站做生鲜配送的
  • 网站开发环境包括什么网站建设有哪些常用行为
  • 重庆百度网站排名如何做exo网站
  • 江西个人网站备案wordpress打开速度太慢
  • 有没有专门做美食的网站wordpress升级超时
  • 通付盾 网站建设青锐成长计划网站开发过程
  • 表白网站在线制作软件珠珠宝宝网网站站建建设设
  • 网站建设的意义与价值深圳网站建设服务清单
  • 做一个商务平台网站的费用修改wordpress语言设置
  • 网站建设进度汇报厦门在建工程项目
  • 宿迁网站建设宿迁淮南seo