I. BACKGROUND
Customer feedback randomly upload small files to the Cos speed is slow, using Python to test upload speed.
Second, the Code
#!/bin/env python#-*-coding:utf-8-*-# _auth:kaliarch# use cos-python-sdk-v5# https://cloud.tencent.com/document/ Product/436/12269from qcloud_cos Import cosconfigfrom qcloud_cos import coss3clientimport randomimport stringimport datetimesecret_id = ' Akidmdjegcmogyiolxxxxxxxxxxxxxxxxde ' # replaced with the user's Secretidsecret_key = ' d5mrl4voxyxxxxxxxxxxxa2lnq7d ' # replaced with the user's secretkeyregion = ' Ap-chengdu ' # replaced with the user's region # Use temporary key to pass in Token, default is empty, can not fill scheme = ' HT TPS ' # Specifies to use the HTTP/HTTPS protocol to access the COS, which is https by default, Bucket_name = ' xuel-test-bucket-1253961596 ' #制定bucket地址con Fig = Cosconfig (region=region, secret_id=secret_id, Secret_key=secret_key, Scheme=scheme) # 2. Get Client Object clients = Coss3client (config) def get_data_list (number): "" "gets a random string, numbers specifies the quantity:p Aram #:: Return: "" For I in range (int (number)): Random_str = '. Join (Random.sample (string.ascii_letters + string.digits, 12)) Yield Str (i) + random_strdef Get_func_time (func): "" " Adorner function:p aram func: Calculate inner function Execution time: return: "" "Def Inter_func (*args): Stime = Datetime.datetime.now () Print (' Start datetime: ', Stime) func (*args) etime = Datetime.datetime.now () print (' Start Dateti Me: ', etime) print (' Duration time ', etime-stime) return inter_func@get_func_timedef Upload_cos (number=1000): "" "Cos file upload:p Aram Number:: Return:" "" Print (' data file Number: ', str (number)) for content in Get_dat A_list (number): Response = Client.put_object (Bucket=bucket_name, Body=bytes (content,encoding = ' Utf-8 '), key=content,) if __name__ = = ' __main__ ': Upload_cos (1000)
Third, testing
Test 500 random files
Test 1000 random files
View Cos file data
Simple cos File upload test