You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ignite.apache.org by "Yaroslav Molochkov (Jira)" <ji...@apache.org> on 2020/12/31 08:41:00 UTC

[jira] [Commented] (IGNITE-12508) GridCacheProcessor#cacheDescriptor(int) has O(N) complexity

    [ https://issues.apache.org/jira/browse/IGNITE-12508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17256892#comment-17256892 ] 

Yaroslav Molochkov commented on IGNITE-12508:
---------------------------------------------

[~ivan.glukos], hello! Couldn't help but notice that cache descriptors are stored in map as <String, DynamicCacheDescriptor>. In essence, we use hash code as a crude map key here:
{code:java}
if (CU.cacheId(ccfg.getName()) == cacheId)
                return cacheDesc; {code}
I suppose that's not entirely correct.

Consider the following snippet:
{code:java}
@Test
public void testCacheProcessor() {
    IgniteEx ignite = grid(2);

    String startedCache = "AaAaAa";
    String assertedCache = "AaAaBB";
    
    ignite.getOrCreateCache(startedCache);

    GridCacheProcessor processor = ignite.context().cache();
    DynamicCacheDescriptor dynamicCacheDescriptor = processor.cacheDescriptor(CU.cacheId(assertedCache));

    assertEquals(assertedCache, dynamicCacheDescriptor.cacheName());
} {code}

I 


> GridCacheProcessor#cacheDescriptor(int) has O(N) complexity
> -----------------------------------------------------------
>
>                 Key: IGNITE-12508
>                 URL: https://issues.apache.org/jira/browse/IGNITE-12508
>             Project: Ignite
>          Issue Type: Bug
>            Reporter: Ivan Rakov
>            Assignee: kartheek b
>            Priority: Major
>              Labels: newbie
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> See the method code:
> {code}
>     @Nullable public DynamicCacheDescriptor cacheDescriptor(int cacheId) {
>         for (DynamicCacheDescriptor cacheDesc : cacheDescriptors().values()) {
>             CacheConfiguration ccfg = cacheDesc.cacheConfiguration();
>             assert ccfg != null : cacheDesc;
>             if (CU.cacheId(ccfg.getName()) == cacheId)
>                 return cacheDesc;
>         }
>         return null;
>     }
> {code}
> This method is invoked in several hot paths which causes significant performance regression when the number of caches is large, for example, logical recovery and security check for indexing.
> The method should be improved to use a hash map or similar data structure to get a better complexity



--
This message was sent by Atlassian Jira
(v8.3.4#803005)