Foros de discusión

TableMapper API

thumbnail
Jay Patel, modificado hace 8 años.

TableMapper API

Regular Member Mensajes: 118 Fecha de incorporación: 24/02/10 Mensajes recientes
Anyone has any idea on the use of TableMapper classes in Liferay 6.2

Long story short, we have been experiencing slow performance while creating/updating users in Liferay.

Long Story:
We have a background job which pushes users to Liferay (create/update). After reaching around 500K users mark, we have seen it takes around 2-3 minutes just to add a user to Liferay. We have been taking thread dumps and found that most time spent is in TableMapper classes. See stack below:

om.liferay.portal.service.persistence.impl.TableMapperImpl.getPrimaryKeys(TableMapperImpl.java:426)
at com.liferay.portal.service.persistence.impl.TableMapperImpl.containsTableMapping(TableMapperImpl.java:452)
at com.liferay.portal.service.persistence.impl.TableMapperImpl.containsTableMapping(TableMapperImpl.java:155)
at com.liferay.portal.service.persistence.RolePersistenceImpl.containsUser(RolePersistenceImpl.java:9607)
at com.liferay.portal.service.base.UserLocalServiceBaseImpl.hasRoleUser(UserLocalServiceBaseImpl.java:807)

While debugging, I found that this checks whether user already has this role or not. What I'm not sure of is...while doing this one of the query is like "select userIds from user_role where roleId=xxx". We have one of the regular role that is associated with most of the users and the result of this query is quite large.

Similarly further dumps showed that while assigning groups to a user, it uses TableMapper classes and spends significant time while pulling userIds associated with some common group.

What I want to understand is what is the significance of this API? Especially if we just want to just create (NOT update) a user, then does it make sense to check whether user belongs to specific role/group etc.

Any pointers???
thumbnail
Alexey Kakunin, modificado hace 8 años.

RE: TableMapper API

Liferay Master Mensajes: 621 Fecha de incorporación: 7/07/08 Mensajes recientes
Hi Jay!

To say truth - I'm really surprised - it looks like you found serious perfomance issue in Liferay.

Liferay used Service Builder and service.xml to automatically generates classes like RolePersistanceImpl - this file is fully generated.
TableMapper is a class to implement many-to-many relation - it used in all places there these relation is used (user <-> role, user <-> group, user <-> organization) and as I said - from my side I'm really surprised that for this implementation to check does user contain role or not (to check is relation exists between two entities) it is instead of one simple sql- query used getting all relations and enumerating them them (even they use cache or BinarySearch - it is not an option).

So - I donot think you should avoid somehow TableMapper API - but method containsTableMapping should be optimized.

From first look - it should not be too complex - class already has templates for sql quesries as well as it can call sql database, so, it looks like we need only to add another template and use it in containsTableMapping method. This can be done with ext-plugin.

But - anyway - it is good issue to send into JIRA or LESA in case you are using EE version - I'm pretty sure in terms of enterprise support it should be fixed quickly (I will be really surprising if you using 500k users portal based on CE)

====
Alexey Kakunin
Liferay Experts in Russia
thumbnail
Jay Patel, modificado hace 8 años.

RE: TableMapper API

Regular Member Mensajes: 118 Fecha de incorporación: 24/02/10 Mensajes recientes
Thanks Alexey for your response.

Yes, we are an EE customer so I'm going to raise a LESA soon. Also I've have an option to override this with ext. But wanted to understand TableMapper first.

However what I'm not clear on :

1. While a user entity is being created, why there is a need to check mapping between user <-> role, user <-> group etc. Database will never have this record at all since user was never in the system and is being added for the first time. So definitely there is a case for optimization.

2. One of the query fired is like "select userIds from user_role where roleId=SOME_REGULAR_ROLE_ID". Again this is confusing, if there is a need to check whether record exists for the user-role mapping why need to retrieve all userIds (im my case around 500K). It can be done other way around like "select roleIds from user_role where userId=SOME_USER_ID". This query will retrieve far less results than the previous query (in my case less than 20).

Thanks again!!
thumbnail
Jay Patel, modificado hace 8 años.

RE: TableMapper API

Regular Member Mensajes: 118 Fecha de incorporación: 24/02/10 Mensajes recientes
Just found out this...I guess I'm not the only one going through this pain emoticon

https://www.liferay.com/community/forums/-/message_boards/message/43336523
thumbnail
Zankar Shah, modificado hace 5 años.

RE: TableMapper API

Regular Member Mensajes: 106 Fecha de incorporación: 3/10/07 Mensajes recientes
Hi Jay,
Did you get any solution to it?

​​​​​​​Did you try out the link https://community.liferay.com/forums/-/message_boards/message/43336523