Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the implementation principle of oss-android and ios-sdk multithreading?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the oss-android and ios-sdk multithreading implementation principle is what the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this oss-android and ios-sdk multithreading principle of what the article will have a harvest, let's take a look at it.

Realization principle

strategy

Oss has the feature of multipart upload. Ali Cloud breakpoint continuation is encapsulated based on several api interfaces of multipart upload, which is mainly composed of InitiateMultipartUpload,UploadPart,CompleteMultipartUpload,AbortMultipartUpload,ListParts.

Details

Resuming upload from breakpoint is a big task, which is completed in three parts, namely, obtaining uploadId, uploading multipart and completing upload. This whole continuous step is carried out in one thread.

To obtain the uploadId, you need to obtain the local cache file first. If you do not get it, you will directly generate a new uploadId and upload it directly. Otherwise, you will restore how many pieces of the recorded id were uploaded before the upload, and continue uploading in the original location.

For multipart upload, multithread concurrent upload mechanism is adopted. At present, the maximum number of threads opened is 5, which is judged according to the core number of cpu.

Ios:

/ / obtain UploadId for upload. If the task fails and the upload can be resumed, the same UploadId can be used to upload the same file to the storage object on the same OSS OSSResumableUploadRequest * resumableUpload = [OSSResumableUploadRequest new]; resumableUpload.bucketName =; resumableUpload.objectKey =; resumableUpload.partSize = 1024 * 1024 int64_t bytesSent Upload.uploadProgress = ^ (int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {NSLog (@ "% lld,% lld,% lld", bytesSent, totalByteSent, totalBytesExpectedToSend);} ResumableUpload.uploadingFileURL = [NSURL fileURLWithPath:]; NSString * cachesDir = [NSSearchPathForDirectoriesInDomains (NSCachesDirectory, NSUserDomainMask, YES) firstObject]; resumableUpload.recordDirectoryPath = cachesDir;// record breakpoint file path OSSTask * resumeTask = [client resumableUpload:resumableUpload]; [resumeTask continueWithBlock: ^ id (OSSTask * task) {if (task.error) {NSLog (@ "error:% @", task.error) If ([task.error.domain isEqualToString:OSSClientErrorDomain] & & task.error.code = = OSSClientErrorCodeCannotResumeUpload) {/ / this task cannot be resumed. You need to obtain a new uploadId to re-upload}} else {NSLog (@ "Upload file success");} return nil;}]

Performance statistics

Data analysis

Compared with the previous test after the multipart upload on android/ios is changed to concurrency, the network request speed of multithreading is the same as that of single thread, which mainly depends on the bandwidth speed. Compared with single thread, multithreading mainly improves the io time of reading files. The data are as follows:

IOS simulator tests 100mb size file 1000 part num single thread 104.530217s multi-thread 54.528591s100 part num single thread 59.306880s multi-thread 54.336914s1.31g size file 100part num single thread 746.775666s multi-thread 731.940330s1000 part num single thread 822.866331s multi-thread 733.306236s2000 part num single thread 965.428122s single thread 731.940330s5000 part num 1205.379382s Multithreaded 732.982330sandroid motoXT1085 dual core cpu100mb files 100 part num single threaded 70.484s multithreaded 53.656s1000 part num single threaded 104.530217s multithreaded 54.528591s1.31g video files 135 part num single threaded 869s multithreaded 738s1342 part num 1079.081s multithreaded 732.079s

Generally speaking, it is better than before. The time consuming of single thread is getting higher and higher with the increase of the number of pieces, while in multi-thread, the time is basically the same. According to the current default configuration of part size 256kb, both network resources and IThread O resources under single thread are full, and the average performance improvement under concurrency is about 30% (upload time is reduced).

This is the end of the article on "what is the principle of oss-android and ios-sdk multithreading?" Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "what is the principle of oss-android and ios-sdk multithreading". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report