Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #8 Add ScopeLink benchmarks #13

Merged
merged 6 commits into from
Jun 1, 2018

Conversation

vsbogd
Copy link
Contributor

@vsbogd vsbogd commented May 30, 2018

Issue #8

I have added benchmarks for creating and adding ScopeLink into atomspace. I have added same EvaluationLink tests to compare performance.

(0) Benchmark results (atomspace and cogutil debug versions) see release results below in comment #13 (comment):

$ ./atomspace/atomspace/benchmark
2018-05-30 18:30:47
Running ./atomspace/atomspace/benchmark
Run on (12 X 4000 MHz CPU s)
CPU Caches:
  L1 Data 32K (x6)
  L1 Instruction 32K (x6)
  L2 Unified 256K (x6)
  L3 Unified 12288K (x1)
-----------------------------------------------------------------------------
Benchmark                                      Time           CPU Iterations
-----------------------------------------------------------------------------
BM_CreateScopeLinkWithVariableList          5127 ns       5127 ns     132751
BM_CreateScopeLinkWithoutVariableList       3669 ns       3669 ns     192123
BM_CreateScopeLinkWithLambdaLink            2925 ns       2925 ns     232632
BM_AddSameScopeLink                        12310 ns      12310 ns      56377
BM_AddScopeLink/65536                      29296 ns      29296 ns      23745
BM_CreateEvaluationLink                     1405 ns       1405 ns     487478
BM_AddSameEvaluationLink                    4865 ns       4865 ns     145954
BM_AddEvaluationLink/65536                 10993 ns      10993 ns      62096

(1) I have used Google Benchmark to create this stuff but it can be discussed.
Pros:

  • benchmark code and benchmark tooling are separated - we can separate benchmark code and tools in atomspace_bm as well but it may be simpler to use well known already implemented tool
  • library is actively maintained and has some community around it

Contras:

  • new format of results representation - it requires diary.txt results transition and I am not sure it is handful for others
  • Google Benchmark is not present in Ubuntu repository so it should be installed by hand but installation process is not that hard and have no other dependencies

(2) I have found comparing BM_AddSameScopeLink and BM_AddSameEvaluationLink profiles that main additional complexity for ScopeLink adding is copying ScopeLink. It leads to second ScopeLink.init() method call which is heavy.

BM_AddSameScopeLink profile:

      - 83,87% _ZL19BM_AddSameScopeLinkRN9benchmark5StateE                                           ▒
         - 83,80% _ZN7opencog9AtomSpace8add_atomERKNS_6HandleEb                                      ▒
            - 78,35% _ZN7opencog9AtomTable3addESt10shared_ptrINS_4AtomEEb                            ▒
               - 46,39% _ZN7opencog10createLinkIJRSt6vectorINS_6HandleESaIS2_EERtEEES2_DpOT_         ▒
                  - 36,55% _ZNK7opencog11ClassServer7factoryERKNS_6HandleE                           ▒
                     - 36,23% _ZN7opencog9ScopeLink7factoryERKNS_6HandleE                            ▒
                        - 33,79% _ZSt11make_sharedIN7opencog9ScopeLinkEJRKSt6vectorINS0_6HandleESaIS3▒
                           - 33,60% _ZSt15allocate_sharedIN7opencog9ScopeLinkESaIS1_EJRKSt6vectorINS0▒
                              - 33,43% _ZNSt10shared_ptrIN7opencog9ScopeLinkEEC2ISaIS1_EJRKSt6vectorI▒
                                 - 33,36% _ZNSt12__shared_ptrIN7opencog9ScopeLinkELN9__gnu_cxx12_Lock▒
                                    - 23,29% _ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC2IN▒
                                       - 22,56% _ZNSt23_Sp_counted_ptr_inplaceIN7opencog9ScopeLinkESa▒
                                          - 22,30% _ZNSt16allocator_traitsISaIN7opencog9ScopeLinkEEE9▒
                                             - 22,19% _ZN9__gnu_cxx13new_allocatorIN7opencog9ScopeLin▒
                                                - 22,07% _ZN7opencog9ScopeLinkC2ERKSt6vectorINS_6Hand▒
                                                   + 18,55% _ZN7opencog9ScopeLink4initEv             ▒
                                                   + 1,41% _ZN7opencog4LinkC2ERKSt6vectorINS_6HandleE▒
                                                   + 1,39% _ZN7opencog9VariablesC2Ev (inlined)       ▒
                                                     0,52% _ZN7opencog9ScopeLink9skip_initEt         ▒

