我遇到了一个asp.net核心应用程序的问题,该应用程序在负载启动时几乎挂起。一旦启动,应用程序可以处理负载没有问题。感觉每个并发请求都会发生初始化。是否还有其他人遇到类似的行为?
测试场景:
作为临时工作,我创建了中间件,在第一次完成之前限制后续请求。这有效地让asp.net mvc在处理大量请求之前进行初始化。这个特殊的应用程序是带有EF核心的asp.net核心1.1(web api)。
答案 0 :(得分:1)
当使用位于全国各地的真实数据库时,我第一次向ASP.NET Core WebAPI请求时遇到了900毫秒的延迟。这是因为它需要建立连接池以便与连接到所述数据库一起使用,并且在运行服务时我不急切地创建连接池。相反,当我通过在服务容器中注册为单例的连接工厂请求连接时,它会被懒惰地初始化。
也许您遇到了与您所说的使用Entity Framework Core相同类型的延迟,而Entity Framework Core可能是由SQL Server支持的。 作为此初始请求的一部分,是否会延迟启动数据库的连接池?
尝试创建一个没有任何返回vanilla class Node:
def __init__(self, path, board, posn, depth, direction=None, f=None):
self.path = path
self.depth = depth
self.board = board
self.posn = posn
self.__children = list()
self.visited = False
if direction is not None:
self.direction = direction
self.__postProcess(direction)
self.g = len(path)
self.h = self.__getHeuristic()
if f is None:
self.f = self.g + self.h
else:
self.f = f
def __repr__(self):
#return "*" + ''.join(str(e) for e in self.board) + "*" DEBUG
return str(hash(self))
def __eq__(self, other):
return isinstance(other, self.__class__) and self.board == other.board
def __hash__(self):
array = tuple(self.board[0] + self.board[1] + self.board[2])
return hash(array)
def __lt__(self, other):
return self.f
def getParentHash(self):
"""Calculates the parent, of this nodes, hash"""
dboard = deepcopy(self.board)
# Find where 0 is on board
for row in range(3):
for column in range(3):
if 0 == dboard[row][column]:
posn = [row, column]
#Undo last step to deepcopy board
if self.path[-1] == "Right":
dboard[posn[0]][posn[1]] = dboard[posn[0]][posn[1]-1]
dboard[posn[0]][posn[1]-1] = 0
elif self.path[-1] == "Left":
dboard[posn[0]][posn[1]] = dboard[posn[0]][posn[1]+1]
dboard[posn[0]][posn[1]+1] = 0
elif self.path[-1] == "Up":
dboard[posn[0]][posn[1]] = dboard[posn[0]+1][posn[1]]
dboard[posn[0]+1][posn[1]] = 0
elif self.path[-1] == "Down":
dboard[posn[0]][posn[1]] = dboard[posn[0]-1][posn[1]]
dboard[posn[0]-1][posn[1]] = 0
return hash(tuple(dboard[0] + dboard[1] + dboard[2]))
def getChildren(self):
"""getChildren generates children of node, if they have not be prev generated or the node has not been visited yet, returns all children for the given node"""
if len(self.__children) == 0 and not self.visited: #allows me to print a graph given the root node
cdn = list()
if 0 not in self.board[0]:
cdn.append(Node(self.path[:], deepcopy(self.board), self.posn[:], self.depth + 1, 'Up'))
if 0 not in self.board[2]:
cdn.append(Node(self.path[:], deepcopy(self.board), self.posn[:], self.depth + 1, 'Down'))
if 0 not in (self.board[0][0], self.board[1][0], self.board[2][0]):
cdn.append(Node(self.path[:], deepcopy(self.board), self.posn[:], self.depth + 1, 'Left'))
if 0 not in (self.board[0][2], self.board[1][2], self.board[2][2]):
cdn.append(Node(self.path[:], deepcopy(self.board), self.posn[:], self.depth + 1, 'Right'))
self.__children = cdn
self.visited = True
return cdn
else:
return self.__children
def __getPos(self, num):
for row in range(3):
for column in range(3):
if num == self.board[row][column]:
return [row, column]
def __getHeuristic(self):
pos0 = self.__getPos(0)
pos1 = self.__getPos(1)
pos2 = self.__getPos(2)
pos3 = self.__getPos(3)
pos4 = self.__getPos(4)
pos5 = self.__getPos(5)
pos6 = self.__getPos(6)
pos7 = self.__getPos(7)
pos8 = self.__getPos(8)
zero = abs(0 - pos0[0]) + abs(0 - pos0[1])
one = abs(0 - pos1[0]) + abs(1 - pos1[1])
two = abs(0 - pos2[0]) + abs(2 - pos2[1])
three = abs(1 - pos3[0]) + abs(0 - pos3[1])
four = abs(1 - pos4[0]) + abs(1 - pos4[1])
five = abs(1 - pos5[0]) + abs(2 - pos5[1])
six = abs(2 - pos6[0]) + abs(0 - pos6[1])
seven = abs(2 - pos7[0]) + abs(1 - pos7[1])
eight = abs(2 - pos8[0]) + abs(2 - pos8[1])
return zero + one + two + three + four + five + six + seven + eight
def __postProcess(self, dirn):
"""postProcess: Correctly updates the current node to accurately reflect it state of the board based on
the direction passed through the functions parameter """
y = self.posn[0]
x = self.posn[1]
if 'Left' == dirn:
self.board[y][x] = self.board[y][x - 1]
self.board[y][x - 1] = 0
self.posn[1] = x - 1
elif 'Right' == dirn:
self.board[y][x] = self.board[y][x + 1]
self.board[y][x + 1] = 0
self.posn[1] = x + 1
elif 'Up' == dirn:
self.board[y][x] = self.board[y - 1][x]
self.board[y - 1][x] = 0
self.posn[0] = y - 1
elif 'Down' == dirn:
self.board[y][x] = self.board[y + 1][x]
self.board[y + 1][x] = 0
self.posn[0] = y + 1
self.path.append(dirn)
的依赖项的控制器。假设您没有具有昂贵的水合服务的全局过滤器,您应该看到Web服务的基线初始化性能。