Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Symfony]ContextListener - przekroczenie limitu pamięci
Forum PHP.pl > Forum > PHP > Frameworki
phpion
Witam,
mam problem z Symfony 4.4 + PHP 7.4 i zużyciem pamięci. Jest formularz z kilkoma polami i w momencie jego wysłania serwer wyrzuca błąd 502 lub symfoniową stronę błędu (różnie). Błąd tyczy przekroczenia pamięci w klasie ContextListener.

W kodzie kontrolera obslugującego formularz jest:
  1. $this->addFlash('success', 'Wysłano komunikat');
  2. return $this->redirectToRoute('prpo_msg_list');

i z tego co zdiagnozowałem to wiadomość flash prawidłowo się zapisuje (więc wcześniejszy kod wykonuje się prawidłowo), dopiero potem rzucany jest błąd. Jeśli w tym momencie wywołam adres spod trasy 'prpo_msg_list' to wczytuje się on prawidłowo + widzę dodany wcześniej komunikat flash.

Zrobiłem też inny test. Lokalnie podniosłem limit pamięci dla tej akcji do 1024M i zakomentowałem linijkę z przekierowaniem. W efekcie akcja post się wykonuje ale nie następuje przekierowanie więc mogę zobaczyć profiler. W momencie wczytania pustego formularza zużycie pamięci pokazywane przez profiler waha się w granicach 20-40MB (co odświeżenie różna wartość), natomiast po wysłaniu formularza postem wynosi... 400MB.

Wyświetlając informacje z profilera Symfony widzę, że największy wzrost pamięci odnotowywany jest w debug.security.authorization.vote (skok o kilkaset mega).

Idąc dalej: przekroczenie pamięci następuje w klasie ContextListener w linii:
  1. $session->set($this->sessionKey, serialize($token));

Zrzuciłem sobie zawartość $token na ekran i zauważyłem, że obiekt użytkownika zawiera m.in. wszystkie wiadomości (krótkie tekstowo, ilość ok. 20 więc bez szału) i poszedłem w tym kierunku. W encji widzę:

  1. /**
  2.   * @var \Doctrine\Common\Collections\Collection
  3.   *
  4.   * @ORM\ManyToMany(targetEntity="App\Module\PricesPolicy\Entity\PrpoMessage", inversedBy="receivers")
  5.   * @ORM\JoinTable(name="prpo_receiver",
  6.   * joinColumns={
  7.   * @ORM\JoinColumn(name="cms_auth_id", referencedColumnName="id")
  8.   * },
  9.   * inverseJoinColumns={
  10.   * @ORM\JoinColumn(name="prpo_message_id", referencedColumnName="id")
  11.   * }
  12.   * )
  13.   */
  14. private $prpoMessage;

Samo dojście do wyświetlenia dumpu $tokena zajmuje ok. 40 sekund. W momencie gdy zakomentuję fragment związany z @ORM\JoinTable są to 3 sekundy. No ale usunięcie tego fragmentu powoduje kolejne błędy w aplikacji.

