-2
下面是我的一点点重构(+一些额外的代码,因为out-parameters)简单的方法,我尝试使用Parallel.Invoke(...)更快地完成任务。c#Parallel.Invoke(零速度改进)
(请忽略async word内部变量:))。
同步版本是相同的 - 同步调用相同的7个方法。
所有这7种方法都很简单 - 它们只是填充和返回集合。
现在 - 我发现惊人的是这样的:都方法执行几乎相同时间(〜6秒)。
这怎么可能或我错过了什么?
private static void GenerateCachingHelpersAsync(
SingleVODCache _svc,
Dictionary<int, DataRow> _dicFirstContentsFilter,
DataSet _ds,
out ConcurrentDictionary<string, DataRow> _cdicValidContentCatalogPrices,
out ConcurrentDictionary<int, DataRow> _cdicAllMetaDataHelper,
out List<KeyValuePair<int, int>> _helperContentMetaDataSync,
out ConcurrentDictionary<int, DataRow> _cdicAllAssetsHelper,
out List<KeyValuePair<int, int>> _helperContentAssetsSync,
out Dictionary<int, OneContentAllViewsHelper> _dicAllContentsViewsHelper,
out ConcurrentDictionary<int, List<Category>> _cdicValidContentCategories
)
{
ConcurrentDictionary<string, DataRow> _cdicValidContentCatalogPricesAsync = new ConcurrentDictionary<string, DataRow>();
ConcurrentDictionary<int, DataRow> _cdicAllMetaDataHelperAsync = new ConcurrentDictionary<int, DataRow>();
List<KeyValuePair<int, int>> _helperContentMetaDataSyncAsync = new List<KeyValuePair<int, int>>();
ConcurrentDictionary<int, DataRow> _cdicAllAssetsHelperAsync = new ConcurrentDictionary<int, DataRow>();
List<KeyValuePair<int, int>> _helperContentAssetsSyncAsync = new List<KeyValuePair<int, int>>();
Dictionary<int, OneContentAllViewsHelper> _dicAllContentsViewsHelperAsync = new Dictionary<int, OneContentAllViewsHelper>();
ConcurrentDictionary<int, List<Category>> _cdicValidContentCategoriesAsync = new ConcurrentDictionary<int, List<Category>>();
Parallel.Invoke(
() =>
{
_cdicValidContentCatalogPricesAsync = BuildValidContentCatalogPricesHelper(_ds.Tables[GetCMSDataTableIndex(m_eCMSDataTablesIndexes.CONTENT_CATALOG_PRICE_SYNC)]);
},
() =>
{
_cdicAllMetaDataHelperAsync = BuildAllMetaDataHelper(_ds.Tables[GetCMSDataTableIndex(m_eCMSDataTablesIndexes.META_DATA)]);
},
() =>
{
_helperContentMetaDataSyncAsync = BuildContentMetaDataSyncHelper(_ds.Tables[GetCMSDataTableIndex(m_eCMSDataTablesIndexes.CONTENT_META_DATA_SYNC)]);
},
() =>
{
_cdicAllAssetsHelperAsync = BuildAllAssetsHelper(_ds.Tables[GetCMSDataTableIndex(m_eCMSDataTablesIndexes.ASSETS)]);
},
() =>
{
_helperContentAssetsSyncAsync = BuildContentAssetsSyncHelper(_ds.Tables[GetCMSDataTableIndex(m_eCMSDataTablesIndexes.CONTENT_ASSET_SYNC)]);
},
() =>
{
_dicAllContentsViewsHelperAsync = BuildAllContensViewsVotesHelper(_ds.Tables[GetCMSDataTableIndex(m_eCMSDataTablesIndexes.CONTENT_VIEWS)], _dicFirstContentsFilter, _svc.MetaData.HowManyPastDaysForMostViewed);
},
() =>
{
_cdicValidContentCategoriesAsync = BuildValidContentCategoriesHelper(_ds.Tables[GetCMSDataTableIndex(m_eCMSDataTablesIndexes.CONTENT_CATEGORY_SYNC)], _dicFirstContentsFilter, _svc.AllCategories);
}
);
_cdicValidContentCatalogPrices = _cdicValidContentCatalogPricesAsync;
_cdicAllMetaDataHelper = _cdicAllMetaDataHelperAsync;
_helperContentMetaDataSync = _helperContentMetaDataSyncAsync;
_cdicAllAssetsHelper = _cdicAllAssetsHelperAsync;
_helperContentAssetsSync = _helperContentAssetsSyncAsync;
_dicAllContentsViewsHelper = _dicAllContentsViewsHelperAsync;
_cdicValidContentCategories = _cdicValidContentCategoriesAsync;
}
您的计算是否受CPU限制。 I/O绑定或内存绑定? – matcheek
CPU /内存绑定。没有I/O操作。 – sabiland