Blog

SAP Commerce Cloud (Hybris) Performance: Issues and Recommendations for Improving

 

Outdated patches, expired promotions, and memory-eating cluster-aware events are pests specific to SAP Commerce Cloud platforms. Along with some more common inefficiencies, they hinder system performance, leading to lost sales and decreased customer satisfaction. 

Consider this: 79% of users who are dissatisfied with site performance are less likely to return. This highlights how vital a fast and responsive platform is for retaining users.

Expert Soft clients recognize this need as well, and that’s why improving performance is a key SAP Commerce (Hybris) e-commerce development task that our team tackles. In this article, we’ve gathered effective recommendations to solve SAP Commerce (SAP Hybris) performance issues, based on our work with a client — a global manufacturer and seller of medical equipment.

Note that the tips provided below are arranged in decreasing order of their impact on system performance. However, we recommend applying them comprehensively to achieve maximum performance optimization.

 

Utilize the Latest SAP Commerce Cloud Patch

Despite how obvious it may seem, outdated patches are the first factor that can hinder your system’s performance. 

Every month, SAP releases new SAP Commerce patches that address issues related to security, performance, compatibility, and more. For detailed information on each patch fix, you can explore this page

So, it may occur that some SAP Commerce (SAP Hybris) performance issues that you’re suffering from have already been resolved in a newer patch version. In this case, updating your system can provide the necessary improvements.  

Regular implementation of updated patches not only improves SAP Commerce Cloud performance but also enhances security, ensuring your platform is protected against vulnerabilities.

However, be careful and thoroughly test patches in a staging environment before applying them to the production to ensure compatibility. Also, we recommend keeping detailed records of all patches applied for better system diagnosing and change monitoring if any issues arise.

 

Do Proper Profiling to Identify Performance Issues

Comprehensive profiling allows developers to identify performance bottlenecks, memory leaks, and inefficient code paths and make targeted improvements for SAP Commerce (Hybris) performance tuning.

When we optimized the performance of the client’s platform, we paid special attention to:

  • Load testing

  • Memory analysis

  • CPU usage

  • Thread analysis

Load testing

Using tools such as Apache JMeter, we simulated varying load intensities on the SAP Commerce (SAP Hybris) platform to identify how it scales. Testing highlighted areas with prolonged execution times or failures in load handling, which we then addressed for improvements.

Load testing along with performance testing should be a continuous process, especially after significant changes to the platform, to ensure consistent performance under different conditions.

Memory analysis

Memory analysis involves monitoring heap usage and identifying memory leaks, including excessive garbage collection.

Let’s see how this works on the SAP Commerce Drools engine. The engine creates numerous short-lived objects during rule evaluations, increasing memory consumption. If not managed properly, these objects trigger frequent garbage collection cycles, further impacting SAP Commerce Cloud performance

To reduce performance impact caused by memory leaks, you can implement caching. It allows for storing part of evaluations in memory, instead of triggering a full evaluation each time. For example, if the same user views the same product multiple times, the cached price can be served immediately. This reduces repeated rule evaluations and improves response times, which eases pressure on the garbage collector.

CPU usage

Regular checking of CPU load helps timely reduce its usage, not slowing down your system. In SAP Commerce platforms, common causes of high CPU load include:

  • Hotspots

    These are methods or operations consuming excessive CPU resources. You can find them in JProfile under “Hot Spots” and then optimize the identified code to reduce CPU load.

  • Recursive calls

    Ensure recursive functions have well-defined base cases to prevent infinite recursion. Where feasible, convert recursive algorithms to iterative ones, as iteration often uses less CPU.

  • Inefficient loops

    The solution here is to implement break statements to exit loops early when conditions are met, reducing unnecessary iterations.

Monitoring CPU usage regularly and addressing spikes can prevent performance degradation and ensure smoother operation.

Thread analysis

