Foros de discusión

Make Asset Publisher very very faster

thumbnail
ALi Reza Kazemi, modificado hace 9 años.

Make Asset Publisher very very faster

New Member Mensajes: 12 Fecha de incorporación: 9/01/11 Mensajes recientes
Dear Sirs/Madams
After some experiences from liferay 3.2 till now, I am trying to share some of my works with others! may be it could help someone.
In last year we was working on asset publisher performance that it's described in some liferay issues like:
https://issues.liferay.com/browse/LPS-28364
https://issues.liferay.com/browse/LPS-14055

The main problem is that Asset Publisher is really very slow. and after some investigation I find this problem:

Sql query for asset filtering on category or tag is not cached!



So we try to solve it by these steps:
1-If you are using older versions(before 6.1.1 CE GA2), you should apply all changes that is described and provided by Laszlo Csontos. in https://issues.liferay.com/browse/LPS-28364

2-You should cache finder method by applying these changes in AssetEntryFinderImpl.java
at portal-impl\src\com\liferay\portlet\asset\service\persistence\AssetEntryFinderImpl.java

some code for above file is here and full file and patch is here: Download
This file is for liferay 6.1 CE GA1 after LPS-28364 patch! (AssetEntryFinderImpl.java: check it in development environment)

public class AssetEntryFinderImpl
	extends BasePersistenceImpl<assetentry> implements AssetEntryFinder {

....
    .....

    public int countEntries(AssetEntryQuery entryQuery) throws SystemException {
        Session session = null;

        Object[] finderArgs = new Object[]{entryQuery};

        Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_COUNT_ENTRIES,
                finderArgs, this);


        if (count == null) {
            try {
                session = openSession();

                SQLQuery q = buildAssetQuerySQL(entryQuery, true, session);

                Iterator<long> itr = q.iterate();

                if (itr.hasNext()) {
                    count = itr.next();

                }

            } catch (Exception e) {
                throw new SystemException(e);
            } finally {
                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ENTRIES,
                        finderArgs, count);
                closeSession(session);
            }
        }else{
        }
        if (count != null) {
            return count.intValue();
        } else {
            return 0;
        }
    }

	public List<assetentry> findEntries(AssetEntryQuery entryQuery)
		throws SystemException {

        Object[] finderArgs = new Object[] {entryQuery};

        List<assetentry> list = (List<assetentry>)FinderCacheUtil.getResult(
                FINDER_PATH_FIND_ENTRIES, finderArgs, this);
        if (list != null) {
            return list;
        }


        Session session = null;

		try {
			session = openSession();

			SQLQuery q = buildAssetQuerySQL(entryQuery, false, session);

            list= (List<assetentry>)QueryUtil.list(
                    q, getDialect(), entryQuery.getStart(), entryQuery.getEnd());
		}
		catch (Exception e) {
			throw new SystemException(e);
		}
		finally {
            if (list == null) {
                FinderCacheUtil.removeResult(
                        FINDER_PATH_FIND_ENTRIES, finderArgs);
            }
            else {
                FinderCacheUtil.putResult(
                        FINDER_PATH_FIND_ENTRIES, finderArgs, list);
            }
			closeSession(session);
		}

        return list;
	}

......
}

</assetentry></assetentry></assetentry></assetentry></long></assetentry>


But after above change, portal performance will not changed! when I check cache hits, I understand that query parameters are changing in every execute! so it make ehcache to call DB and cache hits would be 0!
for solving this issue you should accept that expire date and publish date checks every hour not every millisecond! so make following as step 3:
3- change default constructor for AssetEntryQuery in this file: portal-service\src\com\liferay\portlet\asset\service\persistence\AssetEntryQuery.java

	public AssetEntryQuery() {
//		Date now = new Date();
        Calendar cal = CalendarFactoryUtil.getCalendar();
        cal.set(Calendar.MINUTE,0);
        cal.set(Calendar.MILLISECOND,0);
        cal.set(Calendar.SECOND,0);
		_expirationDate = cal.getTime();
		_publishDate = cal.getTime();
	}


That's All. enjoy from new asset publisher! I could not tell that it make liferay 100 times faster in all cases! but with 50,000 web content and 10 asset publisher in my home page the response time was 16 second!!!! and after above changes it was 10 millisecond!! it means 25000 times faster in my case.

Please do not forgot vote for this threat if it was useful.