BM_AddSameEvaluationLink profile:

   - 88,48% _ZL24BM_AddSameEvaluationLinkRN9benchmark5StateE                                         ▒
      - 88,44% _ZN7opencog9AtomSpace8add_atomERKNS_6HandleEb                                         ▒
         - 82,46% _ZN7opencog9AtomTable3addESt10shared_ptrINS_4AtomEEb                               ▒
            - 32,87% _ZN7opencog10createLinkIJRSt6vectorINS_6HandleESaIS2_EERtEEES2_DpOT_            ▒
               - 17,07% _ZNK7opencog11ClassServer7factoryERKNS_6HandleE                              ▒
                  - 16,54% _ZN7opencog8FreeLink7factoryERKNS_6HandleE                                ▒
                     - 12,09% _ZSt11make_sharedIN7opencog8FreeLinkEJRKSt6vectorINS0_6HandleESaIS3_EEt▒
                        - 11,88% _ZSt15allocate_sharedIN7opencog8FreeLinkESaIS1_EJRKSt6vectorINS0_6Ha▒
                           - 11,75% _ZNSt10shared_ptrIN7opencog8FreeLinkEEC2ISaIS1_EJRKSt6vectorINS0_▒
                              - 11,56% _ZNSt12__shared_ptrIN7opencog8FreeLinkELN9__gnu_cxx12_Lock_pol▒
                                 + 5,81% _ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC2IN7ope▒
                                 + 2,69% _ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC2IN7ope▒
                                 + 1,93% _ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC2IN7ope▒
                                   0,53% _ZNSt12__shared_ptrIN7opencog8FreeLinkELN9__gnu_cxx12_Lock_p

vsbogd added 5 commits May 29, 2018 17:43
ScopeLink benchmarks:
- create ScopeLink using variable list declaration
- create ScopeLink without variable list declaration
- create ScopeLink using LambdaLink
- add same ScopeLink into atomspace few times
- add number of unique ScopeLinks into atomspace

EvaluationLink benchmarks:
- create EvaluationLink to compare with ScopeLink
- add same EvaluationLink into atomspace few times
- add number of unique EvaluationLinks into atomspace
AtomSpace atomspace;
Handle X = atomspace.add_node(VARIABLE_NODE, "$X");
Handle P = atomspace.add_node(PREDICATE_NODE, "P");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really about EvaluationLinks, per se, but links-in-general. you could have used ListLink, instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, my comments is not right. EvaluationLink causes the FreeLink factory to run; but an ordinary ListLink would not. Some of the free-link stuff gets more expensive as the evaluationlink has more variables in it,. I dunno.

