使用Doctrine ORM,450ms的网站响应时间对用户来说是否很慢?

发布于 2024-11-28 05:35:49 字数 2254 浏览 1 评论 0原文

准备推出一个完全依赖于数据库查询的新平台。

最重的页面,即用户看到的第一个页面,处理一堆查询,一些更复杂的查询。我有一个“Newsfeed”,这是一个较重的查询:

$friends = User::getLogged()->Friends->getPrimaryKeys() ;
$friends[] = User::getLogged()->id ;
$query = $this->createQuery('o')->addSelect('o.*')
->leftJoin('o.Creator u')->leftJoin('u.Avatarimage av')->addSelect('u.*, av.*')->addSelect('u.id, av.*, u.display_name AS creators_display_name')
    ->leftJoin('u.Profiletype t')
    ->leftJoin('t.ProfiletypeTranslation tm WITH tm.translation_id=?', Translation::getForVisitor()->id)->addSelect('tm.name AS creators_profiletype_name')
  // for type: NEW_IMAGES_IN_ALBUM
 ->leftJoin('o.NewImagesInAlbum i WITH i.album_id=o.album_id')->addSelect('i.id, i.filename, i.width, i.height') 
    ->leftJoin('o.Album a')->addSelect('a.id, a.name AS album_name')
// for type: NEW_CASTING 
->leftJoin('o.Casting s')
    ->addSelect('s.*, s.title AS castings_title')
// for type: NEW_COMMENT_ON_IMAGE               
->leftJoin('o.Comment c')
    ->leftJoin('c.User u1')->addSelect('c.*, u1.display_name AS receivers_display_name')
    ->leftJoin('c.Image i2')
    ->leftJoin('i2.Album a2')->addSelect('a2.name AS album_of_commented_image')
// for type: NEW_FRIENDSHIP
->leftJoin('o.NewFriends nf')
    ->leftJoin('nf.Avatarimage nfav')
    ->addSelect('nf.*, nfav.*')
->orderBy('created_at DESC')
->whereIn('o.creator_id', $friends)
->andWhereIn('o.type', array
    (
        Activity::NEW_IMAGES_IN_ALBUM, 
        Activity::NEW_PROFILE_STATUS, 
//                  Activity::NEW_COMMENT_ON_USER, 
        Activity::NEW_COMMENT_ON_IMAGE, 
        Activity::NEW_CASTING, 
        Activity::NEW_FRIENDSHIP, 
        Activity::NEW_AVATAR
    )
    )
//              ->where('type=?', 1)
//              ->groupBy('o.id')
->limit(20) ;
return $query->execute() ;

这是页面上最大的查询,还有另一个用于查找通知的大查询,以及另外 3 个用于查找消息的较小查询,等等...

该页面感觉像是立即加载到我,但是使用 Chrome,Chrome 显示等待时间为 452 毫秒(CPU 处理所有该死的类文件),然后另外 200 毫秒来交付/加载所有内容,因此总共需要 650 毫秒来显示所有内容。

在用户交互和社交网络的世界中,这对用户来说会变慢吗?我需要进一步尝试和优化吗?我正在运行双六核 Xeon 2.4GHz(总共 12 个核)。我可能必须升级到更快的版本才能处理所有用户并减少 PHP 加载所有类文件所需的时间。

您对 Doctrine 的 450 毫秒有何看法?

Getting ready to launch a new platform, which relies solely on DB queries.

The heaviest page, the first page users see handles a bunch of queries, some little more complex queries. I have the "Newsfeed" which is a heavier query:

$friends = User::getLogged()->Friends->getPrimaryKeys() ;
$friends[] = User::getLogged()->id ;
$query = $this->createQuery('o')->addSelect('o.*')
->leftJoin('o.Creator u')->leftJoin('u.Avatarimage av')->addSelect('u.*, av.*')->addSelect('u.id, av.*, u.display_name AS creators_display_name')
    ->leftJoin('u.Profiletype t')
    ->leftJoin('t.ProfiletypeTranslation tm WITH tm.translation_id=?', Translation::getForVisitor()->id)->addSelect('tm.name AS creators_profiletype_name')
  // for type: NEW_IMAGES_IN_ALBUM
 ->leftJoin('o.NewImagesInAlbum i WITH i.album_id=o.album_id')->addSelect('i.id, i.filename, i.width, i.height') 
    ->leftJoin('o.Album a')->addSelect('a.id, a.name AS album_name')
// for type: NEW_CASTING 
->leftJoin('o.Casting s')
    ->addSelect('s.*, s.title AS castings_title')
// for type: NEW_COMMENT_ON_IMAGE               
->leftJoin('o.Comment c')
    ->leftJoin('c.User u1')->addSelect('c.*, u1.display_name AS receivers_display_name')
    ->leftJoin('c.Image i2')
    ->leftJoin('i2.Album a2')->addSelect('a2.name AS album_of_commented_image')
// for type: NEW_FRIENDSHIP
->leftJoin('o.NewFriends nf')
    ->leftJoin('nf.Avatarimage nfav')
    ->addSelect('nf.*, nfav.*')
->orderBy('created_at DESC')
->whereIn('o.creator_id', $friends)
->andWhereIn('o.type', array
    (
        Activity::NEW_IMAGES_IN_ALBUM, 
        Activity::NEW_PROFILE_STATUS, 
//                  Activity::NEW_COMMENT_ON_USER, 
        Activity::NEW_COMMENT_ON_IMAGE, 
        Activity::NEW_CASTING, 
        Activity::NEW_FRIENDSHIP, 
        Activity::NEW_AVATAR
    )
    )
//              ->where('type=?', 1)
//              ->groupBy('o.id')
->limit(20) ;
return $query->execute() ;

That's the biggest query on the page, there is another big query for finding notifications, and 3 other smaller queries for finding messages, etc...

The page feels like it loads instantly to me, but using Chrome, Chrome shows 452ms waiting (CPU processing all my damn class files), and then another 200ms to deliver/load everything, so in total it's 650ms to show everything.

In the world of user interaction and social networking, is this going to be to slow for users? Do I need to try and optimize even more? I'm running a dual six-cores xeon 2.4ghz (12 cores total). I might have to upgrade to an even faster one to handle all of the users and reduce the time it takes for PHP to load all the class files.

What are your thoughts on 450ms with Doctrine?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白昼 2024-12-05 05:35:49

粗略地查看您的查询表明您基本上对每个查询都使用 select * ,这对数据库服务器的性能没有帮助。

A cursory look at your queries shows me that you are using select * for basically every query, that doesn't help a database server with performance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文