数据结构中名称空间和祖先之间的区别

时间:2018-06-27 00:02:38

标签: go google-cloud-datastore datastore

两者之间的区别是什么

// MockitoJUnitRunner, MockitoRule, or MockitoAnnotations.initMocks populate these.
// Especially useful for the ArgumentCaptor's generic arguments.
@Mock Jdbi mockJdbi;
@Mock OrgUnitDao mockOrgUnitDao;
@Captor ArgumentCaptor<ExtensionConsumer<OrgUnitDao, RuntimeException>>
    extensionConsumerCaptor;

@Test public void yourTest() throws Exception {
  // No stubbing needed! Just create the system under test.
  YourSystemUnderTest systemUnderTest = new YourSystemUnderTest(mockJdbi);

  // Call the method under test, which presumably calls useExtension(...).
  systemUnderTest.methodUnderTest();

  // Assert anything that should be true before the lambda is called.
  assertFalse(systemUnderTest.getSomeState());

  // Confirm that useExtension was called, and simultaneously acquire the lambda.
  // ArgumentCaptor.capture() is a matcher, so every argument requires a matcher like eq.
  verify(mockJdbi).useExtension(eq(OrgUnitDao.class), extensionConsumerCaptor.capture());

  // Prepare the mock DAO and call the lambda.
  when(mockDao.getFoo()).thenReturn("bar");
  extensionConsumerCaptor.getValue().useExtension(mockDao);

  // Assert anything that should be true after the lambda is called.
  assertTrue(systemUnderTest.getSomeState());
}

key := datastore.NameKey("user", userID, nil)
client.Put(ctx,datastore.IncompleteKey("session",key),&sessionUser)

如果它们的写入/读取相同,可能会导致contention,为什么它们会有所不同 从这个article

  

Cloud Datastore将名称空间和根实体组的类型添加到Bigtable行键中。如果您开始写入新的名称空间或种类而又没有逐渐增加流量,则会遇到一个热点。

我真的很困惑应该如何压缩我的数据, 顺便问一下,其中哪个阅读速度更快?

1 个答案:

答案 0 :(得分:0)

不同之处在于,如果需要,您提到的名称空间争用拐角处的情况只是一个短暂的情况(从根本原因的角度来看),等效于this one

  

...

     

如果您以很高的速率创建新实体,   以前只有很少的现有实体。大表将开始   与所有实体位于同一台平板电脑服务器上,这将需要一些时间   将密钥范围划分到单独的平板电脑服务器上。

     

...

该过渡仅持续到发生足够的数位板拆分以跟上写入操作速率为止。对于您引用的情况,逐渐增加的流量会给这些拆分带来时间,以免发生错误,从而避免出现问题。即使没有逐步增加,争用也可能只发生在分裂发生之前,然后分裂消失。

另一方面,使用血统会带来另一种永久性问题。共享相同血统的所有实体都位于同一实体组中,因此每个实体组速率每秒共享的最大写数为1。小组越大,争用的风险越高。使用与祖先无关的实体(具有或不具有命名空间)可以有效地创建一个实体组,该实体组的大小为1-这种类型的争用最少。

因此,除非您确实非常需要该血统,否则如果您的预期使用方式有争用的余地,我建议您避免使用它。

旁注:该文章仅涉及写争用,但您应注意,争用也可能在读取时发生(在事务中),请参见Contention problems in Google App Engine。在这种情况下,实体组的大小很重要,并且事务尝试锁定整个实体组。

相关问题