Czy ktoś z Was spotkał się z takim zjawiskiem? Gdzie szukać przyczyny tak ogromnego zużycia pamięci?
ohm
A co mówi analiza zapytań doctrine? Bo może zaciąga się kaskadowo za dużo danych i serializacja zjada trochę za dużo zasobów.
phpion
Mamy zrzucone wszystkie zapytania bezpośrednio z bazy. To co się dzieje w tej akcji wywołuje łącznie 54 zapytań (mało, nie mało - to aplikacja wewnętrzna nie narażona na duży ruch):
Kod
        39628 Query    START TRANSACTION
        39628 Query    SELECT t0.id AS id_1, t0.name AS name_2, t0.description AS description_3, t0.redirect AS redirect_4 FROM cms_role t0 INNER JOIN prpo_message_receiver ON t0.id = prpo_message_receiver.cms_role_id WHERE prpo_message_receiver.prpo_message_type_id = 6
        39628 Query    SELECT c0_.id AS id_0, c0_.lang AS lang_1, c0_.username AS username_2, c0_.email AS email_3, c0_.password AS password_4, c0_.active AS active_5, c0_.logged AS logged_6, c0_.passwordChangeRequired AS passwordChangeRequired_7, c0_.lastPasswordChange AS lastPasswordChange_8, c0_.dev AS dev_9, c0_.send_mail_on_dev AS send_mail_on_dev_10, c0_.id AS id_11 FROM cms_auth c0_ INNER JOIN user_point u1_ ON (u1_.user_id = c0_.id) INNER JOIN cms_auth_role c2_ ON (c2_.cms_auth_id = c0_.id) WHERE c0_.active = '1' AND u1_.point_id IN (436) AND c2_.cms_role_id IN (7, 19, 84, 133, 222, 223, 236)
        39628 Query    SELECT c0_.id AS id_0, c0_.lang AS lang_1, c0_.username AS username_2, c0_.email AS email_3, c0_.password AS password_4, c0_.active AS active_5, c0_.logged AS logged_6, c0_.passwordChangeRequired AS passwordChangeRequired_7, c0_.lastPasswordChange AS lastPasswordChange_8, c0_.dev AS dev_9, c0_.send_mail_on_dev AS send_mail_on_dev_10, c0_.id AS id_11 FROM cms_auth c0_ INNER JOIN cms_auth_role c1_ ON (c1_.cms_auth_id = c0_.id) WHERE c0_.active = '1' AND c1_.cms_role_id = 236
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 253
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 726
220322  9:36:32    39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 818
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 865
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 2009
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 2740
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 3324
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 3421
220322  9:36:33    39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 3923
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 4021
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 4434
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 4850
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 5707
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 6162
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 6204


Podzielone na 2 wpisy bo się burzyło, że wpis jest za długi.

I dalsza część logu zapytań:
Kod
220322  9:36:34    39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 6265
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 6353
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 7521
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 7928
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 10516
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 10520
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 10528
        39628 Query    SELECT t0.id AS id_1, t0.is_open AS is_open_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.blocked_at AS blocked_at_5, t0.last_block_activity_at AS last_block_activity_at_6, t0.sender_id AS sender_id_7, t0.updated_by_id AS updated_by_id_8, t0.blocked_by_id AS blocked_by_id_9, t0.prpo_message_type_id AS prpo_message_type_id_10 FROM prpo_message t0 INNER JOIN prpo_receiver ON t0.id = prpo_receiver.prpo_message_id WHERE prpo_receiver.cms_auth_id = 10881
220322  9:36:35    39628 Query    INSERT INTO prpo_message (is_open, created_at, updated_at, blocked_at, last_block_activity_at, sender_id, updated_by_id, blocked_by_id, prpo_message_type_id) VALUES (1, '2022-03-22 08:36:31', NULL, NULL, NULL, 253, 253, NULL, 6)
        39628 Query    INSERT INTO prpo_message_point (prpo_message_id, point_id) VALUES (16814, 436)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (253, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (726, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (818, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (865, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (2009, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (2740, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (3324, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (3421, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (3923, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (4021, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (4434, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (4850, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (5707, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (6162, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (6204, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (6265, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (6353, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (7521, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (7928, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (10516, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (10520, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (10528, 16814)
        39628 Query    INSERT INTO prpo_receiver (cms_auth_id, prpo_message_id) VALUES (10881, 16814)
        39628 Query    INSERT INTO prpo_message_limit_shift_f12 (sender_communicate, iska_limit, sender_limit, sender_duration, receiver_limit, receiver_duration, receiver_communicate, receiver_editor_id, receiver_decision_id, prpo_message_id) VALUES ('Bardzo proszę o zwiększenie limitu Shift F12. Powodem zmiany limitu jest […]', NULL, 350, 'month_end', NULL, NULL, NULL, NULL, NULL, 16814)
        39628 Query    COMMIT
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2024 Invision Power Services, Inc.