2010-10-12 15 views
5

मेरे पास स्प्रिंग + हाइबरनेट का उपयोग कर जावा एप्लिकेशन है। मेरे पास एक बहुत ही सरल लेनदेन है जो हाल ही में निष्पादित करने के लिए वास्तव में लंबे समय तक शुरू करना शुरू कर दिया है (~ 25 सेकेंड) हालांकि यह कोई अस्पष्ट/जटिल प्रश्न नहीं बना रहा है, और लॉग के अनुसार, उन 25 सेकंड को हेबेरांटे के कोड में बिताया जाता है। ब्राउज़र सिर्फ वहाँ लटका हुआ है जब तक यह किया है इंतज़ार कर ...वसंत + हाइबरनेट लेनदेन में 25 सेकंड लगते हैं

लेन-देन हालांकि एनोटेशन किया जाता है, org.springframework.orm.hibernate3.LocalSessionFactoryBean सत्र कारखाने और org.springframework.orm.hibernate3.HibernateTransactionManager लेनदेन प्रबंधक के रूप में के रूप में इस्तेमाल करते हैं।

हाइबरनेट का कैश मैं Memcached उपयोग कर रहा हूँ के लिए, लेकिन यह कोई मुद्दा नहीं होना चाहिए, लॉग कम से कम इस बीच उसे कैश को छू नहीं कर रहा है के अनुसार ....

मैं यहाँ प्रासंगिक टुकड़ा प्रस्तुत TransactionSynchronizationManager |

[डीबग] [2010-10-09 @ 07:25:30] [http-8080-12:

[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|HibernateTransactionManager] Found thread-bound Session [[email protected]] for Hibernate transaction 
[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|HibernateTransactionManager] Using transaction object [org.springframework.orm.hi[email protected]35ca1808] 
[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|HibernateTransactionManager] Creating new transaction with name [com.quebicoca.api.service.PaymentService.buy]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT 
[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|HibernateTransactionManager] Preparing JDBC Connection of Hibernate Session [[email protected]] 
[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|HibernateTransactionManager] Exposing Hibernate transaction as JDBC transaction [[email protected]] 
[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|TransactionSynchronizationManager] Bound value [[email protected]] for key [[email protected]ca8b] to thread [http-8080-12] 
[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|TransactionSynchronizationManager] Initializing transaction synchronization 
[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|TransactionInterceptor] Getting transaction for [com.quebicoca.api.service.PaymentService.buy] 
[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|TransactionSynchronizationManager] Retrieved value [[email protected]] for key [[email protected]] bound to thread [http-8080-12] 
[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|HibernateTransactionManager] Found thread-bound Session [[email protected]] for Hibernate transaction 
[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|TransactionSynchronizationManager] Retrieved value [[email protected]] for key [[email protected]ca8b] bound to thread [http-8080-12] 
[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|HibernateTransactionManager] Using transaction object [org.springframework.orm.hi[email protected]36d0805f] 
[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|HibernateTransactionManager] Participating in existing transaction 
[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|TransactionInterceptor] Getting transaction for [com.quebicoca.api.service.PaymentService.buy] 
[DEBUG] [2010-10-09 @ 07:25:30] [http-8080-12|TransactionSynchronizationManager] Retrieved value [[email protected]] for key [[email protected]] bound to thread [http-8080-12] 
[DEBUG] [2010-10-09 @ 07:25:55] [http-8080-25|HashCodeKeyStrategy] Transformed key [UserOrder_holders] to hashCode [-1959252437] 
[DEBUG] [2010-10-09 @ 07:25:55] [http-8080-25|HashCodeKeyStrategy] Final cache key: [org.hibernate.cache.UpdateTimestampsCache:0:-1959252437] 
[DEBUG] [2010-10-09 @ 07:25:55] [http-8080-25|MemcachedCache] Memcache.set(org.hibernate.cache.UpdateTimestampsCache:0:-1959252437) 
[DEBUG] [2010-10-09 @ 07:25:55] [http-8080-25|SpyMemcache] MemcachedClient.set(org.hibernate.cache.UpdateTimestampsCache:0:-1959252437) 
... 
[DEBUG] [2010-10-09 @ 07:25:55] [http-8080-25|DispatcherServlet] Successfully completed request 
[DEBUG] [2010-10-09 @ 07:25:55] [http-8080-25|TransactionSynchronizationManager] Removed value [[email protected]] for key [[email protected]] from thread [http-8080-25] 
[DEBUG] [2010-10-09 @ 07:25:55] [http-8080-25|OpenSessionInViewFilter] Closing single Hibernate Session in OpenSessionInViewFilter 
[DEBUG] [2010-10-09 @ 07:25:55] [http-8080-25|SessionFactoryUtils] Closing Hibernate Session 
[DEBUG] [2010-10-09 @ 07:25:55] [http-8080-25|ExceptionTranslationFilter] Chain processed normally 
[DEBUG] [2010-10-09 @ 07:25:55] [http-8080-25|SecurityContextPersistenceFilter] SecurityContextHolder now cleared, as request processing completed 
[DEBUG] [2010-10-09 @ 07:25:56] [http-8080-12|TransactionSynchronizationManager] Retrieved value [[email protected]] for key [[email protected]] bound to thread [http-8080-12] 
[DEBUG] [2010-10-09 @ 07:25:56] [http-8080-12|TransactionSynchronizationManager] Retrieved value [[email protected]] for key [[email protected]] bound to thread [http-8080-12] 
[DEBUG] [2010-10-09 @ 07:25:56] [http-8080-12|HibernateTemplate] Found thread-bound Session for HibernateTemplate 
[DEBUG] [2010-10-09 @ 07:25:56] [http-8080-12|HashCodeKeyStrategy] Transformed key [UserOrder] to hashCode [-1966312925] 
[DEBUG] [2010-10-09 @ 07:25:56] [http-8080-12|HashCodeKeyStrategy] Final cache key: [org.hibernate.cache.UpdateTimestampsCache:0:-1966312925] 

आखिरी बात 25 सेकंड के अंतर से पहले लॉग इन किया है: लॉग का ] कुंजी [[email protected]] कुंजी के लिए पुनर्प्राप्त मूल्य [संगठन .hibernate.impl.SessionFactoryImpl @ c4be179] धागे से बंधे [http-8080-12]

