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

Messages User Guide #2493

Merged
merged 6 commits into from
Jan 31, 2017
Merged

Messages User Guide #2493

merged 6 commits into from
Jan 31, 2017

Conversation

sougou
Copy link
Contributor

@sougou sougou commented Jan 23, 2017

No description provided.

Copy link
Member

@derekperkins derekperkins left a comment

Choose a reason for hiding this comment

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

Overall, there are some pretty great design choices that I hadn't expected that really make this stand out.

Rather than a separate keyspace, the fact that queues can live inside the keyspace of relevant existing data, allowing for it to be truly transactional. That is awesome.

It does have the tradeoff of being more prone to hotspots, though I can't think of a way around that without having a task keyspace sharded on the ID, which would lose most of the other guarantees.

* `vt_ack_wait=30`: Wait for 30s for the first message ack. If one is not received, resend.
* `vt_purge_after=86400`: Purge acked messages that are older than 86400 seconds (1 day).
* `vt_batch_size=10`: Send up to 10 messages per batch.
* `vt_cache_seze=10000`: Store up to 10000 messages in the cache.
Copy link
Member

Choose a reason for hiding this comment

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

should be vt_cache_size

insert into my_message(id, message) values(1, 'hello world')
```

These inserts can be part of a regular transaction. Multiple messages can be inserted to different tables. Avoid accumulating too many big messages within a transaction as it consumes memory on the VTTablet side. At the time of commit, memoery permitting, all messages are instantly enqueued to be sent.
Copy link
Member

Choose a reason for hiding this comment

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

memoery to memory

epoch bigint,
time_created bigint,
time_acked bigint,
message varchar(128),
Copy link
Member

Choose a reason for hiding this comment

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

Why varchar instead of varbinary? Is the size configurable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned below, the message can be any MySQL type.


# Creating a message table

The current implementation requires a fixed schema. This will be made more flexible in the future. There will also be a custom DDL syntax. For now, a message table must be created like this:
Copy link
Member

Choose a reason for hiding this comment

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

1 table ~ 1 queue, so inserts / acks will be limited by your single node performance, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The table can be sharded. So, there should be no performance bottleneck. Or did I misunderstand the question?
Also, let me know if the statement can be better rephrased.

* `vt_ack_wait=30`: Wait for 30s for the first message ack. If one is not received, resend.
* `vt_purge_after=86400`: Purge acked messages that are older than 86400 seconds (1 day).
* `vt_batch_size=10`: Send up to 10 messages per batch.
* `vt_cache_seze=10000`: Store up to 10000 messages in the cache.
Copy link
Member

Choose a reason for hiding this comment

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

What are vt_batch_size and vt_cache_size?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Batch size is the number of message rows sent per RPC packet.
Cache size is the number of messages that will be kept in the send queue in memory. The rest will have to wait for the next poller cycle.
I'll add these clarifications.

insert into my_message(id, message) values(1, 'hello world')
```

These inserts can be part of a regular transaction. Multiple messages can be inserted to different tables. Avoid accumulating too many big messages within a transaction as it consumes memory on the VTTablet side. At the time of commit, memoery permitting, all messages are instantly enqueued to be sent.
Copy link
Member

Choose a reason for hiding this comment

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

What does that VTTablet memory limitation look like? It's pretty common for us to add > 1M tasks in a single transaction, with the payload being a ~100 character url.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you have 100 shards, you'll need about 1M per shard.
Is there a reason why all DMLs have to be in the same transaction? Can you not break it up into smaller transactions?

* Dropped tables: The message engine does not currently detect dropped tables.
* Changed properties: Although the engine detects new message tables, it does not refresh properties of an existing table.
* A `SELECT` style syntax for subscribing to messages.
* No rate limiting.
Copy link
Member

Choose a reason for hiding this comment

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

Rate limiting would be my #1 request

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The rate limiting design needs to be discussed. You could add the ability for each vttablet to rate-limit. However, it's hard to manage because of possible size differences, resharding, etc. A more global solution may need to be brainstormed.
In the meantime, you can consider pulling messages at a controlled rate (per subscriber), which should effectively achieve the same thing.


