Created
August 13, 2015 19:19
-
-
Save benneely/a56da24d4dbef5413060 to your computer and use it in GitHub Desktop.
SLO vs DLO using swiftclient in python script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Tue Aug 11 14:03:59 2015 | |
@author: nn31 | |
""" | |
import swiftclient | |
import swiftclient.service | |
from swiftclient.service import SwiftService | |
import time | |
import json | |
######################################################################### | |
#currently there is a disconnect between the client and the low level | |
#functions that we need access to so that we can test large objects, | |
#so we'll switch between the true client (i.e. swiftclient.client) and | |
#the CLI service backbone (i.e. swiftclient.service) | |
######################################################################### | |
#Global Options for swiftclient.service | |
#Learned about this connection method from: http://lists.openstack.org/pipermail/openstack/2015-July/013557.html | |
swiftclient.service._default_global_options['os_username'] = '' | |
swiftclient.service._default_global_options['os_password'] = '' | |
swiftclient.service._default_global_options['os_tenant_name'] = '' | |
swiftclient.service._default_global_options['os_auth_url'] = '' | |
swiftclient.service._default_global_options['os_service_type'] = '' | |
#using bash script to figure this out right now, need to find a python-based way to do this | |
swiftclient.service._default_global_options['os_auth_token'] = '' | |
swiftclient.service._default_global_options['os_storage_url'] = '' | |
#Using the global options create a connection object for serviceclient.client | |
swift_conn = swiftclient.Connection( | |
user=swiftclient.service._default_global_options['os_username'], | |
key=swiftclient.service._default_global_options['os_password'], | |
tenant_name=swiftclient.service._default_global_options['os_username'], | |
authurl=swiftclient.service._default_global_options['os_auth_url'], | |
) | |
#Parameters for this run: | |
containerName = 'cute-cats' | |
fileName = 'samp2.log' | |
segmentSize = '104857600' | |
fileSize = '4.3gb' | |
#Check to see what is available right now: | |
#swiftclient.service methods | |
#swiftclient.client methods | |
myinfo = swift_conn.get_account() | |
print json.dumps(myinfo,indent=4) | |
############################################################################ | |
#Check to see what is available right now: | |
#swiftclient.service methods not used for this, only swiftclient.client | |
############################################################################ | |
#swiftclient.client methods | |
#myinfo = swift_conn.get_account() | |
#print json.dumps(myinfo,indent=4) | |
#Look into a container | |
cont = swift_conn.get_container(containerName+'_dlo'+'_segments') | |
print json.dumps(cont[1],indent=4) | |
cont = swift_conn.get_container(containerName+'_dlo') | |
print json.dumps(cont[1],indent=4) | |
############################################################################ | |
# Dynamic Large Objects (DLO) UPLOAD | |
############################################################################ | |
#Start with a small file: 1.25MB, segment size ~1MB | |
#upload test | |
with SwiftService() as sw: | |
start_time = time.clock() | |
for r in sw.upload(container=containerName+"_dlo", | |
objects=[fileName], | |
options={'segment_size':segmentSize}): | |
print r['success'] | |
final_time_upload_dlo = (time.clock()-start_time) | |
############################################################################ | |
# Static Large Objects (SLO) UPLOAD | |
############################################################################ | |
#Start with a small file: 1.25MB, segment size ~1MB | |
#upload test | |
with SwiftService() as sw: | |
start_time = time.clock() | |
for r in sw.upload(container=containerName+"_slo", | |
objects=[fileName], | |
options={'segment_size':segmentSize,'use_slo':True}): | |
print r['success'] | |
final_time_upload_slo = (time.clock()-start_time) | |
############################################################################ | |
# Dynamic Large Objects (DLO) Download | |
############################################################################ | |
#retreive an object | |
start_time = time.clock() | |
obj_tuple = swift_conn.get_object(containerName+"_dlo", fileName) | |
with open(fileName+'dlo', 'wb') as my_hello: | |
my_hello.write(obj_tuple[1]) | |
final_time_download_dlo = (time.clock()-start_time) | |
############################################################################ | |
# Dynamic Large Objects (SLO) Download | |
############################################################################ | |
#retreive an object | |
start_time = time.clock() | |
obj_tuple = swift_conn.get_object(containerName+"_slo", fileName) | |
with open(fileName+'slo', 'wb') as my_hello: | |
my_hello.write(obj_tuple[1]) | |
final_time_download_slo = (time.clock()-start_time) | |
############################################################################ | |
# RESULTS | |
############################################################################ | |
with open('results'+fileSize+segmentSize+'.txt','wb') as out: | |
out.write('File Size= '+fileSize+'\n'+ | |
'Segment Size = '+segmentSize+'\n'+ | |
'*************************************\n'+ | |
'DLO Upload Time: '+repr(final_time_upload_dlo)+'\n'+ | |
'SLO Upload Time: '+repr(final_time_upload_slo)+'\n'+ | |
'DLO Download Time: '+repr(final_time_download_dlo)+'\n'+ | |
'SLO Download Time: '+repr(final_time_download_slo)+'\n') | |
############################################################################ | |
# Clean UP | |
############################################################################ | |
def delContainer(container__name): | |
cont = swift_conn.get_container(container__name) | |
for obj in range(len(cont[1])): | |
swift_conn.delete_object(container__name,cont[1][obj]["name"]) | |
swift_conn.delete_container(container__name) | |
delContainer(containerName+"_dlo") | |
delContainer(containerName+"_dlo"+'_segments') | |
delContainer(containerName+"_slo") | |
delContainer(containerName+"_slo"+'_segments') | |
swift_conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment