{"id":42684870,"url":"https://github.com/codepr/sol","last_synced_at":"2026-01-29T12:08:53.834Z","repository":{"id":40362679,"uuid":"171187665","full_name":"codepr/sol","owner":"codepr","description":"Lightweight MQTT broker, written from scratch. IO is handled by a super simple event loop based upon the most common IO multiplexing implementations.","archived":false,"fork":false,"pushed_at":"2025-01-19T23:22:32.000Z","size":1154,"stargazers_count":117,"open_issues_count":7,"forks_count":15,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-01-20T00:25:15.280Z","etag":null,"topics":["c","epoll","event-driven","mqtt","mqtt-broker","pubsub","simple","tcp","tutorial"],"latest_commit_sha":null,"homepage":"https://codepr.github.io/posts/sol-mqtt-broker","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codepr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-18T00:11:51.000Z","updated_at":"2024-12-24T03:17:32.000Z","dependencies_parsed_at":"2024-12-16T23:28:29.915Z","dependency_job_id":"bd43a14b-fc33-43a5-89e0-d455fdd80a04","html_url":"https://github.com/codepr/sol","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/codepr/sol","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codepr%2Fsol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codepr%2Fsol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codepr%2Fsol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codepr%2Fsol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codepr","download_url":"https://codeload.github.com/codepr/sol/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codepr%2Fsol/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28877146,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T10:31:27.438Z","status":"ssl_error","status_checked_at":"2026-01-29T10:31:01.017Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","epoll","event-driven","mqtt","mqtt-broker","pubsub","simple","tcp","tutorial"],"created_at":"2026-01-29T12:08:51.014Z","updated_at":"2026-01-29T12:08:53.826Z","avatar_url":"https://github.com/codepr.png","language":"C","readme":"[![Build Status](https://travis-ci.org/codepr/sol.svg?branch=master)](https://travis-ci.org/codepr/sol)\n\nSol\n===\n\nOversimplified MQTT broker written from scratch, which mimic mosquitto\nfeatures. Implemented to learning how the protocol works, it supports\nalmost all MQTT v3.1.1 commands on linux platform and relies on EPOLL interface\nfor multiplexing I/O. The basic development process is documented in this\n[series of posts](https://codepr.github.io/posts/sol-mqtt-broker), referring to\nthe [tutorial branch](https://github.com/codepr/sol/tree/tutorial); the master\nbranch is the most up-to-date and tested.\n**Not for production use**.\n\n### Features\n\nIt's still a work in progress but it already handles the most of the basic\nfeatures expected from an MQTT broker. It does not leak memory as of now,\nthere's probably some corner cases, not deeply investigated yet.\n\n- Configuration file on disk\n- Support for QoS messages 0, 1 and 2\n- Retained messages per topic\n- Session present check and handling\n- Periodic stats publishing\n- Support multiple topics subscriptions through wildcard (#) and (+) for single\n  level wildcard e.g. foo/+/bar/#\n- Authentication through username and password\n- SSL/TLS connections, configuration accepts minimum protocols to be used\n- Logging on disk\n- Daemon mode\n- Multiplexing IO with abstraction over backend, currently supports\n  select/poll/epoll choosing the better implementation.\n- Multithread load-balancing on connections for high concurrent performance\n\n### To be implemented\n\n- Last will \u0026 Testament, already started\n- Persistence on disk for inflight messages on disconnected clients\n- Check on max memory used\n\n### Maybe\n\n- MQTT 5.0 support\n- Porting for BSD/MAC osx\n- Scaling (feeling brave?)\n\n## Build\n\n```sh\n$ cmake .\n$ make\n```\n\n## Quickstart play\n\nThe broker can be tested using `mosquitto_sub` and `mosquitto_pub` or with\n`paho-mqtt` python driver.\n\nTo run the broker with DEBUG logging on:\n\n```sh\n$ ./sol -v\n```\n\nA simple configuration can be passed in with `-c` flag:\n\n```sh\n$ ./sol -c path/to/sol.conf\n```\n\nAs of now the configuration is very small and it's possible to set some of the\nmost common parameters, default path is located to `/etc/sol/sol.conf`:\n\n```sh\n# Sol configuration file, uncomment and edit desired configuration\n\n# Network configuration\n\n# Comment ip_address and ip_port, set unix_socket and\n# UNIX family socket will be used instead\n\nip_address 127.0.0.1\nip_port 8883\n\n# unix_socket /tmp/sol.sock\n\n# Logging configuration\n\n# Could be either DEBUG, INFO/INFORMATION, WARNING, ERROR\nlog_level DEBUG\n\nlog_path /tmp/sol.log\n\n# Max memory to be used, after which the system starts to reclaim memory by\n# freeing older items stored\nmax_memory 2GB\n\n# Max memory that will be allocated for each request\nmax_request_size 2MB\n\n# TCP backlog, size of the complete connection queue\ntcp_backlog 128\n\n# Interval of time between one stats publish on $SOL topics and the subsequent\nstats_publish_interval 10s\n\n# TLS certs paths, cafile act as a flag as well to set TLS/SSL ON\n# cafile /etc/sol/certs/ca.crt\n# certfile /etc/sol/certs/cert.crt\n# keyfile /etc/sol/certs/cert.key\n\n# Authentication\n# allow_anonymous false\n# password_file /etc/sol/passwd\n\n# TLS protocols, supported versions should be listed comma separated\n# example:\n# tls_protocols tlsv1_2,tlsv1_3\n```\n\nIf `allow_anonymous` is false, a password file have to be specified. The\npassword file follows the standard format of username:password line by line.\nTo generate one just add all entries needed in a file and run passwd.py after\nit:\n\n```sh\n$ cat sample_passwd_file\nuser1:pass1\nuser2:pass2\n$ python passwd.py sample_passwd_file\n$ cat sample_passwd_file\nuser1:$6$69qVAELLWuKXWQPQ$oO7lP/hNS4WPABTyK4nkJs4bcRLYFi365YX13cEc/QBJtQgqf2d5rOIUdqoUin.YVGXC3OXY9MSz7Z66ZDkCW/\nuser2:$6$vtHdafhGhxpXwgBa$Y3Etz8koC1YPSYhXpTnhz.2vJTZvCUGk3xUdjyLr9z9XgE8asNwfYDRLIKN4Apz48KKwKz0YntjHsPRiE6r3g/\n```\n\n## Concurrency\n\nThe broker provides an access through a simple IO multiplexing event-loop based\nTCP server, the model is designed to be self-contained and thus easy to spread\non multiple threads. Another approach and probably more elegant would be to\nshare a single event loop to multiple threads, at the cost of higher complexity\nand race-conditions to be handled.\n\n```\n                            THREADS 1..N\n                            [EVENT-LOOP]\n\n    ACCEPT_CALLBACK         READ_CALLBACK         WRITE_CALLBACK\n  -------------------    ------------------    --------------------\n          |                      |                       |\n       ACCEPT                    |                       |\n          | -------------------\u003e |                       |\n          |                READ AND DECODE               |\n          |                      |                       |\n          |                      |                       |\n          |                   PROCESS                    |\n          |                      |                       |\n          |                      |                       |\n          |                      | --------------------\u003e |\n          |                      |                     WRITE\n       ACCEPT                    |                       |\n          | -------------------\u003e | \u003c-------------------- |\n          |                      |                       |\n\n```\n\nHowever, the current model gives some advantages against the single-thread\nimplementation, as each thread can handle a share of the total number of\nconnected client effectively increasing the throughput of the broker, the\nmain drawback is that in worst cases a scenario that can originate is where some\nthreads are serving heavy-load clients and some others are esentially idling\nwithout partecipating or helping.\n\n## Benchmarks\n\nI've run some basic benchmarks comparing Sol and Mosquitto's performance, using\n[mqtt-benchmark](https://github.com/krylovsk/mqtt-benchmark) tool to test\nconcurrent connections and different loads of traffic on my laptop, an\nIntel(R) I5-8265U (8) @ 3.900 GHz CPUs and 8 GB RAM.\n\nTo be minded that currently Sol skips some checks like UTF-8 strings for topics\nand the memory footprint is also much greater than Mosquitto's one; moreover\nthis benchmarks doesn't take into account real publish on multiple subscribers,\njust the publish traffic load on multiple clients with different QoS levels.\n\n![MQTT mosquitto vs sol comparison](MQTTcomparison.png)\n\nAll tests are run pointing to localhost:1883, apparently, out of QoS 0 tests\nwhich are the least interesting as there's no real \"handshakes\" or overhead on\nthe communication between the peers, QoS 1 and even more QoS 2 is where Sol\nseems to shine, highlighting a 95% increased throughtput over Mosquitto on the\nQoS 2 1000 clients benchmark.\nOf course these benchmarks are of little relevance and Mosquitto is compiled\nwithout any optimizations, just an out of the box version binary shipped by\nthe OS repository, version 1.6.8, but in terms of sheer concurrency Sol does\npretty good.\n\n## Contributing\n\nPull requests are welcome, just create an issue and fork it.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodepr%2Fsol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodepr%2Fsol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodepr%2Fsol/lists"}