简体   繁体   中英

asp.net code executes very fast on development while very slow on production

I have the following code to build a large string. it runs well on my development pc, about taking 2 seconds to complete all tasks, but when I put them on production server, it will take 10-20 seconds depending on something unknown. The time is calculated from TimePoint1 to TimePoint2.

BTW: abstractTable.GetWordCountInList(listID) just contains one line: return 100;

All other functions on production server work ok, except for this one. Oracle DB server and Web Server are on the same machine, and the query returns about 5000 records. Product server's data is same as the development server.

public const string WordXMLItemTemplate = @"<S I=""{0}"" W=""{1}"" L=""{2}"" F=""0"" P=""0"" />";   

int totalCounter =0;
int wordCounter = 0;
int listID = 1;
OracleConnection wordLibConn = ConnectionManager.GetNewConnection();
wordLibConn.Open();
try
{
    OracleCommand comm = new OracleCommand();
    comm.Connection = wordLibConn;
    comm.CommandText = "Select WordID from WordTable Order By Lower(Word) ASC";
    OracleDataReader dataReader = comm.ExecuteReader();
    try
    {
        // TimePoint 1
        while (dataReader.Read())
        {
            totalCounter++;
            wordCounter++;
            wordXML = wordXML + string.Format(WordXMLItemTemplate, totalCounter, dataReader[0].ToString(), listID);
            if (wordCounter % abstractTable.GetWordCountInList(listID) == 0)
            {
                wordCounter = 0;
                listID++;
            }
        }
    }
    finally
    {
        dataReader.Close();
    }
}
finally
{
    wordLibConn.Close();
}
// TimePoint 2

I suffered from the problem for months, thanks a lot for any advice.

Create a list for yourself of the potential lines or code fragments which might cause this slowness. Measure all of them and take a look at the results of your measures. Hopefully you will find the exact place where the stalling is caused and you will be closer to the solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM