Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jms serializer performance issue

Tags:

I'm using the JMS Serializer. And I found out that the performance is really bad when I use big data. I've the following object structure displayed as an array:

$jsonData = array(     'message' => 'this is a nice message',      'data' => array(         0 => array(           'firstname' => 'achim',           'lastname' => 'menzel'          )     ) ); 

This is how I serialize the data:

$serializer = $this->get('serializer'); $encodedJson = $serializer->serialize($jsonData, 'json');  $response = new Response($encodedJson); $response->headers->set('Content-Type', 'application/json'); 

Data can be a list of 1 till n objects. When I have more than 500 objects in data, the performance is very very slow (more then 5sec.). When i use json_encode() directly, it tooks not more then 1 second.

How can I improve the usage of JMS Serializer? I don't think that jms serializer cannot handle big data.

This is the main class which will be used for serializing:

class JsonData {    public $success = false;   public $message = '';   public $data;   public $responseCode = 200;   public $contentType = 'application/json'; } 

And currently this object is inside $data:

class GuestDTO {    private $userid;   private $firstname;   private $lastname;   private $birthday;   private $picturemedium;   private $picturelarge;   private $gender;   private $modifydate;   private $entries = array();  } 

And $entries is a list of objects from this class:

class GuestlistentryDTO extends AbstractGuestDTO{    private $guestlistentryid;   private $guestlistid;   private $arrivedat;   private $bouncername;   private $rejectionreason;   private $companioncount;   private $companioncountcheckin;       private $winner;   private $vip;   } 

Without any annotations because I prepared my dto's for using the data as I need.

like image 543
Sandor Farkas Avatar asked May 24 '13 10:05

Sandor Farkas


2 Answers

Unfortunately this library is inherently pretty slow. There's a lot of recursion in there.

A couple of things you can do however is query cache everything using either Redis or Memcache. You can also be smart with your SQL queries, try to trim the fat. Only give the serializer the important data you need so it isn't trawling through lots of data that won't be getting used anyway.

like image 165
Ewan Valentine Avatar answered Nov 17 '22 00:11

Ewan Valentine


Are you using partial responses? your problem seems actually quite obvious. In my opinion your client should ask for a limited number of items and ask for more when necessary...

like image 22
David Vartanian Avatar answered Nov 17 '22 00:11

David Vartanian