留言板

Message bus performances

Fabio De Pra,修改在9 年前。

Message bus performances

New Member 帖子: 24 加入日期: 13-11-4 最近的帖子
Ciao a tutti,
sto utilizzando lo scambio messaggi via Message Bus.

Ho notato una certa lentezza nell'utilizzo dei messaggi sincroni.
L'ordine è di 10 secondi per la ricezione della risposta.
Tenuto conto che questo dato è relativo al mio pc di sviluppo che non è un missile mi sembrano comunque tanti se utilizzato in una jsp.

Mettendo qualche log ho verificato che il rallentamento più evidente è nell'invio della risposta al richiedente.

Qualcuno ha qualche idea per intervenite nei tempi di risposta?

Di seguito i sorgenti e il risultato del log.

Codice della richiesta al message bus racchiuso tra il trace principale

try {
            if (log.isTraceEnabled()) log.trace("products/util/systemsforselect start");
            String jsonResponse = (String) MessageBusUtil.sendSynchronousMessage("products/util/systemsforselect", message);
            if (log.isTraceEnabled()) log.trace("products/util/systemsforselect end");
            
           .....
            
        } catch (MessageBusException e) {
            log.error(e);
        }


Metodo del listener che gestisce la richiesta

private void handleSystemsForSelectRequest(Message message) {
        if (_log.isTraceEnabled()) _log.trace("ProductsUtilListener.handleSystemsForSelectRequest start");
        String localeString = message.getString("locale");
        
        JSONArray systemsJsonArray = JSONFactoryUtil.createJSONArray();
        
        if (localeString != null) {
            Locale locale = LocaleUtil.fromLanguageId(localeString);
        
            try {
                List<object[]> systemsData = ProductTreeLocalServiceUtil.findProductTreeLevelOne(locale, ProductsUtil.LEVEL_SYSTEMS_ID);
                
                if (systemsData != null &amp;&amp; systemsData.size() &gt; 0) {
                    if (_log.isTraceEnabled()) _log.trace("ProductsUtilListener.handleSystemsForSelectRequest for start");
                    for (Object[] rowData : systemsData) {
                        BigInteger treeLevelId = (BigInteger) rowData[0];
                        String name = (String) rowData[1];
                        String erpExternalId = "0";
                        try {
                            ProductTreeLevel productTreeLevel = ProductTreeLevelLocalServiceUtil.getProductTreeLevel(treeLevelId.longValue());
                            if (_log.isTraceEnabled()) _log.trace("ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load");
                            
                            if (productTreeLevel != null) {
                                erpExternalId = productTreeLevel.getErpExternalId();
                            }
                        } catch (PortalException e) {
                            // non gestito: viene sollevato se non viene trovato i livello
                        }
                        
                        // Costruzione oggetto JSON
                        JSONObject rowJson = JSONFactoryUtil.createJSONObject();
                        rowJson.put("treeLevelId", treeLevelId.longValue());
                        rowJson.put("name", name);
                        rowJson.put("erpExternalId", erpExternalId);
                        systemsJsonArray.put(rowJson);
                    }
                    if (_log.isTraceEnabled()) _log.trace("ProductsUtilListener.handleSystemsForSelectRequest for end");
                }
                
            } catch (SystemException e) {
                _log.error("handleSystemsForSelectRequest SystemException", e);
            }
            
            String responseString = systemsJsonArray.toString();
            Message responseMessage = MessageBusUtil.createResponseMessage(message);
            
            responseMessage.put("data", responseString);
            responseMessage.setPayload(responseString);

            MessageBusUtil.sendMessage(responseMessage.getDestinationName(), responseMessage);
        }
        
        if (_log.isTraceEnabled()) _log.trace("ProductsUtilListener.handleSystemsForSelectRequest end");
        
    }</object[]>


Dal log si vede che il rallentamento è dalla fine dell'esecuzione del metodo del listener e la ricezione effettiva nel chiamante (ultime due righe del log)

09:33:14,629 TRACE [http-bio-80-exec-43][AlgoritmaUtil:725] products/util/systemsforselect start
09:33:14,630 TRACE [http-bio-80-exec-43][ProductsUtilListener:42] ProductsUtilListener.receive message received
09:33:14,631 DEBUG [http-bio-80-exec-43][ProductsUtilListener:61] destinationName=products/util/systemsforselect
09:33:14,631 TRACE [http-bio-80-exec-43][ProductsUtilListener:91] ProductsUtilListener.handleSystemsForSelectRequest start
09:33:14,646 TRACE [http-bio-80-exec-43][ProductsUtilListener:103] ProductsUtilListener.handleSystemsForSelectRequest for start
09:33:14,657 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,660 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,662 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,663 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,665 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,667 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,671 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,673 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,675 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,676 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,678 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,680 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,682 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,684 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,686 TRACE [http-bio-80-exec-43][ProductsUtilListener:110] ProductsUtilListener.handleSystemsForSelectRequest productTreeLevel load
09:33:14,687 TRACE [http-bio-80-exec-43][ProductsUtilListener:126] ProductsUtilListener.handleSystemsForSelectRequest for end
09:33:14,687 TRACE [http-bio-80-exec-43][ProductsUtilListener:142] ProductsUtilListener.handleSystemsForSelectRequest end
09:33:24,689 TRACE [http-bio-80-exec-43][AlgoritmaUtil:727] products/util/systemsforselect end
Walter Tommasi,修改在9 年前。

RE: Message bus performances

New Member 发布: 1 加入日期: 12-10-31 最近的帖子
Ciao Fabio
la destinazione "products/util/systemsforselect" di che tipo è ?
Se è una SynchronousDestination un workaround è quello di invocare il metodo sendSynchronousMessage con un valore di timeout basso tipo 1 altrimenti al tempo di risposta del tuo listener sarà aggiunto anche il timeout di default ovvero di 5000 ms.
Fabio De Pra,修改在9 年前。

RE: Message bus performances

New Member 帖子: 24 加入日期: 13-11-4 最近的帖子
Ciao Walter,
si la destinaizone è sincrona.
Inizialmente avevo messo un timeout di 10000ms e poi l'ho tolto perchè pensavo fosse quello che rallentava la risposta.

Provo il tuo suggerimento.

Grazie per la dritta!

Fabio
Fabio De Pra,修改在8 年前。

RE: Message bus performances

New Member 帖子: 24 加入日期: 13-11-4 最近的帖子
Walter Tommasi:
Ciao Fabio
la destinazione "products/util/systemsforselect" di che tipo è ?
Se è una SynchronousDestination un workaround è quello di invocare il metodo sendSynchronousMessage con un valore di timeout basso tipo 1 altrimenti al tempo di risposta del tuo listener sarà aggiunto anche il timeout di default ovvero di 5000 ms.


Ciao Walter,
con un po' di ritardo ;-) ti confermo che con la tua dritta funziona.

Grazie!

Fabio