मैं इस लॉग के दौरान केवल एक ही लॉग इन था, मैंने अपने आप को छोड़कर अपाचे से अलग होने के लिए सभी को बंद कर दिया बिलाव।

किसी भी विचार का स्वागत है।

संपादित करें:

जोड़ा मेरे आदेश वर्ग का अनुरोध के अनुसार:

@Entity 
@Table(name = "UserOrder") 
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 
public class Order { 

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private Long id; 

    @ManyToOne(optional = false) 
    private Deal deal; 
    @CollectionOfElements 
    private Map<String, Integer> holders; 
    @ManyToOne(optional = false) 
    private User user; 
    @org.hibernate.annotations.Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime") 
    @Column(nullable = false) 
    private DateTime buyingDate; 
    @Column(nullable = false) 
    @Enumerated(EnumType.STRING) 
    private OrderState state; 
    private BigDecimal payedWithUserCredit; 
    @Column(nullable = false) 
    private int quantity; 
    @Column(nullable = false) 
    private String secret; 

    private boolean mailSent; 

    @Enumerated(EnumType.STRING) 
    private PaymentMethod paymentMethod; 
} 

संपादित करें 2:

सुझाव Afeter जासूस Memcached मैं वापस ehcache जाने का फैसला करने के लिए कुछ हो सकता है।

यह और भी बदतर हो गया (1:16 लटका)। लॉग:

[DEBUG] [2010-10-13 @ 04:28:47] [http-8080-1|HibernateTransactionManager] Triggering beforeCommit synchronization 
[DEBUG] [2010-10-13 @ 04:28:47] [http-8080-1|HibernateTransactionManager] Triggering beforeCompletion synchronization 
[DEBUG] [2010-10-13 @ 04:28:47] [http-8080-1|HibernateTransactionManager] Initiating transaction commit 
[DEBUG] [2010-10-13 @ 04:28:47] [http-8080-1|HibernateTransactionManager] Committing Hibernate transaction on Session [[email protected]] 
[DEBUG] [2010-10-13 @ 04:30:03] [http-8080-1|HibernateTransactionManager] Triggering afterCommit synchronization 
[DEBUG] [2010-10-13 @ 04:30:03] [http-8080-1|HibernateTransactionManager] Triggering afterCompletion synchronization 
[DEBUG] [2010-10-13 @ 04:30:03] [http-8080-1|TransactionSynchronizationManager] Clearing transaction synchronization 
[DEBUG] [2010-10-13 @ 04:30:03] [http-8080-1|TransactionSynchronizationManager] Removed value [[email protected]] for key [[email protected]616] from thread [http-8080-1] 
[DEBUG] [2010-10-13 @ 04:30:03] [http-8080-1|HibernateTransactionManager] Not closing pre-bound Hibernate Session [[email protected]] after transaction 
[DEBUG] [2010-10-13 @ 04:30:03] [http-8080-1|TransactionSynchronizationManager] Retrieved value [[email protected]] for key [[email protected]] bound to thread [http-8080-1] 
[DEBUG] [2010-10-13 @ 04:30:03] [http-8080-1|DriverManagerDataSource] Creating new JDBC DriverManager Connection to [jdbc:mysql://localhost/quebicoca] 
[DEBUG] [2010-10-13 @ 04:30:03] [http-8080-1|TransactionSynchronizationManager] Retrieved value [[email protected]] for key [[email protected]] bound to thread [http-8080-1] 

मैं compeltely खो दिया हूँ ...

+0

लॉग संदेशों के पिछले काल की वजह से, मैं मान रहा हूं (शायद गलत तरीके से) जो सत्र धारक को उचित समय में पूरा कर रहा है। क्या UserOrder आपकी कक्षाओं में से एक है, और यदि ऐसा है, तो यह कैसा दिखता है? – Jeff

+0

जेफ: नहीं, 'लेनदेन सिंक्रनाइज़ेशन प्रबंधक' से वह संदेश पुनर्प्राप्त करने का अंत है। इसके अलावा मेमकैच भी एक मुद्दा हो सकता है क्योंकि 'हैशकोडकेसेस्ट्रेटी' हाइबरनेट-मेमकैड से एक कक्षा है। – axtavt

+0

मैंने जेफ के लिए ऑर्डर कोड जोड़ा। उम्मीद है कि इस मुद्दे में कुछ प्रकाश डाला जाएगा .... – Johnco

उत्तर

2

यह पता चल!

@Transactional विधि में यह कर मैं कुछ इस तरह करना होगा:

orderDAO.save(order); 
user.addOrder(order); 

तो आदेश बचाया जाएगा, और आदेश के उपयोगकर्ता के सेट करने के लिए जोड़ा।

जब सहेजने के लिए कहा गया था, आदेश के लिए डालने रखा गया था, लेकिन धारक के लिए नहीं।

विधि से बाहर निकलने पर, हाइबरनेट सत्र में सभी मॉडलों पर जायेगा ताकि यह देखने के लिए कि और क्या जारी रखने की आवश्यकता है (जो केवल UserOrder_holder को इंगित करना चाहिए)। ऐसा लगता है कि यह उपयोगकर्ता के आदेशों के साथ इसे समझने की कोशिश कर रहा है, और संबंधित सौदे (जिनमें से अधिकांश अलग-अलग आदेशों में दोहराए जाते हैं)। और मैं एक विशाल डेटाबेस के बारे में बात नहीं कर रहा हूं, ऑर्डर पुनर्प्राप्त करने के लिए उपयोग की जाने वाली क्वेरी डेटाबेस से 17 पंक्तियां वापस कर देगी ... यह सिर्फ लंगड़ा है।

वैसे भी, ऑर्डर के डील आलसी के संबंध में इस मुद्दे को हल करने के लिए, कम से कम अब तक, टी अधिक ऑर्डर के साथ बाद में पुनरुत्थान कर सकता है।

संबंधित मुद्दे