Thread contention and deadlocks occur when different threads compete for the same resources. To prevent this, you can use thread pools to manage the number of active threads and avoid excessive thread creation. You should also monitor thread pools to ensure they are correctly sized.

 

Optimize SAP Commerce Database Queries

While your platform is in constant communication with databases, long and unoptimized queries lead to delays in data retrieval and increased response times. The main goal is to minimize the number of database queries and ensure they are executed efficiently.

Here are some best practices that we implement on our projects and suggest doing constantly if you aim to enhance SAP Commerce (former SAP Hybris) performance:

  • Turn on JDBC logs, find the most frequent DB queries, and check if there is a way to reduce their number.
  • Avoid localized attributes where regular attributes are suitable, as many database queries may refer to localized attributes and increase load times.
  • Optimize slow queries by adding indexes, rewriting queries, or denormalizing tables.
  • Ensure efficient use of database connections and improved session handling.
  • Optimize queries to avoid the N+1 query problem, when the data access layer executes N additional queries to fetch the same data that could have been retrieved when executing the primary query. 
  • Cache the results of frequently executed queries to reduce the load on the database.

 

Streamline SAP Commerce Performance with Transactions

This point complements the previous one, as one of the best practices for working with databases is to reduce the number of queries. And transactions are an effective way to achieve this. 

By grouping persistence operations, transactions reduce database updates, especially if Jalo is used. Transactions also ensure adherence to the A.C.I.D. (atomicity, consistency, isolation, and durability) principles, making your code more efficient.

Let’s look at an example. 

final CartModificationData cartModification = cartFacade.addToCart(code, qty);

Could you guess how many database calls the out-of-the-box card facade for ‘Add To Cart’ can produce outside a transaction? This simple and very common operation can make about 70 calls to the database, with more than 10 commit calls among them! You can explore a detailed database call listing here.

Where does the problem lie? SAP Commerce (Hybris) invalidates the item’s cache entry whenever an item is saved. This means the item is retrieved from the database again, even if it’s needed in the next line of code. In our example, the system not only adds a new item to the cart but also recalculates the cart total, applies promotions, and more. All of this is followed by model cache invalidation and updating model modification history, causing significant overhead.

Let’s try to fix this by adding a transaction.

boolean success = false;
Transaction tx = Transaction.current();
tx.begin();
try {
final CartModificationData cartModification = cartFacade.addToCart(code, qty);
success = true;
} finally {
if (success) {
tx.commit();
} else {
tx.rollback();
}
}

By wrapping this method in a transaction, you can reduce the number of database calls from 70+ to around 20-30, avoiding numerous commits! On average, this can speed up code execution by 1.5-10 times, depending on the operation and system load. 

Be cautious, though: if multiple transactions try to update the same items, this can lead to database locks. Other transactions will have to wait for the commit/rollback of the transaction that managed to update the row first. This frequently happens with many-to-many relations in SAP Commerce. For example, if a new user is created and added to some user group, the system will send a request to change this group’s modifiedtime field, locking the row in the database. You can tweak this behavior by using properties.

# E.g. to disable marking the usergroup item if you add/remove a user to/from this group, you have to uncomment the following line: #relation.PrincipalGroupRelation.markmodified=false

 

Clean up Expired Promotions that Hinder Performance

How often do you create short-term or seasonal promotions with specific end dates? And how often do you remove expired ones?

Within a promotion, the system also creates and accumulates drool rules and promotion source rules, taking up memory. So, are you sure that expired promotions from 2021 are not unnecessarily loading your platform?

Even though these promotions are no longer relevant, they are not automatically removed from Drools engine memory and can still participate in calculations. Functionally, these rules don’t affect the final result, but they still increase the CPU load.

Therefore, proper cleanup is required. On our projects, we perform such cleanups periodically, freeing up additional system capacity.

To make this process efficient, you can implement automated cleanup jobs that run at scheduled intervals to remove expired promotions and associated rules. Custom cleanup scripts tailored to your unique business logic and operational requirements might also be helpful.

