This message was deleted.
# community-help
s
This message was deleted.
j
May I know what embedding model you're using? For eg, this demo uses sentence-bert and runs on 4vCPU and returns results in tens of milliseconds with 324K records: https://hn-comments-search.typesense.org
b
I have created 2 tests: instance 8GB RAM - 2 vCPU 1. Search only for 5 terms (multisearch) embedded: 10 concurrent users, the average response is 1.5 sec
2. Search only for 1 term embedded: 10 concurrent users, the average response is 228ms
The multisearch adds up 200 ms per term, because it needs to vectorize the term and then search
tests by K6
j
10 concurrent users
Those response times seem in-line for 10 concurrent users, plus multiple searches...
These models are compute intensive, so to support additional concurrency you want to run them on a GPU
b
Yes, even with a 16 vcpu - 32 gb ram, I can have only 200 concurrent reqs
32* vCPUS
64 GB RAM
Is there any workaround instead of multisearch?
I was looking for a more cost affordable solution, average cost per GPU instance in the cloud is 300-400$/month x 3
j
Unfortunately, that's the nature of ML models... They're just computationally intensive. That compute either needs to come by adding more CPU cores (which is actually less efficient compared to GPUs for ML models), or add a GPU.
b
Yes the cpu way isn't scallable
Does typesense support hugging face inference endpoints, that would be a solution
in order to use it to generate the embedding
j
We don't at the moment, but could you open a GitHub issue for this?
Btw, doesn't hugging face charge by the hour for running these models?
b
Yes but it's fixed. eg 45$/month
Not like OpenAI, or Google Vertex which are by token
The issue by using an external provider is the latency. For example, the multisearch with 5 terms will need 5 API calls which will add more latency (anerage 100-150ms each). So I think in this case (multisearch with multiple terms) the only solution is by using GPU
j
Looking at the configs here for HuggingFace, I suspect that the CPU-run models will have similar performance like what you're seeing now.
b
same performance + latency
j
Right
b
latency * eg. 5 calls
j
So you'd anyway need GPU-powered inference endpoints in either case I suspect
b
Better to host typesensein a GPU instance to avoid latency by the calls
➕ 1
@Jason Bosco @Kishore Nallan Is it normal to have response time at 1s for a normal multi_search? I have constructed the array with 5 searches in the same collection
k
Each search within multi search is executed sequentially because we optimize for parallel multi search requests.n
b
So does it add more latency?
I tested it in a 4 vCPU - 8 GB RAM and in a 8 vCPU - 16 GB RAM, and the response time is the same ~ 1.3s. So the issue is with the multi_search
k
Did you sum up the search time ms response value in all the individual search responses in the multi search response array?
b
No I tested it with K6, 100 concurrent reqs
my collection has 1000 docs and typesense runs in a 8 vCPU - 16GB instance
I need to search for 5 terms in the same collection so I constructed 5 searches in multi_search payload
k
Technically with higher number of cpu, latency should be lower but beyond a certain point in concurrency if the load is super cpu bound like in the case of embeddings generation then just 4 more cpu cores won't make too much of a difference.
b
I don't use embedding for this search. just a normal query search
k
What is the response time on a single search request?
b
110ms
with 50 -> 330 ms
with 100 -> 1.2-1.3secs
k
That seems super high for just 1000 docs
b
Yes but I search for 5 terms, it's like 5 searches on each request
k
What is the time with concurrency of 1?
b
avg=110.48ms min=95.41ms med=108.91ms max=302.26ms
test for 10s
k
Do you have exhaustive search enabled?
b
no
I have set prefix: false
Copy code
{
  "filter_by": "` + filterBy + `",
  "collection": "test",
  "q": "test",
  "query_by": "title, about",
  "prefix": false,
  "per_page": "8`",
  "sort_by": "published:desc",
  "page": 1
}
5 payloads like this in "searches": [] field
k
Would you be able to share the dataset and queries with me?
1000 docs should take like 2-3 ms or less per query.
b
And i use typsesense v0.25.1
I have deployed the server in a digital ocean droplet, the response time is not typesense's response time
it's the response time from the server to the client
k
Ah, then that includes network latency
So what you are essentially measuring is the network latency because each search request will take negligible time to be processed.
b
yes but the results seems like there is a lot of delay when there are 100 users
1.3 seconds
k
Unless I know the
search_time_ms
values it's difficult to really ascertain what's going on.
b
"search_time_ms":2
for 5 terms in multi_search
wrong, many queries have "search_time_ms":25
"search_time_ms":42
"search_time_ms":109
k
This is on a single instance or on a cluster?
b
Tested on a single
with 20 concurrent
I had indexed an embedded field in this collection, does it adds up overhead in a normal search?
because it has the vec in memory
k
Try excluding that field in response because they tend to be large.
b
I have excluded it
k
Fetching the document with large fields will be slow as well.
Exclusion will only help with reducing data sent on wire.
b
Yes I use only include_fields
The documents don't have large fields
k
Embedding is a large field
Including field or excluding fields is done only after the large doc is fetched from disk. That might add to the overhead even if you don't use the embedding field for anything.
b
Yes, should I delete it and test again?
k
Yes
b
Ok
Deleted and now I have "search_time_ms":17
"search_time_ms":112
20 concurrent reqs
@Kishore Nallan I installed v0.25.1 in a fresh cluster but I get Multi-node with no leader: refusing to reset peers.. All nodes are state: 4
solved it
@Kishore Nallan Tested on a new fresh instance, 1 document in collection and tested by K6 - 20 concurrent users - multi_search 5 terms. The average response time is avg=228.75ms and in search time ms -> 18 - 83 ms
Is this normal?
1 doc in collection , 5 terms in multi_search and in 1GB RAM - 1 vCPU instance tested - no embeddings
j
I'm actually surprised to hear that Typesense even works on a 1vCPU server, we typically require at least 2vCPUs.
Could you try repeating this with 2vCPUs
b
@Jason Bosco I tested it in 1GB RAM - 1vCPU : 220ms response 20 concurrent 5 terms in multi_search and 1 doc total in collection
4GB RAM - 2 vCPU - 200ms
"search_time_ms":29
"search_time_ms":48
"search_time_ms":53
j
That seems completely off from what I'd expect, especially with just 1 record. For eg, even with 2M records, this example has a search_time_ms of about 10ms: https://recipe-search.typesense.org/?r%5Bquery%5D=Oregano
With 28M books, this returns results in about 5ms: https://books-search.typesense.org/?b%5Bquery%5D=Devops
Could you elaborate on how you're running Typesense? What's the CPU architecture, clock speed of the CPU, disk type (is it an SSD or magnetic disks), are you using Docker, or running natively, are there any load balancers in front, etc?
Also, are you running k6 on the same hardware as Typesense?
b
@Jason Bosco these examples don’t use multi_search. I use multi_search with 5 searches (objects)
The disk is nvme, k6 test from my local pc, cpu is a premium intel, intel Xeon I think, runs in Ubuntu Linux not docker, and tested without load balancer. I host it in digital ocean
Have you tested typesense with multi search, appending 5-10 search objects in searches field?
@Jason Bosco @Kishore Nallan any idea?
j
Even with multiple search objects, I see less 1ms - 16ms in response times:
Copy code
curl -s 'https://qtg5aekc2iosjh93p.a1.typesense.net/multi_search?x-typesense-api-key=8hLCPSQTYcBuK29zY5q6Xhin7ONxHy99' \
        -d '
{
  "searches": [
    {
      "query_by": "title",
      "collection": "r",
      "q": "Oregano"
    },
    {
      "query_by": "title",
      "collection": "r",
      "q": "Pizza"
    },
    {
      "query_by": "title",
      "collection": "r",
      "q": "Chilli"
    },
    {
      "query_by": "title",
      "collection": "r",
      "q": "Pineapple"
    },
    {
      "query_by": "title",
      "collection": "r",
      "q": "Artichoke"
    }
  ]
}' | jq '.results[].search_time_ms'
1
16
1
12
6
b
How many concurrent requests and what are the specs of the server?
j
This was just one request, this is a 4vCPU server
b
Could you try it with 20-100 concurrent reqs?
With 1 request I don’t have any issue
j
That's what the first benchmark on this page did: https://typesense.org/docs/overview/benchmarks.html
Copy code
A dataset containing 2.2 Million recipes (recipe names and ingredients):
Took up about 900MB of RAM when indexed in Typesense
Took 3.6mins to index all 2.2M records
On a server with 4vCPUs, Typesense was able to handle a concurrency of 104 concurrent search queries per second, with an average search processing time of 11ms.
b
One notice, try the test with multi search. This test run with single queries not multi search of 5 searches
In order to reproduce, run the multi search query that you sent me with 100 concurrent requests. What’s the search time?
j
That's going to take a bit of time to setup the benchmarking harness, etc...
b
Just download k6 and run the query with vu 100 in the url that you sent me
@Jason Bosco Are there benchmark tests for multi_search?
j
There is now! • 2.2M recipes • Running on a 4vCPU server (single node). • 5 searches per multi_search request, similar to the curl request above. Results: • Up to around 84 multi_search requests per second (which translates to 84 * 5 = 420 searches per second),
search_time_ms
avg is 6ms, max is 34ms. • After that, CPU is exhausted on the Typesense server (100% CPU usage across all cores), and only then search_time_ms spikes to about 55ms. Adding more CPU will help increase concurrency beyond that if needed.
b
Thank you for the fast response. I appreciate it. Yes that are exactly the response times I get from my tests. 100 concurrent multisearches with average 50-70ms search time
So the solution to this issue, in order to handle more requests, is only by adding more CPUs or is there any other tuning that I can add in search query?
j
Adding CPU would be the solution... You could also enable server-side caching in Typesense (
use_cache: true
). The search_time_ms will be cached as well though, so if you use caching, you want to look at the full http response time
b
Okay right now, I have tested it in a 3 node cluster 2gb ram - 2vCPU and it can handle 200 concurrent requests with average 300ms and search time at 10-50ms . With normal search query, it can handle 350 concurrent requests with average 400ms response time
j
You want to look at CPU usage, measure the response time just before CPU hits say 95%... because otherwise the average would include the high response times once CPU is exhausted
b
What's the best point in order to upgrade my instance? 75% of CPU?
I'll add an alert
j
Yeah 70-75% is a good threshold to upgrade CPU
On a side note, may I know how many concurrent users you're planning for? Depending on the placement / usage of the search feature, if there are
X
users on a site / app, I've typically seen that translate to
20% of X
searches per second, given that not all users are searching at the exact same second
This is a super generalization, but that's the rough metric I've seen
b
I built a suggestions query when a user opens my app
So if I have 10K users that would convert to ~ 100 concurrent
👍 1
This multi_search will run exactly on the launch in order to fetch suggestions for the user
I had implemented it with Embeddings etc.. but as I informed you the cost is too high for this phase
Wouldn't be more performant if the requests in multi_search run in parallel and not in sequence?
j
At high enough concurrency, where the concurrency is higher than the individual number of searches inside a multi_search request, then executing each search inside a multi_search in serial actually reduces context switching overhead and improves performance
Only at low concurrency (when the concurrency is lower than the max number of searches inside a multi search request), executing searches inside a multi_search request in parallel would be slightly more performant...
👍 1
b
Ok, thank you for your time Jason
j
Happy to help!