php / php/php-src

set_timeout() fails to terminate execution when IO Latency is high

Đang mở
#11,971 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Feature Status: Needs Triage
Ngôn ngữ chính
C
Star
40.4k
Fork
8.2k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

Description

I'm not sure if this is a bug or not and I haven't found the proper channel to ask (shall I raise a discussion in Internals?).

We faced a problem in our production cluster. Our setup is following:

SAPI: fpm
max_execution_time: 28
hard_timeout: 2

When Opcache is reloading, we're having excessive IO pressure, which is expected - PHP starts reading everything from disk, etc... However, scripts started executing for 5+ minutes - that wasn't expected.

Further investigation showed that zend_set_timeout_ex uses setitimer(ITIMER_PROF) by default, which means the time the process spends in IOWait doesn't seem to count.

So, basically, even though our gateway cannot wait for such long - it expects that application will finish earlier, PHP still performs the request. One more backside of such behaviour - the restart of Opcache takes longer - it waits until all the workers finish execution (or become killed by opcache when opcache.force_restart_timeout is reached).

This problem doesn't seem to appear when we use ITIMER_REAL. I can provide how we tested this.

I can see a couple of solutions here:

  • Switch to ITIMER_REAL (it looks like there are some concerns about the Apache module)
  • Choose one over another for some SAPIs when we are sure that there shouldn't be a conflict (e.g. FPM, CLI)
  • Make this behaviour configurable (either at runtime or compile time)
  • Something else?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu từ zend_set_timeout_ex và so sánh hành vi được báo cáo của ITIMER_PROF với ITIMER_REAL dưới FPM và độ trễ I/O cao. Xem xét mối lo ngại về mô-đun Apache và các phương án thay thế được đề xuất; công việc được coi là hoàn tất khi đã quyết định được hành vi của timer hoặc cách tiếp cận cấu hình ngăn các request chạy trong vài phút.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
c, php
Lĩnh vực
operating-systems
Loại issue
Lỗi
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.