Additionally, instead of deleting expired promotions outright, consider archiving them to a separate data store. This preserves historical data for analytics and reporting without burdening the main system. Once the number of expired promotions exceeds a threshold, it should trigger timely cleanups.

 

Monitor SAP Commerce Cluster-aware Events for Memory Leaks

Cluster-aware events help keep different nodes in a distributed SAP Commerce system synchronized. However, if not managed properly, these events can lead to memory leaks, severely impacting SAP Commerce Cloud performance.

Events often carry large amounts of data that should be deserialized. This process itself eats up many resources, and when there is a lot of data, it consumes even more. Additionally, all data is loaded into memory, further increasing its utilization.

When cluster-aware events are not efficiently handled, they tend to accumulate in memory, especially in high-frequency event environments. This increases garbage collection cycles, further degrading SAP Commerce (former SAP Hybris) performance.

To mitigate these issues, you can implement filtering mechanisms to ensure that only necessary events are distributed across the cluster, carrying only required attributes. For example, instead of sending events with the entire Order model, include only the key data needed by the nodes.

Regularly monitoring and adjusting these settings will help maintain a balanced load on your system and prevent performance degradation over time.

 

Avoid Unnecessary Exceptions

Exceptions might seem less critical for performance, but optimizing them can boost your SAP Commerce platform’s efficiency when combined with other improvement strategies.

Exceptions help adjust the system operation when exceptional or unforeseen situations occur. During the system run, there can be many such instances. For example, during load testing, when many users try to access the system, more than 60K exceptions can occur within 2-3 minutes.

Some of them arise automatically, but developers also introduce some through the code. These are the instances you should optimize. Frequent or unhandled exceptions consume resources and can lead to slower response times and increased system load.

When an exception is thrown, the system must halt the current execution, handle the exception, and often perform additional logging. This process is resource-intensive, especially if exceptions occur frequently.

So, the goal is to reduce the number of exceptions by avoiding them in places where other alternatives are available or where normal program flow is expected. 

For example, if you want to find a user with a certain name in the database, not finding such a user is not an exceptional case but a normal scenario. Using an exception here would be a mistake, accumulation of which would overload the system. As the name implies, exceptions should be used for truly exceptional conditions, not for regular control logic.

Besides reducing unnecessary exceptions, we advise implementing thorough handling to ensure that all issues are caught and managed appropriately. This includes cleaning up resources and providing meaningful error messages without overloading the system with logging. 

These measures not only improve performance but also enhance system stability and reliability.

 

Conclusion

Improving SAP Commerce (former SAP Hybris) performance requires a comprehensive and systematic approach at various levels to achieve significant results. We especially advise paying attention to the strategies that apply specifically to SAP Commerce systems. While profiling, transactions, and queries optimization apply to any Java project, monitoring promotions and cluster-aware events are particularly crucial for SAP Commerce (Hybris) performance tuning.

As mentioned at the beginning of the article, all these practices we implemented on our customer’s project. So, let’s see what exactly we’ve done and how this has affected the client’s system.

One of the objectives of a global medical technology company was to enhance system performance and improve user experience. The primary SAP Commerce (Hybris) performance issues included prolonged website loading times, increased end-to-end latency, and a high volume of database queries during the order process. 

To address these challenges, our team implemented a series of targeted solutions:

  • reducing database queries from thousands to a few hundred per order;
  • establishing profiling;
  • analyzing and cleaning up expired promotions;
  • minimizing the use of exceptions for regular control flow;
  • optimizing the performance of the backoffice and storefront.

These measures reduce website loading times and enhance overall system stability and reliability. Facing similar challenges? Contact us to learn more about how you can improve your SAP Commerce performance

Contact Us

All submitted information will be kept confidential
MARY MAKARENKOVA
MARY MAKARENKOVA
Head of Client Relations & Customer Success