Back

error when querying on big database 300 million rows.

  • 1
  • Self Hosted
  • Databases
jesus
25 Jul, 2024, 20:25

Hi,

When trying to query using 'Query.contains' on string attribute containing 300 million rows of data im getting this error:

AppwriteException: , ClientException with SocketException: The semaphore timeout period has expired. (OS Error: The semaphore timeout period has expired. , errno = 121)

What are the fixes? Do making a fulltext index help or not?

TL;DR
Developers experiencing timeout errors while querying a large database with 300 million rows. The issue arises specifically when using 'Query.contains' on a string attribute. Suggestions for fixes include: trying simpler query operators like equals, utilizing the 'search' operator for fulltext indexes, implementing collection-level permissions for better performance at scale, and ensuring proper indexing for improved efficiency. Additionally, adding an index for '$createdAt' is recommended. The error message 'The semaphore timeout period has expired' indicates a timeout occurring during the query process.
Eldad
25 Jul, 2024, 20:30

Can you provide more context? What setup you have? self-hosted or cloud? What's the data structure? What's the query you're trying to run? What permissions level do you use for the collection?

jesus
25 Jul, 2024, 20:33

Selfhosted, The data structure is a: row for phone numbers, and a row for names,

The query is Query.contains('name', '<the name>'

The permission is 'any' have all permission.

jesus
25 Jul, 2024, 20:34

I have an key index in the numbers row, and a key index in the name row.

Eldad
25 Jul, 2024, 20:34

How much time in avg it usually takes this query to complete?

jesus
25 Jul, 2024, 20:36

It never completed not ones, i always get this error when querying the name row, but with the numbers row it fast, I don't get errors in the numbers row querying

Eldad
25 Jul, 2024, 20:37

and where did you get the The semaphore timeout period has expired. error? Appwrite 500 response or in the console logs?

jesus
25 Jul, 2024, 20:37

The error happens when the query contains two name like this "john doe"

D5
25 Jul, 2024, 20:37

Are you able to see the elements in the console?

jesus
25 Jul, 2024, 20:37

Yes the development mode is enabled

jesus
25 Jul, 2024, 20:38

No

D5
25 Jul, 2024, 20:38

Try adding an index for $createdAt

jesus
25 Jul, 2024, 20:39

It is indexed by default by appwrite

jesus
25 Jul, 2024, 20:40

The row id and _uid and created at and updated at is indexed by default.

Eldad
25 Jul, 2024, 20:42

So... a few things I have in mind.

  1. Contains is not a super performant query because its hard to index properly. This is still great for many use cases, but in a table that big I can see how it can take a lot of time as it can't use any index efficiently.
  2. I would try a simpler query operator like equals to try and ensure no other problem exists. With your index it should be fairly fast even on a big table.
  3. For finding the name with a loose search, fulltext index should work better. The downside is that it will take a big chunk of storage space, but with this size of table it won't be avoidable.
  4. Another thing I would try is to go to collection level permissions instead of document level, collection level will be faster at scale.
Eldad
25 Jul, 2024, 20:43

@jesus also, I sent you a DM, I'm very curious to learn more on your use case with Appwrite:)

Eldad
25 Jul, 2024, 20:44

For 3 with the full text index, you should use the search operator to take advantage of the index.

jesus
25 Jul, 2024, 20:44

Yes it is collection level permission,

And i have tried the fulltext index i get the same time out error

Eldad
25 Jul, 2024, 20:44

Does a simple query work?

jesus
25 Jul, 2024, 20:46

Yes but i want to search between the names example:

John, John doe, Jeusu john doe,

I want the query to grab all these, the only solution is contains and search and all of them get time out error.

Eldad
25 Jul, 2024, 20:46

I also wonder if this error comes from Appwrite or your client. From looking online it seems like an error a Flutter client could throw

jesus
25 Jul, 2024, 20:48

No, I'm using sentry and I'm getting the same error. In the logs

jesus
25 Jul, 2024, 20:49

Just diffrent log text

Eldad
25 Jul, 2024, 20:49

Can you DM me with the logs information?

jesus
25 Jul, 2024, 20:49

Ok just a minute

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more