-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Hibernate, serialization, performance... can anyone explain?
PostPosted: Fri Apr 23, 2004 12:13 pm 
Newbie

Joined: Tue Oct 07, 2003 3:58 pm
Posts: 16
Location: Netherlands
This is a trace of executing just a simple load() method on an
OperatorSession object, which has got three fields of 'serializable' type.

To improve performance, serialization was rewritten as custom readObject()/writeObject() methods.

What I see here is a little bit embarassing:


- OperatorSessionFactory - Loading operator session id='123'
- SessionImpl - loading [OperatorSession#123]
- SessionImpl - attempting to resolve [OperatorSession>
- ReadWriteCache - Cache lookup: 123
- Plugin - key: 123
- MemoryStore - OperatorSessionCache: MemoryStore miss>
- Cache - OperatorSession cache - Miss
- Plugin - Element for 123 is null
- ReadWriteCache - Cache miss: 123
- SessionImpl - object not resolved in any cache [Oper>

Ok, we haven't found it in the cache, let's go to database

- EntityPersister - Materializing entity: [OperatorSession>
- BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
- SQL - select operatorse0_.id as id0_, operatorse0_.operatorName as operator>
- BatcherImpl - preparing statement
- StringType - binding '123' to parameter: 1
- Loader - processing result set
- Loader - result row: 123
- Loader - Initializing object from ResultSet: 123
- Loader - Hydrating entity: OperatorSession#123
- StringType - returning null as column: operator2_0_
- StringType - returning '123456' as column: terminal3_0_
- StringType - returning null as column: candidat4_0_
- TimestampType - returning '23 April 2004 17:54:57' as column: created0_
- TimestampType - returning '23 April 2004 17:54:57' as column: accessed0_
- BooleanType - returning 'false' as column: justResu7_0_
- OperatorSession - OperatorSession$ScriptState state recovered: /false////
..deserialized...
- OperatorSession - OperatorSession$ScriptState state saved: /false////
..serialized...
- SerializableType - returning '2c6d8085f3f280bae3efedaef6efe3efe7eee9f4e9efeeaeebe5f2eee5>
- OperatorSession - OperatorSession$ScriptState state recovered: /false////
..deserialized...
- OperatorSession - OperatorSession$ScriptState state saved: /false////
..serialized...
- SerializableType - returning '2c6d8085f3f280bae3efedaef6efe3efe7eee9f4e9efeeaeebe5f2eee5>
- OperatorSession - OperatorSession$ScriptState state recovered: /false////
..deserialized...
- OperatorSession - OperatorSession$ScriptState state saved: /false////
..serialized...

Deserialization I could understand but why were those fields serialized again?

- SerializableType - returning '2c6d8085f3f280bae3efedaef6efe3efe7eee9f4e9efeeaeebe5f2eee5>
- SerializableType - returning '2c6d8085f3f28091eae1f6e1aef5f4e9ecaec8e1f3e8cde1f085875a41>
- StringType - returning null as column: environ12_0_
- SerializableType - returning null as column: assignment0_
- SerializableType - returning '2c6d8085f3f28091eae1f6e1aef5f4e9ecaec8e1f3e8d3e5f43ac40515>
- Loader - done processing result set (1 rows)
- BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
- BatcherImpl - closing statement
- Loader - total objects hydrated: 1

Hurray, finally object is loaded.

- SessionImpl - resolving associations for [OperatorSe>
- SessionImpl - adding entity to second-level cache [O>

Let's add it to cache just in case.

- OperatorSession - OperatorSession$ScriptState state saved: /false////
- OperatorSession - OperatorSession$ScriptState state saved: /false////
- OperatorSession - OperatorSession$ScriptState state saved: /false////

Serialize it again (!) - why, I might be well using local in-memory cache?
I understand that for distributed cache it's necessary to serialize, but why not let cache plug-in implementation to decide whether serialize or not?

- ReadWriteCache - Caching: 123
- Plugin - key: 123
- MemoryStore - OperatorSessionCache: MemoryStore miss>
- Cache - OperatorSession cache - Miss
- Plugin - Element for 123 is null
- ReadWriteCache - Saved to cache: 123
- OperatorSession - OperatorSession$ScriptState state saved: /false////
- OperatorSession - OperatorSession$ScriptState state recovered: /false////
- OperatorSession - OperatorSession$ScriptState state saved: /false////
- OperatorSession - OperatorSession$ScriptState state recovered: /false////
- OperatorSession - OperatorSession$ScriptState state saved: /false////
- OperatorSession - OperatorSession$ScriptState state recovered: /false////

After being saved to cache, every field is three times serialized/deserialized.

- SessionImpl - done materializing entity [OperatorSes>
- SessionImpl - initializing non-lazy collections
- OperatorSessionFactory - [78 ms] Operator session loaded

Yes it took 78 milliseconds to do a lot of those strange things.

I'm not very sure about application performance in this case: there were _three_ serializations and two deserializations. My plain stupid hand-made Entity BMP was doing it with just one deserialization. Why all that? Serialization is expensive, why do it again and again?

This is mapping file (excerpt):

<hibernate-mapping>
<class
name="OperatorSession"
table="OPERATOR_SESSION"
dynamic-update="true"
dynamic-insert="true"
>
<cache usage="read-write" />

<id
name="id"
column="id"
type="java.lang.String"
length="20"
>
<generator class="assigned">
</generator>
</id>

<property
name="operatorName"
type="java.lang.String"
update="true"
insert="true"
column="operatorName"
length="20"
/>

<property
name="mainScriptState"
type="serializable"
update="true"
insert="true"
>
<column
name="mainScriptState"
sql-type="binary"
/>
</property>

<property
name="subroutineScriptState"
type="serializable"
update="true"
insert="true"
>
<column
name="subroutineScriptState"
sql-type="binary"
/>
</property>

<property
name="switchingScriptState"
type="serializable"
update="true"
insert="true"
>
<column
name="switchingScriptState"
sql-type="binary"
/>
</property>

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 23, 2004 12:23 pm 
Newbie

Joined: Tue Oct 07, 2003 3:58 pm
Posts: 16
Location: Netherlands
am I right that if I want to avoid triple serialization with local caching, I need just to plug it custom implementation of Type that will just return the contents instead?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 23, 2004 12:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
That is how Hibernate snapshots and dirty checks serializabel objects.

Usually, CMP engines do not implement proper dirty checking for mutable objects, so that explains the difference.

If you want some other behavior, it is trivial to implement a UserType.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 25, 2004 6:42 am 
Newbie

Joined: Tue Oct 07, 2003 3:58 pm
Posts: 16
Location: Netherlands
thanks Gavin, that's the way I'll take


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.