Spring batch - mise en place de listener pour évaluer le temps passé

602 views
Skip to first unread message

sami44

unread,
Sep 14, 2010, 7:21:10 AM9/14/10
to Spring User Group France
Bonjour,

J'ai mis en place un batch en spring batch composé de 8 steps.
Je souhaitais évaluer le temps passé dans chaque step, j'ai utilisé
pour ce faire un listener qui implémente l'interface
StepExecutionListener.

Cela fonctionne bien mais je souhaiterais maintenant évaluer pour
chaque step :
- le temps passé dans le reader
- le temps passé dans le process
- le temps passé dans le writer

J'ai mis en place toute une série de listener supplémentaire qui
implémentent les interfaces :
- ChunkListener
- ItemReadListener
- ItemProcessListener
- ItemWriteListener

Malheureusement, à l'exécution je n'arrive pas à récupérer ce qui
m'intéresse :
- Le listener sur les chunk renvoie un temps entre before et after = 0
secondes
- Le listener sur les reader renvoie un temps entre before et after =
0 secondes
- Le listener sur les process renvoie un temps entre before et after =
0 secondes
- Le listener sur les writer n'est jamais appelé.


Exemple de logs récupérés lors de l'exécution du step "step0"

DEBUG;2010-09-14 13:17:01,823;MODELE;;;;E;step [step0];before;
DEBUG;2010-09-14 13:17:01,964;MODELE;;;;E;chunk;before;
DEBUG;2010-09-14 13:17:01,964;MODELE;;;;E;reader;before;
DEBUG;2010-09-14 13:17:01,964;MODELE;;;;E;reader;after;0.0s
DEBUG;2010-09-14 13:17:01,964;MODELE;;;;E;chunk;after;0.0s
DEBUG;2010-09-14 13:17:02,011;MODELE;;;;E;step [step0];after;0.047s

Par quel moyen puis je loguer les temps passé pour les reader, le
processor, le writer ?

Cordialement,

Samuel

Pascal GASP

unread,
Sep 14, 2010, 7:49:59 AM9/14/10
to su...@googlegroups.com
Bonjour samuel, 
peux tu fournir ton fichier de configuration de ton job 
Cdlt
Pascal

Manu

unread,
Sep 14, 2010, 8:00:50 AM9/14/10
to su...@googlegroups.com
Tu es peut être victime de l'effet Windows XP.
Sous windows xp, si le temps écoulé est inférieur à 15ms, le temps que tu calculeras sera souvent de 0ms.
Je crois mais sans avoir testé que cette limitation disparait sous Windows 7.

Exemple :
long start = System.currentTimeMillis();
// Traitement rapide < 15 ms mais qui ne prend pas 0 ms
long end = System.currentTimeMillis();
System.out.println(end - start + " ms");

Ce code t'affichera la plupart du temps 0 ms.
C'est peut être l'explication de tes temps.

Il faut peut être englober plus de traitement entre tes prises de mesures pour avoir des mesures plus pertinentes.

My 2 cents.
Manuel

2010/9/14 sami44 <samuel....@gmail.com>

sami44

unread,
Sep 14, 2010, 10:39:22 AM9/14/10
to Spring User Group France
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

<import resource="classpath*:ams/rf/beans-definitions.xml" />

<bean id="transactionManager"

class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:database.properties</value>
</list>
</property>
</bean>

<!-- the transactional advice (i.e. what 'happens'; see the
<aop:advisor/> bean below) -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- the transactional semantics... -->
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="get*" read-only="true"
propagation="REQUIRED" rollback-for="AbstractRgpException" />
<!-- other methods use the default transaction settings (see below)
-->
<tx:method name="*" propagation="REQUIRED" />
<!-- <tx:method name="*" propagation="REQUIRED" rollback-
for="AbstractRgpException"/>-->
</tx:attributes>
</tx:advice>

<!-- ensure that the above transactional advice runs for any
execution
of an operation defined by the FooService interface -->
<aop:config>
<aop:pointcut id="TxAdvicePointCut"
expression="execution(* fr.rgp.rf..*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="TxAdvicePointCut" />
</aop:config>


<bean id="jobLauncher"

class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>

<bean id="jobRepository"

class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>
<!--


<job id="job" restartable="false"
xmlns="http://www.springframework.org/schema/batch">

</job>-->

<job id="hibernateJob" restartable="false"
xmlns="http://www.springframework.org/schema/batch">

<step id="step1">
<tasklet>
<listeners>
<listener ref="logStepListener"></listener>
<listener ref="logChunkListener"></listener>
<listener ref="logReaderListener"></listener>
<listener ref="logProcessListener"></listener>
<listener ref="logWriterListener"></listener>
</listeners>
<chunk reader="hibernateAutomatePollePlusReader"
processor="automatePollePlusProcessor" writer="hibernateWriter"
commit-interval="3">
</chunk>
</tasklet>
<next on="*" to="step2" />
<fail on="FAILED" exit-code="FAILED" />
</step>

[...]
</job>

[...]


<!-- Listener pour connaître les temps de traitement sur chaque step
-->
<bean id="logStepListener"
class="fr.rgp.listener.LogStepExecutionListener">
</bean>

<!-- Listener sur reader -->
<bean id="logReaderListener"
class="fr.rgp.listener.LogReaderListener">
</bean>

<!-- Listener sur process -->
<bean id="logProcessListener"
class="fr.rgp.listener.LogProcessListener">
</bean>

<!-- Listener sur writer -->
<bean id="logWriterListener"
class="fr.rgp.listener.LogWriterListener">
</bean>

<!-- Listener chunk (peut-être pas utile) -->
<bean id="logChunkListener"
class="fr.rgp.listener.LogChunkListener">
</bean>

</beans>

sami44

unread,
Sep 14, 2010, 10:39:55 AM9/14/10
to Spring User Group France
On 14 sep, 13:49, Pascal GASP <pascal.g...@gaspelie.fr> wrote:
> Bonjour samuel,
> peux tu fournir ton fichier de configuration de ton job
> Cdlt
> Pascal
>
Reply all
Reply to author
Forward
0 new messages