저는 ActiveRecord 시스템이있는 PHP 프레임 워크를 사용하고 있습니다. ActiveRecord를 사용하여 많은 메모리를 사용하고 복잡한 쿼리에 대해 실행 시간이 길어서 큰 결과를 얻지 못했습니다.실행 시간과 메모리 사용량이 PHP 관련 성능 지표입니까? CPU는 어떻습니까?
내 참조 페이지 (10,000 개의 개체가있는 배열을 생성하는 스크립트)에서 메모리 소비를 100MB 이상 ~ 15MB로 줄이고 실행 시간을 5 초에서 ~ 1.5 초로 줄였습니다.
이 두 측정 만 고려해야합니까? 아니면 PHP를 통해 나와 다른 메트릭을 사용해야합니까?
객체 변수를 저장하는 함수를 변경하여 대부분의 개선 사항을 달성했습니다. 따라서 CPU에 대한 걱정입니다. 로컬 호스트에서의 테스트가 CPU 부족이 아니기 때문입니다. 그러나 실제 환경에서는 다른 요청 때문에 CPU가 지속적으로 사용됩니다. 그러나 PHP에서 CPU 소비를 측정하는 방법은 무엇입니까?
예 : 활성 레코드가 인스턴스화 될 때마다 필드, 규칙 및 관계가 각 개체 인스턴스의 개인 속성에 설정되었습니다. 필자는 이것을 객체 속성 대신 항상 컴파일하고 반환하는 함수로 변경했습니다.
는 않는 메모리 보자
class Record {
function __construct() {
// Drop the setter methods. Let the CPU work when using the getters.
}
private function getRelations() {
// This process of getting predefined relations, checking for correct data,
// and some other calculations is done once, on every getFields()
// This costs CPU!
return $relations;
}
private function getFields() {
// This process of getting predefined fields, checking for correct data,
// and some other calculations is done once, on every getFields()
// This costs CPU!
return $fields;
}
}
내 두 가지 질문은 다음과 같습니다 :
이- 무엇이 더
class Record { private $relations; private $fields; function __construct() { $this->setRelations(); $this->setFields(); } private function setRelations() { // This process of getting predefined relations, checking for correct data, // and some other calculations is done once, on every construct. // The result is stored in $this->relations; // This costs memory! } private function setFields() { // This process of getting predefined fields, checking for correct data, // and some other calculations is done once, on every construct. // The result is stored in $this->fields; // This costs memory! } private function getRelations() { // This is fast. Loading the set relations from memory. return $this->relations; } private function getFields() { // This is fast. Loading the set relations from memory. return $this->fields; } }
CPU를하자 그것을 할 ?
- 어떻게하면 CPU 소비를 측정 할 수 있습니까?
어쨌든 퍼포먼스에 관심이있는 분들은 ActiveRecord ORM을 사용해야합니다.신속한 프로토 타이핑에 적합하지만 성능이 크게 향상되고 일반적으로 고부하 응용 프로그램에서 실수가 발생합니다. Gateways와 DataMappers를 살펴 보는 것이 좋습니다. – rdlowrey