我在我的web应用程序中运行了几个角色。他们通过它们之间的Azure存储队列消息进行通信。这意味着在角色抓住它并开始执行之后,Web角色会放置消息。Azure Worker执行长时间运行操作失败
主要是工作人员角色使用文件。它删除xlsx文件中的所有空行。 工作人员迭代每行中的所有行和单元格。所以如果行内的所有单元格都是空的,我会删除行
它适用于总行数少于100 000的文件,但我们的客户加载的文件中有1 100 000条记录(1 098 800个为空)。所以当工人处理它失败时。见附图。
我附加调试器到这个过程。我的断点在循环中首先发射了30-40秒。但是在调试器脱离后,我在Azure门户中看到该消息,该工作人员不健康。
我也尝试在单独的线程中执行文件处理方法。但有同样的结果。
任何想法?
UPDATE:
我的运行方法看起来像
public override void Run() {
var queue = GetCloudQueue();
int maxJobRetries = 10;
while (true) {
try {
var msg = queue.GetMessage();
if (msg != null) {
if (msg.DequeueCount <= maxJobRetries) {
ImportCommand ic = JsonConvert.DeserializeObject <ImportCommand> (msg.AsString);
ProcessImport(queue, msg);
} else {
queue.DeleteMessage();
}
} else {
Thread.Sleep(100);
}
} catch (Exception ex) {
//handle exception
}
}
}
我真的不认为有任何未处理的异常可以被抛出。我把所有的代码放在try catch块中。
我认为值得一提的是我使用Gembox来解析xlsx文件。我的分析方法如下:
public IEnumerable <string[]> ReadLines(int sheetIndex) {
string[] data = null;
if (_file.Worksheets.Count > 0 && _file.Worksheets[sheetIndex].Rows.Count > 0) {
if (_headerLength == 0) {
_headerLength = _file.Worksheets[sheetIndex].Rows[0].AllocatedCells.Count;
}
// I have great than 1 000 000 Rows
foreach(ExcelRow row in _file.Worksheets[sheetIndex].Rows) {
data = new string[_headerLength];
// I have 30 columns
for (int j = 0; j < _headerLength ; j++) {
ExcelCell cell = row.Cells[j];
if (cell.Value != null) {
bool isDate = cell.Value is DateTime;
if (!isDate) {
data[j] = cell.Value.ToString();
} else {
//if locale is null then used CurrentCulture (.net feature)
data[j] = ((DateTime) cell.Value).ToString(_locale);
}
} else {
data[j] = null;
}
}
yield return data;
}
}
}
更新2:
感谢David Makogon。 我改变了两个尺寸(高达A2),现在它正在工作。但是我的记忆花了一分钟。而且保留A2非常昂贵。任何想法如何减少我的代码,使其在小实例上工作?
最有可能你的角色,是因为未处理的异常的循环。你能否包括你的角色的'OnStart'方法的代码? –