Giter Club home page Giter Club logo

lila-openingexplorer's Introduction

lila-openingexplorer

Test

Opening explorer for lichess.org, capable of handling trillions of positions, featuring:

Usage

Run server

  1. Install recent stable Rust (rustup recommended).

  2. Set some environment variables used at build time: set -a && source .env && set +a

  3. Build the server and view available options:

    cargo run --release -- --help
    

    Strongly consider adjusting --db-compaction-readahead, --db-cache, and --db-rate-limit depending on your setup.

  4. Run the server with the chosen options:

    ulimit -n 131072 && EXPLORER_LOG=lila_openingexplorer=info cargo run --release -- --db-compaction-readahead
    

โš ๏ธ In a production environment, administrative endpoints must be protected using a reverse proxy. It's best to whitelist only /masters, /lichess, and /player.

Import games

  1. Download database dumps from https://database.lichess.org/.

  2. Import (optionally works directly with compressed files):

    cd import-pgn
    cargo run --release -- *.pgn.zst
    

    The database size will be well below 3x the compressed PGN size.

    If you can fit this on SSDs, read and compaction performance, especially tail latencies, will benefit significantly. All else equal, RAIDs with multiple small disks are preferable to RAIDs with few larger disks. Block and page cache will take advantage of large amounts of available RAM.

    As of February 2023, Lichess handles around 12k requests/minute, using:

    • 4 spinning disks in RAID10
    • 128 GiB RAM, of which 100 GiB are used for the block cache
    • Compressed PGN import rate of around 100 KiB/s on the live system, paused at peak hours.

    Importing is currently very slow, but good enough to index faster than games are played. Initially, the database was prepared offline, with speed dropping as the database grew, averaging 1 MiB/s compressed indexing speed (so effectively 7 MiB/s uncompressed PGN data).

Monitoring

/monitor

Example:

curl http://localhost:9002/monitor

Response in InfluxDB line protocol:

opening_explorer block_index_miss=2271815u,block_index_hit=44204637u,block_filter_miss=2272244u,block_filter_hit=81741291u,block_data_miss=31540587u,block_data_hit=33327789u,indexing=5u,lichess_cache=31038u,lichess_miss=2993390u,lichess_history_cache=2112u,lichess_history_miss=19558u,masters_cache=38276u,masters_miss=3430066u,masters=158629555u,masters_game=2519908u,lichess=121970833029u,lichess_game=4331746117u,player=18693470276u,player_status=182129u

/monitor/db/<prop>

/monitor/cf/<cf>/<prop>

Example:

curl http://localhost:9002/monitor/cf/lichess/rocksdb.stats
** Compaction Stats [lichess] **
Level    Files   Size     Score Read(GB)  Rn(GB) Rnp1(GB) Write(GB) Wnew(GB) Moved(GB) W-Amp Rd(MB/s) Wr(MB/s) Comp(sec) CompMergeCPU(sec) Comp(cnt) Avg(sec) KeyIn KeyDrop Rblob(GB) Wblob(GB)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  L0      1/0   34.75 MB   0.2     64.3     0.0     64.3     157.5     93.2       0.0   1.6      1.4      3.5  46068.07           3002.68      2760   16.691   1763M    92M       0.0       0.0
  L1      4/0   205.48 MB   0.8    172.6    93.2     79.4     165.5     86.1       0.0   1.8      3.7      3.5  48254.63           3779.43       207  233.114   4758M   164M       0.0       0.0
  L2     52/0    2.49 GB   1.0    321.9    81.7    240.3     317.2     77.0       4.4   3.9      3.5      3.4  94232.38           6840.29      1345   70.061   8967M   121M       0.0       0.0
  L3    591/0   24.95 GB   1.0    338.4    78.2    260.1     333.0     72.9       3.1   4.3      3.5      3.5  97870.15           7213.25      1532   63.884   9448M   146M       0.0       0.0
  L4   3367/0   90.71 GB   0.4     81.3    48.6     32.7      79.9     47.2      27.5   1.6      3.7      3.6  22451.14           1770.16       904   24.835   2281M    35M       0.0       0.0
  L6  47776/0    2.78 TB   0.0      0.0     0.0      0.0       0.0      0.0       0.0   0.0      0.0      0.0      0.00              0.00         0    0.000       0      0       0.0       0.0
 Sum  51791/0    2.90 TB   0.0    978.5   301.6    676.9    1053.2    376.3      35.0  10.9      3.2      3.5 308876.38          22605.81      6748   45.773     27G   560M       0.0       0.0
 Int      0/0    0.00 KB   0.0      0.0     0.0      0.0       0.0      0.0       0.0   0.0      0.0      0.0      0.00              0.00         0    0.000       0      0       0.0       0.0

** Compaction Stats [lichess] **
Priority    Files   Size     Score Read(GB)  Rn(GB) Rnp1(GB) Write(GB) Wnew(GB) Moved(GB) W-Amp Rd(MB/s) Wr(MB/s) Comp(sec) CompMergeCPU(sec) Comp(cnt) Avg(sec) KeyIn KeyDrop Rblob(GB) Wblob(GB)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Low      0/0    0.00 KB   0.0    978.5   301.6    676.9     956.6    279.7       0.0   0.0      3.5      3.4 288675.78          20752.87      4203   68.683     27G   560M       0.0       0.0
High      0/0    0.00 KB   0.0      0.0     0.0      0.0      96.6     96.6       0.0   0.0      0.0      4.9  20200.60           1852.94      2545    7.937       0      0       0.0       0.0

Blob file count: 0, total size: 0.0 GB, garbage size: 0.0 GB, space amp: 0.0

Uptime(secs): 610745.6 total, 3.5 interval
Flush(GB): cumulative 96.595, interval 0.000
AddFile(GB): cumulative 0.000, interval 0.000
AddFile(Total Files): cumulative 0, interval 0
AddFile(L0 Files): cumulative 0, interval 0
AddFile(Keys): cumulative 0, interval 0
Cumulative compaction: 1053.16 GB write, 1.77 MB/s write, 978.51 GB read, 1.64 MB/s read, 308876.4 seconds
Interval compaction: 0.00 GB write, 0.00 MB/s write, 0.00 GB read, 0.00 MB/s read, 0.0 seconds
Stalls(count): 1028 level0_slowdown, 1018 level0_slowdown_with_compaction, 0 level0_numfiles, 0 level0_numfiles_with_compaction, 0 stop for pending_compaction_bytes, 1809 slowdown for pending_compaction_bytes, 0 memtable_compaction, 0 memtable_slowdown, interval 0 total count
Block cache LRUCache@0x7feb60a3f150#4001884 capacity: 40.00 GB usage: 39.97 GB table_size: 524288 occupancy: 6030149 collections: 1018 last_copies: 5 last_secs: 0.039008 secs_since: 408
Block cache entry stats(count,size,portion): DataBlock(165238,10.35 GB,25.885%) FilterBlock(22233,29.11 GB,72.7832%) IndexBlock(22348,499.64 MB,1.21981%) Misc(1,0.00 KB,0%)

** File Read Latency Histogram By Level [lichess] **

** DB Stats **
Uptime(secs): 610745.6 total, 3.5 interval
Cumulative writes: 0 writes, 0 keys, 0 commit groups, 0.0 writes per commit group, ingest: 0.00 GB, 0.00 MB/s
Cumulative WAL: 0 writes, 0 syncs, 0.00 writes per sync, written: 0.00 GB, 0.00 MB/s
Cumulative stall: 00:00:0.000 H:M:S, 0.0 percent
Interval writes: 0 writes, 0 keys, 0 commit groups, 0.0 writes per commit group, ingest: 0.00 MB, 0.00 MB/s
Interval WAL: 0 writes, 0 syncs, 0.00 writes per sync, written: 0.00 GB, 0.00 MB/s
Interval stall: 00:00:0.000 H:M:S, 0.0 percent

Public HTTP API

See https://lichess.org/api#tag/Opening-Explorer.

/masters

/lichess

/player

Example:

curl https://explorer.lichess.ovh/player?player=foo&color=white&play=e2e4

Query parameters:

name type default description
variant string chess antichess, atomic, chess (or standard, chess960, fromPosition), crazyhouse, horde, kingOfTheHill, racingKings, threeCheck
fen string starting position of variant FEN of the root position
play string empty Comma separated moves in UCI notation. Play additional moves starting from fen. Required to find an opening name, if fen is not an exact match for a named position.
player string required Username to filter for
color string required Filter for games where player is white or black
modes string all Comma separated list of game modes (rated, casual) to filter for
speeds string all Comma separated list of speeds (ultraBullet, bullet, blitz, rapid, classical, correspondence) to filter for
since string 0000-01 Year-Month. Filter for games played in this month or later
until string 3000-12 Year-Month. Filter for games played in this month or earlier