for (auto _ : state)
{
atomspace.add_atom(links[i++ % number_of_links]);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you are measuring here is a totally-disjoint graph. Pretend that node==vertex, and link==edge. You've created a large number of totally disconnected directed edges: * -->-- *. You've created 2N vertexes, and N edges connecting them together.

But real-world data is not like that. There are three or four more interesting cases:

  1. the clique -- N vertexes, and N^2 edges connecting them.
  2. the bipartite graph -- N left(start) vertexes, M right(finish) vertexes, and NM total edges,
  3. the scale-free network -- N vertexes, listed in order, with N edges from the first vertex to all of the others. N/2 edges from the second vertex to half the others. N/2 edges from the third vertex to half the others. N/4 edges from vertex 4,5,6,7 to random others. The N/8 edges fro 8 vertexes to random samplings of 1/8th of the others, etc.

I think I described the scale-free network correctly, There are several variations on scale-free. Natural language is scale-free. One of my natural-language datasets will not fit into 256GB RAM when it runs, it blows out all L1, L2, L3 caches, etc. For me, this is the most interesting benchmark.

For PLN, logic, I am not sure of what the typical graph/edge network they have.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, also - for the scale free network, the other interesting task is to walk it, randomly following edges, and then update the truth value for each vertex as you encounter it, while walking the network. Say, increment the count by one. This neither adds nor removes from the atomspace. But it does for the incoming sets to work hard, and the incoming sets will be all sorts of very different sizes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is another interesting point: in the totally-disconnected graph you created, the incoming sets are almost trivial. For the clique and the bipartite graph, they are always very large. Again, the scale-free network is interesting... and this affects the earlier benchmark: BM_CreateEvaluationLink - the create will run faster, when the vertexes are maximally independent. It will run slowly when they're no. I think in that benchmark, you create just two vertexes, and then create N edges between them. When you measure performance, I think you will see N logN behavior (or something like that..), because the incoming set is stored as a c++ std::set of weak pointers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that in current state BM_AddEvaluationLink and BM_AddScopeLink are not very interesting. I wrote them before I looked to Atomspace code. I thought about removing it but found that after size of atomspace is increased significally performance decreases. I have commited tests with different atomspace sizes to demonstrate the difference:

$ ./atomspace/atomspace/benchmark --benchmark_filter='AddScope|AddEval'
2018-05-31 15:10:48
Running ./atomspace/atomspace/benchmark
Run on (12 X 4000 MHz CPU s)
CPU Caches:
  L1 Data 32K (x6)
  L1 Instruction 32K (x6)
  L2 Unified 256K (x6)
  L3 Unified 12288K (x1)
------------------------------------------------------------------
Benchmark                           Time           CPU Iterations
------------------------------------------------------------------
BM_AddScopeLink/4096            13869 ns      13869 ns      37463
BM_AddScopeLink/8192            15389 ns      15389 ns      41657
BM_AddScopeLink/16384           22546 ns      22545 ns      24945
BM_AddEvaluationLink/16384       5839 ns       5839 ns     108308
BM_AddEvaluationLink/32768       7933 ns       7933 ns      65748
BM_AddEvaluationLink/65536      11290 ns      11290 ns      62715

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using scale-free network looks interesting, will add it to look what difference does it make.

@linas
Copy link
Member

linas commented May 30, 2018

The code looks reasonable to me. I'll let Nil look at it and merge. I made comments, but those don't need to be fixed before merging.

Nil might want to review the complexity of the ScopeLink -- it seems to be over-simplified, and not very much like a "typical" scope link.

@linas
Copy link
Member

linas commented May 30, 2018

re diary.txt, for now, leave that alone, and/or start a new one. Some time late, in a few weeks/months, I'll rename diary.txt to something else, update it, make comments about old vs new.

@linas
Copy link
Member

linas commented May 30, 2018

Anyway, I like it. Results on scale-free graphs might be the most useful, the most real-life-like

@vsbogd
Copy link
Contributor Author

vsbogd commented May 31, 2018

I have found that numbers above are not correct as I used debug versions of libraries by accident. Correct numbers are below and they are ten times better:

$ ./atomspace/atomspace/benchmark 
2018-05-31 18:18:44
Running ./atomspace/atomspace/benchmark
Run on (12 X 4000 MHz CPU s)
CPU Caches:
  L1 Data 32K (x6)
  L1 Instruction 32K (x6)
  L2 Unified 256K (x6)
  L3 Unified 12288K (x1)
-----------------------------------------------------------------------------
Benchmark                                      Time           CPU Iterations
-----------------------------------------------------------------------------
BM_CreateScopeLinkWithVariableList           583 ns        583 ns    1207156
BM_CreateScopeLinkWithoutVariableList        441 ns        441 ns    1601252
BM_CreateScopeLinkWithLambdaLink             409 ns        409 ns    1713858
BM_AddSameScopeLink                         1160 ns       1160 ns     601468
BM_AddScopeLink/4096                        1316 ns       1316 ns     505942
BM_AddScopeLink/8192                        1614 ns       1614 ns     423016
BM_AddScopeLink/16384                       1691 ns       1691 ns     381658
BM_CreateEvaluationLink                      292 ns        292 ns    2386244
BM_AddSameEvaluationLink                     793 ns        793 ns     896268
BM_AddEvaluationLink/16384                  1014 ns       1014 ns     670038
BM_AddEvaluationLink/32768                  1070 ns       1070 ns     585950
BM_AddEvaluationLink/65536                  1185 ns       1185 ns     437785

@ngeiswei
Copy link
Member

@vsbogd Just curious, what was compiled in debug mode? google benchmark? atomspace? cogutil? opencog benchmark? All?

@vsbogd
Copy link
Contributor Author

vsbogd commented May 31, 2018

atomspace and cogutil - I have two versions built: debug and release and debug was loaded because of LD_LIBRARY_PRELOAD override.

@vsbogd
Copy link
Contributor Author

vsbogd commented May 31, 2018

Nevertheless profile analysis gives the same results:
ScopeLink adding:

-   86,57%     0,57%  benchmark  benchmark            [.] _ZL19BM_AddSameScopeLinkRN9benchmark5StateE▒
   - 86,01% _ZL19BM_AddSameScopeLinkRN9benchmark5StateE                                              ◆
      - 85,99% _ZN7opencog9AtomSpace8add_atomERKNS_6HandleEb                                         ▒
         - 78,02% _ZN7opencog9AtomTable3addESt10shared_ptrINS_4AtomEEb                               ▒
            - 32,35% _ZN7opencog10createLinkIJRSt6vectorINS_6HandleESaIS2_EERtEEES2_DpOT_            ▒
               - 23,10% _ZNK7opencog11ClassServer7factoryERKNS_6HandleE                              ▒
                  - 23,01% _ZN7opencog9ScopeLink7factoryERKNS_6HandleE                               ▒
                     - 22,84% ?? (inlined)                                                           ▒
                        - 21,90% ?? (inlined)                                                        ▒
                           - 21,49% ?? (inlined)                                                     ▒
                              - 21,47% ?? (inlined)                                                  ▒
                                 - 21,01% ?? (inlined)                                               ▒
                                    - ?? (inlined)                                                   ▒
                                       - 20,05% ?? (inlined)                                         ▒
                                          - 19,62% _ZN7opencog9ScopeLink7factoryERKNS_6HandleE       ▒
                                             - 19,27% _ZN7opencog9ScopeLinkC2ERKSt6vectorINS_6HandleE▒
                                                + 16,79% _ZN7opencog9ScopeLink17extract_variablesERKS▒

EvaluationLink adding:

-   89,26%     1,08%  benchmark  benchmark            [.] _ZL24BM_AddSameEvaluationLinkRN9benchmark5S▒
   - 88,18% _ZL24BM_AddSameEvaluationLinkRN9benchmark5StateE                                         ◆
      - 88,15% _ZN7opencog9AtomSpace8add_atomERKNS_6HandleEb                                         ▒
         - 80,14% _ZN7opencog9AtomTable3addESt10shared_ptrINS_4AtomEEb                               ▒
            + 32,21% _ZNK7opencog9AtomTable9getHandleERKSt10shared_ptrINS_4AtomEE                    ▒
            - 20,35% _ZN7opencog10createLinkIJRSt6vectorINS_6HandleESaIS2_EERtEEES2_DpOT_            ▒
               - 11,93% ?? (inlined)                                                                 ▒
                  - 11,01% ?? (inlined)                                                              ▒
                     - ?? (inlined)                                                                  ▒
                        - 7,20% ?? (inlined)                                                         ▒
                           - 5,56% ?? (inlined)                                                      ▒
                              - 4,37% ?? (inlined)                                                   ▒
                                 - 4,30% ?? (inlined)                                                ▒
                                    - 2,79% ?? (inlined)                                             ▒
                                       - 2,10% _ZN7opencog10createLinkIJRSt6vectorINS_6HandleESaIS2_E▒
                                          + 2,02% _ZN7opencog4Link4initERKSt6vectorINS_6HandleESaIS2_

@linas linas merged commit 8763ad6 into opencog:master Jun 1, 2018
@linas
Copy link
Member

linas commented Jun 1, 2018

It looks more or less as I would expect.

@vsbogd vsbogd deleted the add-scope-link-benchmarks branch June 1, 2018 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants