drtpbx3606 2018-08-15 10:00
浏览 34

Symfony批处理请求内核执行时间

I am trying to perform bulk operations using a command line tool and the http_kernel component.

I have stored the requests in a database and, using a command, i'm trying to use my controllers internally by calling $kernel->handle($request); for every request.

The problem is that the execution time of each request is growing up over time.

This command has been run in a test environment and I am sure the execution will be much more faster on the production server.

Edit: I have about 10.000 requests to be executed, and all those requests are very similar

However, I would like to know if there is an optimisation that could be done to ensure a stable execution time for the whole batch.

Here is my code:

$kernel = $this->getContainer()->get('http_kernel');

foreach ($requests as $request) {

        $start = round(microtime(true) * 1000);

        $response = $kernel->handle($request);
        $kernel->terminate($request, $response);

        $requestDuration = (round(microtime(true) * 1000) - $start);

        $output->writeln(($response->isSuccessful() ? ' . ' : ' X ') . '(' . $handleDuration . ')');
}

Here is an example output : (. stands for a successfull request; the time (ms) is in parentheses)

. (246 ms)
. (275 ms)
. (271 ms)
. (268 ms)
. (564 ms)
. (379 ms)
. (353 ms)
. (321 ms)
[...]
. (416 ms)
. (425 ms)
. (409 ms)
. (448 ms)
. (402 ms)
. (405 ms)
. (410 ms)
. (453 ms)
. (476 ms)
. (462 ms)
. (488 ms)
[...]
. (564 ms)
. (537 ms)
. (553 ms)
. (564 ms)
. (510 ms)
. (564 ms)
. (531 ms)
. (569 ms)
. (655 ms)
[...]
. (1155 ms)
. (1179 ms)
. (1142 ms)
. (1126 ms)

Thank you for your help !

(Edit)

Here are some details about the actions performed by the controller :

public function postEntityAction(Request $request) {
    // get the authenticated user
    $authUser = $this->getUser();
    // fetch some data from the database (there is about 6 calls like this one that could be done during the process)
    // note: the hydrator used by all my repository methods is SIMPLEOBJECT
    $item = $itemRepository->getItemById($request->request->get('itemId'));
    // create an entity and set its fields
    $entity = new Entity();
    $entity->setItem($item);
    // I also do some validations using the validator service
    $validator = $this->get('validator');
    $validator->validate($entity);
    // I persist the new entity
    $this->getDoctrine()->getManager()->persist($entity);
    $this->getDoctrine()->getManager()->flush();
    // and finally I return the serialized object (using JMS serializer)
    return $this->serialize($entity);
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)