Response: Streamed application/x-ndjson with rows as follows.

Will start indexing, immediately respond with the current results, and stream more updates until indexing is complete. The stream is throttled and deduplicated. Empty lines may be sent to avoid timeouts.

{
    "white": 10, // total number of white wins from this position
    "draws": 1,
    "black": 22,
    "moves": [
        {
            "uci": "e7e5",
            "san": "e5",
            "white": 6, // total number of white wins with this move.
                        // more may transpose to resulting position.
            "draws": 1,
            "black": 9,
            "averageOpponentRating": 1500, // or null
            "game": { // only game for this move.
                      // would not actually be sent, because there are multiple
                      // games in this case, but for example:
                "id": "uPdCG6Ts",
                "winner": "black",
                "speed": "correspondence",
                "mode": "casual",
                "white": {
                    "name": "foo",
                    "rating": 1500
                },
                "black": {
                    "name": null,
                    "rating": null
                },
                "year": 2015,
                "month": "2015-09"
            }
        },
        // ...
    ],
    "recentGames": [ // currently up to 15 recent games.
                     // limit is up to discussion.
        {
            "uci": "e7e5",
            "id": "uPdCG6Ts",
            "winner": "black",
            "speed": "correspondence",
            "mode": "casual",
            "white": {
                "name": "foo",
                "rating": 1500
            },
            "black": {
                "name": null,
                "rating": null
            },
            "year": 2015,
            "month": "2015-09"
        },
        // ...
    ],
    "opening": {
        "eco": "B00",
        "name": "King's Pawn"
    },
    "queuePosition": 3 // waiting for other players to be indexed first
}

License

Licensed under the GNU Affero General Public License v3. See the LICENSE file for details.

lila-openingexplorer's People

Contributors

dependabot[bot] avatar fitztrev avatar hasimir avatar niklasf avatar ornicar avatar scala-steward avatar srimethan avatar timjentzsch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lila-openingexplorer's Issues

filter duplicates

We could use something like a bloom filter on the game id to detect duplicates. Probably this can't happen anyway, though.

Cheated games

I analyzed a line in the Lichess opening explorer, and one of the Top game listed was a game that ended with cheat detection.
I'm not sure engine games should be indexed by the opening explorer and displayed as examples.

The game in question: https://lichess.org/izhNCrJG
The line analyzed was:

r2qk2r/pp1nbpp1/2p1pn1p/7P/3P4/3Q1NN1/PPPB1PP1/2KR3R w kq - 4 13

The game in question appeared with the explorer settings at Lichess Database, all level, Rapid and Classical time control.

Not sure if this the good repository for this issue, sorry if not the case.

top games not filtered by time control

@ornicar: bummer ... i just noticed top games are not filtered by time control. good time to realize this, with indexing almost complete?

i'll figure out the best we can do without complete reindexing. then let's talk about the options.

Weird move listed

The opening explorer suggests a very strange move in the Sicilian Najdorf after 1.e4 c5 2.Nf3 d6 3.d4 cxd4 4.Nxd4 Nf6 5.Nc3 a6 6.Be3 Ng4, the move Qxg4 is listed is having been played in one game in the masters database. However, upon playing that move, no game is shown.

screenshot from 2016-08-12 13-54-44

the problem with rating groups

Is that ratings are not consistent across categories.

bullet ratings are usually higher
variant ratings are usually lower
ELO ratings (external master games) are ~300 points lower.

issue with castling rights in atomic

in atomic, castling rights can be indirectly destroyed when exploding a rook by capturing a piece next to it.

the fen won't have castling rights. scalachess will have castling rights internally.

=> boom. no games found

(almost the same thing as in antichess)

