Stockfish Chess Engine Server
For linux users it seems pretty easy and natural to let scid chess databases, on low CPU and RAM devices, to use stockfish chess engine that runs on a more powerful server.
We start by installing stockfish onto our most powerful machine.
In my case a desktop with 32G RAM and 8 CPU cores with 2 threads per core, that means 16 threads.
Stockfish server
The chess engine will run only when the user is logged in. So, in ~/.local/share/systemd/user/ directory, we create two stockfish files
~/.local/share/systemd/user/stockfish.socket
[Unit]
Description=Stockfish Engine Chess
[Socket]
ListenStream=8123
Accept=yes
CollectMode=failed
[Install]
WantedBy=sockets.target
~/.local/share/systemd/user/stockfish@.service
[Unit]
Description=Stockfish Engine Chess
[Service]
ExecStart=/usr/bin/stockfish
StandardInput=socket
We enable stockfish socket by
systemctl –user enable stockfish.socket
and reboot or
systemctl –user start stockfish.socket
Now, whenever user is logged in and a client, as scid or droidfish, communicates on 8123 port, stockfish engine starts to run.
SSH port forward
My router can handle 16 ports and somehow i already covered all of them. So, either on my laptop (by terminal) or my mobile android phone (by termux), before starting using the stockfish engine, i forward my desktop 8123 port to them by the terminal command
ssh my_user@stocfish_running_engine_ip -L 8123:localhost:8123
Now, either my phone or my laptop can communicate with their (localhost) 8123 port and start using the stockfish engine that runs on my desktop.
droidfish
On my mobile i use droidfish. So, I Configure Network Engine with
Host name localhost
Port 8123
I want to use almost all available threads of my desktop. So, instead of 2*8=16, i set one less, in Engine Options
Threads (1-1024) 15
and in Settings
Hash Table 16384 MB
(That is about half of my desktop’s RAM).
scid
On my laptop I use scid and it was not so straight forward how to communicate with my desktop’s stockfish engine.
bug?
The “Add a remote engine” button appears only after the creation of a new engine and starting it by F2 or F3. I could not succeed on adding my desktop’s stockfish engine by the use of that button. If i understood correctly the help pages, remote URL engines concerns the sites where one downloads the engine (that will run locally) and not the remote location where it runs. I may be wrong but i bypassed the difficulty by installing “telnet” and the creation of a normal local engine.
scid’s ’local’ remote engine
Through the above ssh command, the desktop’s chess engine already listens to 8123 port of my laptop. So, I configured the ’local’ engine with
Command: telnet
Parameters: localhost 8123
Directory: path_to_/.scid5.0/config
Threads: 15
Hash: 16777 (actually, i wanted 2^24 bytes)
Without the above Directory option, hash and threads options could not be permanently stored.
bugs?
- I can not tell about Hash that on engine info seems to increase slowly and takes long enough time to fill up to 100% but the CPU load, as it remains to 0, points to the resources that scid client on my laptop uses. The correct should be the displayed 1500% (of 15 threads) by the ’top’ or ‘htop’ command on my desktop.
- The stockfish engine starts when either ‘Start engine 1’ or ‘Analysis engine…’ windows from ‘Tools’ are opene:qd. The engine quit when the above windows are closed. The ‘Start engine’ or ‘Stop engine’ buttons just start or stop calculations in both cases.
My suggestion would be to alter the title of ‘Stop engine’ to ‘Pause engine’ as more descriptive. In any case, the title in ‘Start engine 1’ or F2 window needs a correction as its title remains ‘Start engine’ either if one wants to start or pause the engine.
Since every window opens a new stockfish instance on my desktop and it is configured each instance to use 15 of its 16 available threads and half of its RAM, it seems good a ‘Pause’ title to remind me that i have to have only one engine window open. Else, engine window’s become slow, freeze or buggy.
Conclusion
The above is a working example in my case. It would be great if someone propose improvements in any part.