The message feature is currently in alpha, and can be improved. Here is the list of possible limitations/improvements:

* Flexible columns: Allow any number of application defined columns to be in the message table.
Copy link
Member

Choose a reason for hiding this comment

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

Flexible columns is a close second on the feature list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This won't be too hard to add on (after I take care of a few unrelated high-priority items).


## Exponential backoff

A message that was successfully sent will wait for the specified ack wait time. If no ack is received by then, it will be resent. The next attempt will be 2x the previous wait, and this delay is doubled for every attempt.
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to set a queue level min/max?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We debated not backing off beyond a certain time period. However, that will just lead to hotspots in the future for messages that have chronic failures.

It's better to provide for manual control over such messages, so they can be tried only after the root cause is addressed.

* Proactive scheduling: Upcoming messages can be proactively scheduled for timely delivery instead of waiting for the next polling cycle.
* Monitoring support: To be added.
* Dropped tables: The message engine does not currently detect dropped tables.
* Changed properties: Although the engine detects new message tables, it does not refresh properties of an existing table.
Copy link
Member

Choose a reason for hiding this comment

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

Does properties mean the columns or the rows themselves? Is it possible to UPDATE the table? For example, sometimes we've had situations where exponential backoff has pushed the next execution time back hours or days, but it is especially helpful during debugging to have a message run now, and then update all those messages to run now after the bug has been fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now, it's all properties: columns, types as well as config parameters like cache size, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's actually possible to update the table. I've mentioned this in the Advanced Usage section. I'll add instructions for rescheduling messages in there.

@sougou
Copy link
Contributor Author

sougou commented Jan 23, 2017

About your comment related to making your message rows co-exist with a parent row of another table, you can still get that using a custom sharding scheme. However, it could lead to hotspots if some root rows generate more messages than others.

Let's say the parent table has user_id as the primary key, the message table can have an id column that contains the user_id in its bits, and you can have it use the same sharding, but only using the user_id parts as input.

Review comments addressed.
@sougou
Copy link
Contributor Author

sougou commented Jan 30, 2017

Ping. Need lgtm.


# Overview

Vitess messaging gives the application an easy way to schedule and manage work that needs to be performed asynchronously. Under the covers, messages are stored in a traditional MySQL table and therefore enjoy the following properties:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you format this file with < 80 characters per line? My emacs does that for me...


Vitess messaging gives the application an easy way to schedule and manage work that needs to be performed asynchronously. Under the covers, messages are stored in a traditional MySQL table and therefore enjoy the following properties:

* **Transactional**: Messages can be created or acked as part of an existing transaction. The action will complete only if the commit succeeds.
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is not the main attraction, I would move it down, keep Scalable as the first one in the list.

@alainjobart
Copy link
Contributor

alainjobart commented Jan 31, 2017

LGTM

Approved with PullApprove

@sougou sougou merged commit 6297b03 into vitessio:master Jan 31, 2017
frouioui pushed a commit to planetscale/vitess that referenced this pull request Mar 26, 2024
….0 query (vitessio#2493)

* cherry pick of 13375

* fix xtrabackup setup

Signed-off-by: Shlomi Noach <[email protected]>

* either MySQL or Percona Server

Signed-off-by: Shlomi Noach <[email protected]>

* fixing xtrabackup/percona-server installation

Signed-off-by: Shlomi Noach <[email protected]>

* again, fixing xtrabackup code

Signed-off-by: Shlomi Noach <[email protected]>

* reverting workflow changes

Signed-off-by: Shlomi Noach <[email protected]>

* Support views in BaseShowTablesWithSizes for MySQL 8.0 (vitessio#13394)

* Support views in BaseShowTablesWithSizes for MySQL 8.0

Signed-off-by: Shlomi Noach <[email protected]>

* added test

Signed-off-by: Shlomi Noach <[email protected]>

* fixed test

Signed-off-by: Shlomi Noach <[email protected]>

* schema tracker: use null safe comparison

Signed-off-by: Andres Taylor <[email protected]>

---------

Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Co-authored-by: Andres Taylor <[email protected]>

---------

Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Co-authored-by: Shlomi Noach <[email protected]>
Co-authored-by: Andres Taylor <[email protected]>
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.

4 participants