# Query timing: 'took' value and what I'm measuring

**URL:** <https://discuss.elastic.co/t/query-timing-took-value-and-what-im-measuring/9870>\
**Category:** Elasticsearch\
**Created:** [November 28, 2012, 8:06pm UTC](https://discuss.elastic.co/t/query-timing-took-value-and-what-im-measuring/9870 "2012-11-28T20:06:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Weitzenfeld](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_weitzenfeld/32/2593_2.png) [@Daniel\_Weitzenfeld](https://discuss.elastic.co/u/Daniel_Weitzenfeld)\
**Post date:** [November 28, 2012, 8:06pm UTC](https://discuss.elastic.co/t/query-timing-took-value-and-what-im-measuring/9870/1 "2012-11-28T20:06:08Z")

</div>

I'm running some tests on Elastic Search to see if it's performant in our  
particular situation.  
My queries average ~130ms, according to the 'took' field returned by  
Elastic Search. But when I time the query round trip, I'm getting ~820ms.  
What might be causing this discrepancy? Am I misunderstanding the 'took'  
field?

My setup:  
elastic search 0.19.0  
amazon ec2 m2.xlarge box running Centos  
talking to elastic search via python pyes package, e.g.:

from pyes import \*  
import time

conn = ES('127.0.0.1:9200')

now=time.time()  
response=conn.search\_raw(my\_query\_dictionary)  
now2=time.time()

now2-now  
.82

response.took  
130

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 29, 2012, 11:27am UTC](https://discuss.elastic.co/t/query-timing-took-value-and-what-im-measuring/9870/2 "2012-11-29T11:27:22Z")

</div>

The time reported by elasticsearch in the "took" field is the time that it  
took elasticsearch to process the query on its side. It doesn't include

- serializing the request into JSON on the client

- sending the request over the network

- deserializing the request from JSON on the server

- serializing the response into JSON on the server

- sending the response over the network

- deserializing the response from JSON on the client

On Wednesday, November 28, 2012 3:06:08 PM UTC-5, Daniel Weitzenfeld wrote:

> I'm running some tests on Elastic Search to see if it's performant in our  
> particular situation.  
> My queries average ~130ms, according to the 'took' field returned by  
> Elastic Search. But when I time the query round trip, I'm getting ~820ms.  
> What might be causing this discrepancy? Am I misunderstanding the 'took'  
> field?
> 
> My setup:  
> Elasticsearch 0.19.0  
> amazon ec2 m2.xlarge box running Centos  
> talking to Elasticsearch via python pyes package, e.g.:
> 
> from pyes import \*  
> import time
> 
> conn = ES('127.0.0.1:9200')
> 
> now=time.time()  
> response=conn.search\_raw(my\_query\_dictionary)  
> now2=time.time()
> 
> now2-now  
> .82
> 
> response.took  
> 130

--

---

<div class="post-metadata">

**Author:** ![Daniel\_Weitzenfeld](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_weitzenfeld/32/2593_2.png) [@Daniel\_Weitzenfeld](https://discuss.elastic.co/u/Daniel_Weitzenfeld)\
**Post date:** [November 29, 2012, 2:20pm UTC](https://discuss.elastic.co/t/query-timing-took-value-and-what-im-measuring/9870/3 "2012-11-29T14:20:26Z")

</div>

Got it, thanks. I'm going to try Thrift and faster JSON serializers.

On Thursday, November 29, 2012 6:27:22 AM UTC-5, Igor Motov wrote:

> The time reported by elasticsearch in the "took" field is the time that it  
> took elasticsearch to process the query on its side. It doesn't include
> 
> - serializing the request into JSON on the client
> 
> - sending the request over the network
> 
> - deserializing the request from JSON on the server
> 
> - serializing the response into JSON on the server
> 
> - sending the response over the network
> 
> - deserializing the response from JSON on the client
> 
> On Wednesday, November 28, 2012 3:06:08 PM UTC-5, Daniel Weitzenfeld wrote:
> 
> > I'm running some tests on Elastic Search to see if it's performant in our  
> > particular situation.  
> > My queries average ~130ms, according to the 'took' field returned by  
> > Elastic Search. But when I time the query round trip, I'm getting ~820ms.  
> > What might be causing this discrepancy? Am I misunderstanding the 'took'  
> > field?
> > 
> > My setup:  
> > Elasticsearch 0.19.0  
> > amazon ec2 m2.xlarge box running Centos  
> > talking to Elasticsearch via python pyes package, e.g.:
> > 
> > from pyes import \*  
> > import time
> > 
> > conn = ES('127.0.0.1:9200')
> > 
> > now=time.time()  
> > response=conn.search\_raw(my\_query\_dictionary)  
> > now2=time.time()
> > 
> > now2-now  
> > .82
> > 
> > response.took  
> > 130

--

---

<div class="post-metadata">

**Author:** ![Daniel\_Weitzenfeld](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_weitzenfeld/32/2593_2.png) [@Daniel\_Weitzenfeld](https://discuss.elastic.co/u/Daniel_Weitzenfeld)\
**Post date:** [December 3, 2012, 3:21pm UTC](https://discuss.elastic.co/t/query-timing-took-value-and-what-im-measuring/9870/4 "2012-12-03T15:21:29Z")

</div>

Switching to Thrift shaved off a half a second per query. Awesome.

On Thursday, November 29, 2012 9:20:26 AM UTC-5, Daniel Weitzenfeld wrote:

> Got it, thanks. I'm going to try Thrift and faster JSON serializers.
> 
> On Thursday, November 29, 2012 6:27:22 AM UTC-5, Igor Motov wrote:
> 
> > The time reported by elasticsearch in the "took" field is the time that  
> > it took elasticsearch to process the query on its side. It doesn't include
> > 
> > - serializing the request into JSON on the client
> > 
> > - sending the request over the network
> > 
> > - deserializing the request from JSON on the server
> > 
> > - serializing the response into JSON on the server
> > 
> > - sending the response over the network
> > 
> > - deserializing the response from JSON on the client
> > 
> > On Wednesday, November 28, 2012 3:06:08 PM UTC-5, Daniel Weitzenfeld  
> > wrote:
> > 
> > > I'm running some tests on Elastic Search to see if it's performant in  
> > > our particular situation.  
> > > My queries average ~130ms, according to the 'took' field returned by  
> > > Elastic Search. But when I time the query round trip, I'm getting ~820ms.  
> > > What might be causing this discrepancy? Am I misunderstanding the 'took'  
> > > field?
> > > 
> > > My setup:  
> > > Elasticsearch 0.19.0  
> > > amazon ec2 m2.xlarge box running Centos  
> > > talking to Elasticsearch via python pyes package, e.g.:
> > > 
> > > from pyes import \*  
> > > import time
> > > 
> > > conn = ES('127.0.0.1:9200')
> > > 
> > > now=time.time()  
> > > response=conn.search\_raw(my\_query\_dictionary)  
> > > now2=time.time()
> > > 
> > > now2-now  
> > > .82
> > > 
> > > response.took  
> > > 130

--

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [December 3, 2012, 7:59pm UTC](https://discuss.elastic.co/t/query-timing-took-value-and-what-im-measuring/9870/5 "2012-12-03T19:59:05Z")

</div>

[https://github.com/esnme/ultrajson](https://github.com/esnme/ultrajson) could also be worth a try for Python  
clients.

Jörg

--

---

<div class="post-metadata">

**Author:** ![jschelle\_2](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jschelle\_2](https://discuss.elastic.co/u/jschelle_2)\
**Post date:** [July 23, 2013, 1:40pm UTC](https://discuss.elastic.co/t/query-timing-took-value-and-what-im-measuring/9870/6 "2013-07-23T13:40:49Z")

</div>

@Igor,

I know this is an old thread, but it seemed like the right place for this.  
Does 'took' include the time that the request sat in the queue before a  
thread from the pool was available? Is this the best "response time"  
measurement to use for assessing your maximum shard size?

On Thursday, November 29, 2012 6:27:22 AM UTC-5, Igor Motov wrote:

> The time reported by elasticsearch in the "took" field is the time that it  
> took elasticsearch to process the query on its side. It doesn't include
> 
> - serializing the request into JSON on the client
> 
> - sending the request over the network
> 
> - deserializing the request from JSON on the server
> 
> - serializing the response into JSON on the server
> 
> - sending the response over the network
> 
> - deserializing the response from JSON on the client
> 
> On Wednesday, November 28, 2012 3:06:08 PM UTC-5, Daniel Weitzenfeld wrote:
> 
> > I'm running some tests on Elastic Search to see if it's performant in our  
> > particular situation.  
> > My queries average ~130ms, according to the 'took' field returned by  
> > Elastic Search. But when I time the query round trip, I'm getting ~820ms.  
> > What might be causing this discrepancy? Am I misunderstanding the 'took'  
> > field?
> > 
> > My setup:  
> > Elasticsearch 0.19.0  
> > amazon ec2 m2.xlarge box running Centos  
> > talking to Elasticsearch via python pyes package, e.g.:
> > 
> > from pyes import \*  
> > import time
> > 
> > conn = ES('127.0.0.1:9200')
> > 
> > now=time.time()  
> > response=conn.search\_raw(my\_query\_dictionary)  
> > now2=time.time()
> > 
> > now2-now  
> > .82
> > 
> > response.took  
> > 130

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [July 23, 2013, 2:09pm UTC](https://discuss.elastic.co/t/query-timing-took-value-and-what-im-measuring/9870/7 "2013-07-23T14:09:33Z")

</div>

It measures "wall time" of query execution in the transport level of  
elasticsearch, which includes any queue waiting time. It basically  
everything after request from deserialized from JSON and before the  
response serialized into JSON again. The idea behind assessing the maximum  
shard size is to load this shard until you have unacceptably slow  
performance. If you measure performance in terms of time reported in the  
'took' parameter then you can use it. If you measure performance in terms  
of end-to-end response time, then you need to measure end-to-end response  
time.

On Tuesday, July 23, 2013 9:40:49 AM UTC-4, shadow000fire wrote:

> @Igor,
> 
> I know this is an old thread, but it seemed like the right place for  
> this. Does 'took' include the time that the request sat in the queue  
> before a thread from the pool was available? Is this the best "response  
> time" measurement to use for assessing your maximum shard size?
> 
> On Thursday, November 29, 2012 6:27:22 AM UTC-5, Igor Motov wrote:
> 
> > The time reported by elasticsearch in the "took" field is the time that  
> > it took elasticsearch to process the query on its side. It doesn't include
> > 
> > - serializing the request into JSON on the client
> > 
> > - sending the request over the network
> > 
> > - deserializing the request from JSON on the server
> > 
> > - serializing the response into JSON on the server
> > 
> > - sending the response over the network
> > 
> > - deserializing the response from JSON on the client
> > 
> > On Wednesday, November 28, 2012 3:06:08 PM UTC-5, Daniel Weitzenfeld  
> > wrote:
> > 
> > > I'm running some tests on Elastic Search to see if it's performant in  
> > > our particular situation.  
> > > My queries average ~130ms, according to the 'took' field returned by  
> > > Elastic Search. But when I time the query round trip, I'm getting ~820ms.  
> > > What might be causing this discrepancy? Am I misunderstanding the 'took'  
> > > field?
> > > 
> > > My setup:  
> > > Elasticsearch 0.19.0  
> > > amazon ec2 m2.xlarge box running Centos  
> > > talking to Elasticsearch via python pyes package, e.g.:
> > > 
> > > from pyes import \*  
> > > import time
> > > 
> > > conn = ES('127.0.0.1:9200')
> > > 
> > > now=time.time()  
> > > response=conn.search\_raw(my\_query\_dictionary)  
> > > now2=time.time()
> > > 
> > > now2-now  
> > > .82
> > > 
> > > response.took  
> > > 130

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:25am UTC](https://discuss.elastic.co/t/query-timing-took-value-and-what-im-measuring/9870/8 "2017-07-06T02:25:02Z")

</div>