ui

  • allow variant selection in /analysis

  • hangs when clicking on drops, in crazyhouse
  • inconsistency: P@c3 from the api, @c3 in move list

  • show recent/top games

  • do not (try to) display number if bar is too thin
  • master games unavailable for variants, do not show the option
  • opening book available during correspondence games?
  • if no games are found, remind the user of the filter settings

  • consider highlighting squares as moves are hovered
  • consider showing average rating as tooltip
  • right align numbers
  • thousands spacing
  • master games imported by: the user that first clicked them
  • consider cutting off the percent sign if bar is thinner than ~ 20%
  • color choice: i like high contrast color for the headers. it's much better than the old version. the buttons in the settings are green. buttons in the existing user preferences are orange. maybe reuse that?

test three check

i'd be surprised if three-check was working right now. test it

game count?

I have imported 60k master games and the explorer says the initial position has 240k games.

What am I missing?

select multiple speeds (like blitz+classical)

I'm building the explorer config UI

And I think it would make sense to select multiple speeds, notably blitz+classical, since the opening stage should not be too different and it would give more result to select both.

Feasible?

Nimzo-Indian Defense E20 Premature Naming

The Nimzo-Indian Defense E20 is described as:

  1. d4 Nf6 2. c4 e6 3. Nc3 Bb4

but if you make the moves

  1. d4 Nf6 2. c4 e6 3. Nc3

it is already prematurely calling this the Nimzo-Indian Defense.

If black does not make the move Bb4 and makes any other move the game will be described as a Nimzo-Indian Defense game which it is not.

Proof of the official E20 game moves:

https://www.365chess.com/eco/E20
http://www.chessgames.com/chessecohelp.html
https://en.m.wikipedia.org/wiki/Nimzo-Indian_Defence

The Bb4 move is an essential part of this opening...

tune defrag parameter

Kyoto can be tuned to execute one defragmentation operation per n writing operations. And it can be totally worth it (see below for a full out-of-band defrag). We should play with the settings.


Before:

ubuntu@lichess-cloud:~/tonyro_successful_import$ du -h *
312M    LiChess 2200 DB.7z?dl=0
1.7G    LiChess 2200 DB.pgn
3.5G    master.kct
1.3G    master-pgn.kct

Full defrag:

ubuntu@lichess-cloud:~/tonyro_successful_import$ kctreemgr defrag master-pgn.kct 
kctreemgr: [WARN]: ./kchashdb.h: 2717: reorganize_file: -: reorganizing the database
kctreemgr: [WARN]: ./kcplantdb.h: 3642: reorganize_file: master-pgn.kct: reorganizing the database
ubuntu@lichess-cloud:~/tonyro_successful_import$ kctreemgr defrag master.kct 
kctreemgr: [WARN]: ./kchashdb.h: 2717: reorganize_file: -: reorganizing the database
kctreemgr: [WARN]: ./kcplantdb.h: 3642: reorganize_file: master.kct: reorganizing the database

After:

ubuntu@lichess-cloud:~/tonyro_successful_import$ du -h *
312M    LiChess 2200 DB.7z?dl=0
1.7G    LiChess 2200 DB.pgn
1.5G    master.kct
991M    master-pgn.kct

Stats:

Pack format 0: 46125923 nodes 
Pack format 1: 2609441 nodes 
Pack format 2: 520405 nodes 
Pack format 3: 6800 nodes 
Pack format 4: 2 nodes 
Pack format 5: 0 nodes 
Pack format 6: 0 nodes 
Unique positions: 49262571

filter master games

@ornicar I just noticed the master game database also contains entries with low (or no) ratings, pulling the averages down. We should decide on a rating threshold or filter for (at least one?) titled player.

can not click last move of main line

  1. open example game id on staging server gxXOugin#41
  2. click Ne1 in explorer
lichess.analyse.min.js?v=850:4 Uncaught TypeError: Cannot read property 'length' of undefined

game links

I need to know the players names and the year to display them.

master games: store in kyoto? separate DB maybe? or use the existing PGN DB and read the game tags?

lichess games: data can be retrieved from lichess DB on demand. But I see the initial position has 31 recent games plus 31 top games. Do we really need all that? How about 4 each?

Wrong move notation

The opening explorer shows an invalid move in the Latvian Gambit after 1.e4 e5 2.Nf3 f5 3.Nxe5. It shows Qxe7 as a possible continuation, and although Qe7 is a valid move, it's not a capture.

ss 2016-07-31 at 05 17 16

I'm not sure if this is an issue of this component specifically or whether I should file it under lila, but here we go.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.