Ruby Ingest Timeout


I'm hitting sporadic timeouts when bulk indexing documents into App Search, using the Ruby client.

I have a 3 node cluster setup and I'm giving 4GB of heap to the App Search server.

Here's what my client code looks like:

require 'elastic-app-search'
require 'json'
require 'faker'

client =
  api_key: 'private-my-key',
  api_endpoint: 'https://my-endpoint/api/as/v1/')

engine_name = 'test'
documents = []

for i in 1..1000000
  doc = {}
  doc['id'] = i
  doc['timestamp'] =
  doc['author'] = Faker::Book.title
  doc['author'] =
  doc['publisher'] = Faker::Book.publisher
  doc['category'] = Faker::Book.genre
  doc['overview'] = Faker::Lorem.paragraphs(number: 1)[0]
  doc['body'] = Faker::Lorem.paragraphs(number: 10).join(' ')

  documents << doc

  if i % 100 == 0
    document_receipts = client.index_documents(engine_name, documents)
    puts "Uploaded #{i} documents"
    documents = []

And here's the timeout I'm hitting:

Traceback (most recent call last):
	20: from as-index.rb:12:in `<main>'
	19: from as-index.rb:12:in `each_line'
	18: from as-index.rb:26:in `block in <main>'
	17: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/elastic-app-search-7.7.0/lib/elastic/app-search/client/documents.rb:57:in `index_documents'
	16: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/elastic-app-search-7.7.0/lib/elastic/app-search/request.rb:21:in `post'
	15: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/elastic-app-search-7.7.0/lib/elastic/app-search/request.rb:40:in `request'
	14: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/timeout.rb:108:in `timeout'
	13: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/elastic-app-search-7.7.0/lib/elastic/app-search/request.rb:62:in `block in request'
	12: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/http.rb:1470:in `request'
	11: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/http.rb:920:in `start'
	10: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/http.rb:1472:in `block in request'
	 9: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/http.rb:1479:in `request'
	 8: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/http.rb:1506:in `transport_request'
	 7: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/http.rb:1506:in `catch'
	 6: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/http.rb:1509:in `block in transport_request'
	 5: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/http/response.rb:29:in `read_new'
	 4: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/http/response.rb:40:in `read_status_line'
	 3: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/protocol.rb:201:in `readline'
	 2: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/protocol.rb:191:in `readuntil'
	 1: from /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/protocol.rb:217:in `rbuf_fill'
/home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/net/protocol.rb:217:in `wait_readable': execution expired (Timeout::Error)

It's very repeatable just not consistent, in terms of when it gets thrown during an ingest run.

What's the best way to track down what's causing this timeout?

I'm trying to ingest millions of documents and the ingest will run for quite a while before it throws one of these exceptions. I do see a 500 in the API Logs section of the Admin UI, with the following response:

Response Body
  "errors": [
    "Internal server error. Please check your application server logs for more details and contact Elastic support if the problem persists"

I then go look through /var/log/enterprise-search/app-server.log.* for the time window the error occurred around. It looks like this is the culprit:

[2020-06-18T18:24:27.755+00:00][10820][2372][app-server][ERROR]: [24f10217-8383-44cf-90fe-e902d7dfb0ff] /tmp/jetty- `body': Could not read from stream: Read timed out (Manticore::StreamClosedException)
        from /tmp/jetty- `block in call'
        from /tmp/jetty- `handleResponse'
        from /tmp/jetty- `call'
        from /tmp/jetty- `call'
        from /tmp/jetty- `call'
        from /tmp/jetty- `build_response'
        from /tmp/jetty- `run_request'
        from /tmp/jetty- `es_http_request'
        from /tmp/jetty- `request'
        from /tmp/jetty- `request'
        from /tmp/jetty- `request'
        from /tmp/jetty- `bulk_request'
        from /tmp/jetty- `bulk_create'
        from /tmp/jetty- `bulk_create'
        from /tmp/jetty- `bulk_action'
        from /tmp/jetty- `block in save_constraints!'
        from org/jruby/ `each'
        from /tmp/jetty- `save_constraints!'
        from /tmp/jetty- `save_documents_with_constraints'
        from /tmp/jetty- `save_documents'
        from /tmp/jetty- `save_documents'
        from /tmp/jetty- `save_documents'

It's hard to determine what record is causing the error and why.

I'm bulk inserting 100 documents at a time, trying to get to ~5M documents in App Search.

On average, I'll get around 500K documents ingested in a successful run. But after a few hours of the job running, I'll come back to the client returning a client-side timeout (with no other error) and this (above) in the server-side logs. I restart the job and it times out at a different place, after running again for a few hours.

Any suggestions?

The solution here is to set the overall_timeout parameter. It defaults to 15 seconds.

client = 30)

I set mine to 300 and was able to ingest without hitting that Timeout error.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.