Skip to content

Commit

Permalink
Merge pull request #7 from lysand-org/main
Browse files Browse the repository at this point in the history
v0.1.2
  • Loading branch information
CPlusPatch authored Dec 1, 2023
2 parents 7d92867 + d7398e1 commit 2fb3e5c
Show file tree
Hide file tree
Showing 16 changed files with 676 additions and 49 deletions.
12 changes: 9 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ RUN chmod +x /docker-entrypoint-initdb.d/init.sh
```

4. Copy the `config.toml.example` file to `config.toml` and fill in the values (you can leave most things to the default, but you will need to configure things such as the database connection)

5. Generate the Prisma client:

5. Run migrations:
```bash
bun prisma generate
```

6. Run migrations:

```bash
bun migrate
Expand Down Expand Up @@ -130,9 +136,9 @@ When you are done with your changes, you can open a pull request. Please make su

We use Bun's integrated testing system to write tests. You can find more information about it [here](https://bun.sh/docs/cli/test). It uses a Jest-like syntax.

Tests **must** be written for all API routes and all functions that are not trivial. If you are not sure whether you should write a test for something, you probably should.
Tests **should** be written for all API routes and all functions that are not trivial. If you are not sure whether you should write a test for something, you probably should.

To help with the creation of tests, you may find [GitHub Copilot](https://copilot.github.com/) useful (or some of its free alternatives like [Codeium](https://codeium.com/)). Please do not blindly copy the code that it generates, but use it as a starting point for your own tests.
To help with the creation of tests, you may find [GitHub Copilot](https://copilot.github.com/) useful (or some of its free alternatives like [Codeium](https://codeium.com/)). Please do not blindly copy the code that it generates, but use it as a starting point for your own tests. I recognize that writing tests is very tedious, which is why LLMs can come in handy.

### Writing documentation

Expand Down
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,62 @@

This is a project to create a federated social network based on the [Lysand](https://lysand.org) protocol. It is currently in alpha phase, with basic federation and API support.

This project aims to be a fully featured social network, with a focus on privacy and security. It will implement the Mastodon API for support with clients that already support Mastodon or Pleroma.
This project aims to be a fully featured social network, with a focus on privacy, security, and performance. It will implement the Mastodon API for support with clients that already support Mastodon or Pleroma.

> **Note:** This project is not affiliated with Mastodon or Pleroma, and is not a fork of either project. It is a new project built from the ground up.
## Features

- [x] Inbound federation
- [x] Hyper fast (thousands of HTTP requests per second)
- [x] S3 or local media storage
- [x] Deduplication of uploaded files
- [x] Federation limits
- [x] Configurable defaults
- [x] Full regex-based filters for posts, users and media
- [x] Custom emoji support
- [x] Automatic image conversion to WebP or other formats
- [x] Scripting-compatible CLI with JSON and CSV outputs
- [ ] Moderation tools
- [ ] Full Mastodon API support
- [ ] Outbound federation

## Benchmarks

> **Note**: These benchmarks are not representative of real-world performance, and are only meant to be used as a rough guide.
### Timeline Benchmarks

You may run the following command to benchmark the `/api/v1/timelines/home` endpoint:

```bash
TOKEN=token_here bun benchmark:timeline <request_count>
```

The `request_count` variable is optional and defaults to 100. `TOKEN` is your personal user token, used to login to the API.

On a quad-core laptop:

```
$ bun run benchmarks/timelines.ts 100
✓ All requests succeeded
✓ 100 requests fulfilled in 0.12611s
```

```
$ bun run benchmarks/timelines.ts 1000
✓ All requests succeeded
✓ 1000 requests fulfilled in 0.90925s
```

```
$ bun run benchmarks/timelines.ts 10000
✓ All requests succeeded
✓ 10000 requests fulfilled in 12.44852s
```

Lysand is extremely fast and can handle tens of thousands of HTTP requests per second on a good server.

## How do I run it?

### Requirements
Expand Down Expand Up @@ -105,6 +143,12 @@ bun cli

You can use the `help` command to see a list of available commands. These include creating users, deleting users and more.

#### Scripting with the CLI

Some CLI commands that return data as tables can be used in scripts. To do so, you can use the `--json` flag to output the data as JSON instead of a table, or even `--csv` to output the data as CSV. See `bun cli help` for more information.

Flags can be used in any order and anywhere in the script (except for the `bun cli` command itself). The command arguments themselves must be in the correct order, however.

### Using Database Commands

The `bun prisma` commands allows you to use Prisma commands without needing to add in environment variables for the database config. Just run Prisma commands as you would normally, replacing `bunx prisma` with `bun prisma`.
Expand Down
56 changes: 56 additions & 0 deletions benchmarks/timelines.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Usage: TOKEN=your_token_here bun benchmark:timeline <request_count>
*/

import { getConfig } from "@config";
import chalk from "chalk";

const config = getConfig();

const token = process.env.TOKEN;
const requestCount = Number(process.argv[2]) || 100;

if (!token) {
console.log(
`${chalk.red(
"✗"
)} No token provided. Provide one via the TOKEN environment variable.`
);
process.exit(1);
}

const fetchTimeline = () =>
fetch(`${config.http.base_url}/api/v1/timelines/home`, {
headers: {
Authorization: `Bearer ${token}`,
},
}).then(res => res.ok);

const timeNow = performance.now();

const requests = Array.from({ length: requestCount }, () => fetchTimeline());

Promise.all(requests)
.then(results => {
const timeTaken = performance.now() - timeNow;
if (results.every(t => t)) {
console.log(`${chalk.green("✓")} All requests succeeded`);
} else {
console.log(
`${chalk.red("✗")} ${
results.filter(t => !t).length
} requests failed`
);
}
console.log(
`${chalk.green("✓")} ${
requests.length
} requests fulfilled in ${chalk.bold(
(timeTaken / 1000).toFixed(5)
)}s`
);
})
.catch(err => {
console.log(`${chalk.red("✗")} ${err}`);
process.exit(1);
});
Binary file modified bun.lockb
Binary file not shown.
Loading

0 comments on commit 2fb3e5c

Please sign in to comment.