Yii Framework Forum: no effect on $model()->save() with high load - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

no effect on $model()->save() with high load Rate Topic: -----

#1 User is offline   rotschopf 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 01-December 08

Posted 04 December 2008 - 10:25 AM

hi there,

i've got a problem with the active record system or the database? :(

$session = session::model()->find("sid=:sid AND end=:end", array(':sid' => $_POST['SESSION'], ':end' => "0"));
if ($session->sid === $_POST['SESSION'] && $session->plant->login === $_POST['ACCOUNT'])
{
$dataset = new dataset;
$dataset->....
                        .
                        .
if (!dataset::model()->exists('plantID=:plantID AND timeStamp=:timeStamp', array(':plantID' => $session->plant->id, ':timeStamp' => $_POST['TIME'])))
if ($dataset->save())
{
$session->lastActivity = time();
$session->transmitedDS = $session->transmitedDS + 1;
if ($session->save())
{
$this->answers['O'] = 'data successfully uploaded';
} else {
$this->answers['E'] = $session->getErrors();
}
}
else
$this->answers['E'] = 'it occured a problem while uploading data';
else
$this->answers['E'] = "there is already data for this time";
}
else
$this->answers['E'] = "session doesn't belong to your account";


The problem occures when this code is requested to many times simultaneously.
Then sometimes the $session model isn't saved... About 30% of the new datasets (DS) aren't regristered...

hopefully somebody nows a solution, greets
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,871
  • Joined: 04-October 08
  • Location:DC, USA

Posted 04 December 2008 - 10:31 AM

The problem is not obvious to me. You have two "if" conditions outside of the if(save()) call. Did you check if they have problem? What about the first line? Does it always returns a not-null session?
0

#3 User is offline   rotschopf 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 01-December 08

Posted 04 December 2008 - 10:57 AM

i've got a client program in python for the client side and can define the max of simultaneous connections to the server.

if only one connection at once there's no problem... but with five simultaneous connections in about 30% of theses requests the $session couldn't be saved... and $this->answers['E'] becomes an empty array...
0

#4 User is offline   rotschopf 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 01-December 08

Posted 04 December 2008 - 11:01 AM

if (!dataset::model()->exists('plantID=:plantID AND timeStamp=:timeStamp', array(':plantID' => $session->plant->id, ':timeStamp' => $_POST['TIME'])))

checks a unique key...

is there any possibility to do that by a cvalidator?

and
if ($dataset->save())

makes sure that the DS was really transmited into the database
0

#5 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,871
  • Joined: 04-October 08
  • Location:DC, USA

Posted 04 December 2008 - 11:20 AM

Yes, there is a CUniqueValidator that you may use.

However, for your testing scenario, I think you probably should consider enclosing the uniqueness check and saving inside a transaction. Otherwise it is very likely something will not be saved due to uniqueness constraint.
0

#6 User is offline   rotschopf 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 01-December 08

Posted 04 December 2008 - 06:30 PM

please have another look at the unique test...

there are two columns that have to be together unique... i didn't find a possibility to tell that the CUniqueValidator class.

another question is: what are transactions? but i going to answer that tomorrow ;)
0

#7 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,871
  • Joined: 04-October 08
  • Location:DC, USA

Posted 04 December 2008 - 07:44 PM

Then you can't use CUniqueValidator because it uses only one column.

You can put the uniqueness check inside beforeSave() method.

A transaction ensures queries inside it to be atomic. See:
http://www.yiiframew...saction-with-ar
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users