Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Super slow uploads (10x time) on 1% packet loss connection #3471

Open
yspreen opened this issue Jun 26, 2021 · 1 comment
Open

Super slow uploads (10x time) on 1% packet loss connection #3471

yspreen opened this issue Jun 26, 2021 · 1 comment
Assignees

Comments

@yspreen
Copy link

yspreen commented Jun 26, 2021

I'm running two different network connections. One is over WIFI with 25MBit/s upload at 1% packet loss. One is over mobile with 24MBit/s upload at 0% packet loss. The first connection takes 10x as long to upload files to a Django server, while the mobile connection is a lot faster. This app is the only place where I'm experiencing slowdowns. I use this connection every day for everything else. As far as I can tell, Alamofire is the only part of the chain that could cause these slowdowns.

Alamofire Environment

Alamofire Version: 5.4.3
Dependency Manager: SPM
Xcode Version: 12.5.1
Swift Version: 5
Platform(s) Running Alamofire: iOS 14.6
macOS Version Running Xcode: 11.4

Demo Project

ℹ Please link to or upload a project we can download that reproduces the issue.

  public static func uploadVideo(
    from url: URL, progress: ((Double) -> Void)? = nil, completion: ((String?) -> Void)?
  ) -> UploadRequest {
    let ext = url.absoluteString.split(separator: ".").last ?? ".binary"
    return AF.upload(multipartFormData: {
      $0.append(url, withName: "video", fileName: "video.\(ext)", mimeType: "application/octet-stream")
    }, to: "\(server)file_upload/")
    .uploadProgress {
      progress?($0.fractionCompleted)
    }
    .response {
      let data = $0.data ?? Data()
      let string = String(data: data, encoding: .utf8) ?? ""
      let json = JSON(parseJSON: string)
      completion?(json["url"].array?.compactMap { $0.string }.first)
    }
  }
@jshier
Copy link
Contributor

jshier commented Jun 26, 2021

Alamofire is built on top of URLSession and so isn't responsible for any of its own networking. Uploads are handled by URLSession and the raw network connection, as well as the logic dealing with packet loss, are at an even lower level. So there's not much Alamofire can do to impact, or fix, raw network speed. I suggest you investigate further and try to find the bottleneck in your upload operation. One thing to investigate is whether moving away from multipart form uploads and directly uploading the file would improve performance.

@jshier jshier self-assigned this Jun 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants