D
D
deleted-mezhevikin2012-12-05 19:34:02
Yii
deleted-mezhevikin, 2012-12-05 19:34:02

Should ActiveRecord be used in high-load projects?

The documentation says:

Don't abuse Active Record. Although Active Record is a convenient OOP-style data projection, performance is degraded due to the use of objects to represent each row of the result. For data-intensive applications, it is recommended to use a DAO or an API to work with the DBMS at an even lower level.

1. Do you use Active Record in your projects?
2. Are there open source yii projects optimized for high loads?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
P
p4s8x, 2012-12-06
@p4s8x

ActiveRecord is a very handy and useful tool and can and should be used, one of the great parts of the framework that makes development really fast and easy.
If there are performance problems:
1) In all projects we use: CProfileLogRoute with the setting CDbConnection.enableProfiling=true
Tells a lot of useful things.
2) If we see lazy Loading - do not forget to add the necessary relays to with(""), use together() forcibly where necessary.
3) If we use findAll () on a large number of records - use CDbCriteria.select and list only the necessary columns, this will help to significantly improve performance.
I recommend studying in detail from the inside - how CActiveRecord works , CActiveFinder
Use extensions like XDebug for detailed project profiling.
The main performance losses occur inside the
CActiveRecord.populateRecord method - look - what happens inside.
4) All rarely updated data is very easy to cache with a bunch:
CTimestampBehavior + CDbCacheDependency('SELECT MAX(update_time) .... where...');
If the table is rarely updated, then this query will be processed instantly. Mysql also caches the results of such queries itself.
As a result, there are very few places where ActiveRecord has to be abandoned.
We keep the page speed at a level of no more than 0.1 s.
If you have really high workloads, you will hardly save yourself from ActiveRecord alone:
​​Look:
Yii: ActiveRecord Device and Sharding MySQL Sharding on
the Yii Framework

U
un1t, 2012-12-05
@un1t

I do not believe that there can be a plug in this place. Gags happen - a DB, a network and disk operations. Relatively little time is spent on generating objects. I know, some large and really high-loaded projects use hellish braking technologies like extended xslt transformations inside. At the same time, everything flies for the user. This is achieved by caching and horizontal scaling.

L
Lev Lybin, 2012-12-05
@lybin

1. We try not to use it, if suddenly where it becomes noticed, with the possibility of time, it is immediately rewritten.

V
VeMax, 2012-12-05
@VeMax

1. Yes, but either without fanaticism. The bulk of every project does not use AR.
2. Did not meet.

B
Boris Syomov, 2012-12-05
@kotomyava

I use it where appropriate.
Of course, it makes sense to optimize frequently performed front-end operations by abandoning AR.
And in general, it’s not bad to take care of profiling if loads are planned, and sometimes even if they are not planned, for the sake of interest. =)

R
Rowdy Ro, 2012-12-05
@rowdyro

For reading (the vast majority of operations under load), I rarely use AR, and this is not very convenient, because the output goes either directly to the template engine or to json. To use foreign keys in this case (respectively join) is a fail.
But when adding / changing, it is very convenient to carry out validation through AR.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question