Я работаю над интеграцией приложения c ++ с хранилищем BLOB-объектов Azure.
Чтобы добиться этого, я реализовал класс-оболочку для API wastorage 4.0.
#include "stdafx.h"
#include "AzureStorage.h"
// Microsoft Azure Library Header Includes.
#include "was\storage_account.h"
#include "was\blob.h"
struct RadAzureData{
azure::storage::cloud_storage_account storage_account;
azure::storage::cloud_blob_client blob_client;
azure::storage::cloud_blob_container container;
};
RadAzureStorage::RadAzureStorage():
RadCloudStorageInterface(RAD_STORAGE_TYPE::AZURE_CLOUD)
{
}
RadAzureStorage::RadAzureStorage(std::string accountName1, std::string accountKey1, std::string containerName1) : RadCloudStorageInterface(RAD_STORAGE_TYPE::AZURE_CLOUD)
{
std::wstring accountNameWS(accountName1.begin(), accountName1.end());
std::wstring accountKeyWS(accountKey1.begin(), accountKey1.end());
std::wstring containerNameWS(containerName1.begin(), containerName1.end());
d = new RadAzureData();
accountName = accountNameWS;
accountKey = accountKeyWS;
containerName = containerNameWS;
std::wstring connStr1 = L"AccountName=" + accountName + L";AccountKey=" + accountKey + L";DefaultEndpointsProtocol=https";
d->storage_account = azure::storage::cloud_storage_account::parse(connStr1.c_str());
// Create a blob container
d->blob_client = d->storage_account.create_cloud_blob_client();
d->container = d->blob_client.get_container_reference(containerName.c_str());
CreateContainer();
}
bool RadAzureStorage::CreateContainer()
{
try
{
d->container.create_if_not_exists();
}
catch (const azure::storage::storage_exception& e)
{
cout<<"Exception in container creation: " << e.what()<<endl;
cout <<"The request that started at:" << e.result().start_time().to_string().c_str() << " and ended at " << e.result().end_time().to_string().c_str() << " resulted in HTTP status code " << e.result().http_status_code() << " and the request ID reported by the server was " << e.result().service_request_id().c_str()<<endl;
return false;
}
return true;
}
bool RadAzureStorage::UploadFile(std::string blockBlobName, std::string dicomFileLocation)
{
std::wstring blockBlobNameWS(blockBlobName.begin(), blockBlobName.end());
std::wstring dicomFileLocationWS(dicomFileLocation.begin(), dicomFileLocation.end());
// Create a Block Blob Object.
azure::storage::cloud_block_blob block_blob = d->container.get_block_blob_reference(blockBlobNameWS.c_str());
// Upload Block Blob to container.
try
{
block_blob.upload_from_file(dicomFileLocationWS.c_str());
}
catch (const azure::storage::storage_exception& e)
{
cout<< "Exception in file upload: " << e.what() << endl;
cout<< "The request that started at:" << e.result().start_time().to_string().c_str() << " and ended at " << e.result().end_time().to_string().c_str() << " resulted in HTTP status code " << e.result().http_status_code() << " and the request ID reported by the server was " << e.result().service_request_id().c_str() << endl;
return false;
}
return true;
}
#undef __FILENAME__
Из приложения создается экземпляр класса RadAzureStorage и вызывается API UploadFile.
RadAzureStorage* clsi = new RadAzureStorage(accountname, acesskey, containername);
<<timer.start>>
clsi->UploadFile(blockBlobName, file);
<<timer.end>>
cout << timer.ellapsedMilliSeconds<< "ms"<< endl;
UploadFile API занимает 14-16 мс для файлов размером от 190 до 250 КБ.
Существуют ли некоторые параметры при инициализации хранилища, которые можно изменить, чтобы добиться этого менее чем за 10 мс.
Текущая среда тестирования размещена в Azure South India:
1. ВМ: Windows server 2016, 4v Core, 16 ГБ ОЗУ.
2. Горячий уровень доступа, учетная запись хранения.
Обратите внимание: подобная логика реализована на C #, где загрузка для файла выполняется за 10 мс для того же набора данных.