duan39779 2019-01-29 20:10
浏览 28

golang复制文件花费太多时间

I use the following code to copy files which works OK The problem is that when we use this method to copy folder and items like node_js project with node_modules inside in windows this can take a long time about 40 sec and in mac it takes 2 sec. when doing trace (print the copied files) we saw that for example the io.copy took 5 sec to copy short readme file or json file , in each run it get stuck on different files , small size files like json readme etch this is not consistent, in different run it stuck on different files ( if you run on same project).

we checked it on 3 different windows10 machine ( 1-3 years old) and 2 different macbook (3 years old) on exact same project. What it can be ?

func walk(src string, baseDir string, archive *zip.Writer) error {
   return filepath.Walk(src, func(path string, info os.FileInfo, err error) (e error) {
      if err != nil {
         return err
      }

      if info.IsDir() {
         return
      }

      header, err := zip.FileInfoHeader(info)
      if err != nil {
         return err
      }
      if baseDir != "" {
         header.Name = filepath.ToSlash(getRelativePath(path, baseDir))
      }

      header.Method = zip.Deflate
      writer, err := archive.CreateHeader(header)
      if err != nil {
         return err
      }

      file, err := os.Open(path)
      if err != nil {
         return err
      }
      defer func() {
         e = CloseFile(file, e)
      }()

      _, err = io.Copy(writer, file)
      return err
   })
}

we are checking it almost 4 days and we didnt find any pattern :(

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题