English 中文(简体)
数据库的多读
原标题:multithreading with database

我正在研究一项战略,利用多读(可能是偶然的代表们)开展同步行动。 我是新到的,这样一来将首先概述我的设想。 如今,根据所提供的参数对一组数据(组合)进行了同步操作。 下面(简称代码)实施:

public DataSet DoTests(int fundId, DateTime portfolioDate)
{
    // Get test results for the portfolio
    // Call the database adapter method, which in turn is a stored procedure,
    // which in turns runs a series of "rule" stored procs and fills a local temp table and returns it back.
    DataSet resultsDataSet = GetTestResults(fundId, portfolioDate);

    try 
    {

        // Do some local processing on the results
        DoSomeProcessing(resultsDataSet);

        // Save the results in Test, TestResults and TestAllocations tables in a transaction.

        // Sets a global transaction which is provided to all the adapter methods called below
        // It is defined in the Base class
        StartTransaction("TestTransaction");    

        // Save Test and get a testId
        int testId = UpdateTest(resultsDataSet);    // Adapter method, uses the same transaction

        // Update testId in the other tables in the dataset
        UpdateTestId(resultsDataSet, testId);

        // Update TestResults
        UpdateTestResults(resultsDataSet);          // Adapter method, uses the same transaction

        // Update TestAllocations
        UpdateTestAllocations(resultsDataSet);      // Adapter method, uses the same transaction

        // It is defined in the base class
        CommitTransaction("TestTransaction");
    }
    catch
    {
        RollbackTransaction("TestTransaction");
    }
        return resultsDataSet;
}

现在,需要的是提供多套数据。 一种办法是将上述<代码>()方法称作一种格式并获取数据。 我倾向于同时这样做。 但有一些渔获:

  • StartTransaction() method creates a connection (and transaction) every time it is called.
  • All the underlying database tables, procedures are the same for each call of DoTests(). (obviously).

因此,我的问题是:

  • Will using multithreading anyway improve performance?
  • What are the chances of deadlock especially when new TestId s are being created and the Tests, TestResults and TestAllocations are being saved? How can these deadlocked be handled?
  • Is there any other more efficient way of doing the above operation apart from looping over the DoTests() method repeatedly?
问题回答

Hopefully I completely understand what you mean. 1. Yes if you call DoTests several times on different threads your code performance will be better. Assuming you don t get locked inside your GetTestResults and UpdateXXX methods. 2. This basically depends on your implementation of methods you call ( GetTestResults and UpdateXXX methods) 3. You were going to call several DoTests simultaneously, correct? So why do you ask about plain looping?

实际上,我没有完全了解交易。 我的理解是,你会利用自己的交易,纠正吗? 否则,我认为你会遇到一系列交易更新问题。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签