# Nginx eval with memc set command very slowly

**URL:** <https://www.ruby-forum.com/t/nginx-eval-with-memc-set-command-very-slowly/184764>\
**Category:** NGINX\
**Created:** [March 8, 2010, 9:30am UTC](https://www.ruby-forum.com/t/nginx-eval-with-memc-set-command-very-slowly/184764 "2010-03-08T09:30:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yaoxinming](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e9bcb4/32.png) [@yaoxinming](https://www.ruby-forum.com/u/yaoxinming)\
**Post date:** [March 8, 2010, 9:30am UTC](https://www.ruby-forum.com/t/nginx-eval-with-memc-set-command-very-slowly/184764/1 "2010-03-08T09:30:45Z")

</div>

when use eval with memc set(all dev by agentzh ) ,I feel the response  
is  
very slowly,but get is very quickly,below is the configue

location /myset {  
eval &var1{  
set $memc\_cmd ‘set’;  
set $memc\_key ‘test1’;  
set $memc\_flags 12345;  
set $memc\_exptime 24;  
set $memc\_value ‘my\_value’;

```
      memc_pass 127.0.0.1:11211;
  }

```

}

does any one has meet this problem,any advice is welcome  
thanks very much

---

<div class="post-metadata">

**Author:** ![yaoxinming](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e9bcb4/32.png) [@yaoxinming](https://www.ruby-forum.com/u/yaoxinming)\
**Post date:** [March 8, 2010, 9:44am UTC](https://www.ruby-forum.com/t/nginx-eval-with-memc-set-command-very-slowly/184764/2 "2010-03-08T09:44:13Z")

</div>

On Mon, Mar 8, 2010 at 4:30 PM, yaoxinming [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> when use eval with memc set(all dev by agentzh ) ,I feel the response is  
> very slowly,but get is very quickly,below is the configue

Which version of ngx\_memc, ngx\_eval, and memcached are you using? And  
which OS?

Cheers,  
-agentzh

---

<div class="post-metadata">

**Author:** ![yaoxinming](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e9bcb4/32.png) [@yaoxinming](https://www.ruby-forum.com/u/yaoxinming)\
**Post date:** [March 12, 2010, 4:05am UTC](https://www.ruby-forum.com/t/nginx-eval-with-memc-set-command-very-slowly/184764/3 "2010-03-12T04:05:47Z")

</div>

On Tue, Mar 9, 2010 at 10:52 AM, agentzh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Mon, Mar 8, 2010 at 4:30 PM, yaoxinming [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > when use eval with memc set(all dev by agentzh ) ,I feel the response is  
> > very slowly,but get is very quickly,below is the configue
> 
> I’m guessing that it’s caused by the “201 Created” status returned by  
> the ngx\_memc set command. According to the source of ngx\_eval, it only  
> accepts “200 OK”. So in case of 201, it simply returns NGX\_DECLINED,  
> which _may_ produce that hang.

I’ve reproduced this hang on my side and spent half of my day tracking  
this issue. But it looked deeper than I had expected.

Using subrequests issued by echo\_location and echo\_location\_async does  
not trigger this hang, but “eval” does. I’m now guessing it has  
something to do with subrequests issued from the rewrite phase because  
the ngx\_echo module starts subrequests in content handlers only.

I don’t have enough time to track this further for now. Will get back  
to this issue some time later. Sorry.

Cheers,  
-agentzh

---

<div class="post-metadata">

**Author:** ![yaoxinming](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e9bcb4/32.png) [@yaoxinming](https://www.ruby-forum.com/u/yaoxinming)\
**Post date:** [March 12, 2010, 4:10am UTC](https://www.ruby-forum.com/t/nginx-eval-with-memc-set-command-very-slowly/184764/4 "2010-03-12T04:10:28Z")

</div>

On Fri, Mar 12, 2010 at 11:05 AM, agentzh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve reproduced this hang on my side and spent half of my day tracking  
> this issue. But it looked deeper than I had expected.

Forgot to mention that the “post subrequest” handler does not get  
called in this case. It seems ngx\_http\_upstream does not call  
finalize\_request. Most likely an issue in ngx\_memc’s input filters.

If others can take a look at the ngx\_http\_memc\_empty\_filter\_init and  
ngx\_http\_memc\_empty\_filter functions in ngx\_memc below, I’ll really  
appreciate that:

```
http://github.com/agentzh/memc-nginx-module/blob/master/src/ngx_http_memc_response.rl

```

Thanks!  
-agentzh

---

<div class="post-metadata">

**Author:** ![yaoxinming](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e9bcb4/32.png) [@yaoxinming](https://www.ruby-forum.com/u/yaoxinming)\
**Post date:** [March 9, 2010, 3:53am UTC](https://www.ruby-forum.com/t/nginx-eval-with-memc-set-command-very-slowly/184764/5 "2010-03-09T03:53:01Z")

</div>

On Mon, Mar 8, 2010 at 4:30 PM, yaoxinming [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> when use eval with memc set(all dev by agentzh ) ,I feel the response is  
> very slowly,but get is very quickly,below is the configue

I’m guessing that it’s caused by the “201 Created” status returned by  
the ngx\_memc set command. According to the source of ngx\_eval, it only  
accepts “200 OK”. So in case of 201, it simply returns NGX\_DECLINED,  
which _may_ produce that hang.

I’m currently in the Hangzhou city and far from my laptop in Beijing.  
So I can’t confirm this right now. I’ll look into this and hopefully  
do a fix in my branch of ngx\_eval if it’s indeed the case.

Thanks for the report!  
-agentzh

---

<div class="post-metadata">

**Author:** ![yaoxinming](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e9bcb4/32.png) [@yaoxinming](https://www.ruby-forum.com/u/yaoxinming)\
**Post date:** [April 10, 2010, 4:41pm UTC](https://www.ruby-forum.com/t/nginx-eval-with-memc-set-command-very-slowly/184764/6 "2010-04-10T16:41:29Z")

</div>

On Fri, Mar 12, 2010 at 11:09 AM, agentzh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Fri, Mar 12, 2010 at 11:05 AM, agentzh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I’ve reproduced this hang on my side and spent half of my day tracking  
> > this issue. But it looked deeper than I had expected.
> 
> Forgot to mention that the “post subrequest” handler does not get  
> called in this case. It seems ngx\_http\_upstream does not call  
> finalize\_request. Most likely an issue in ngx\_memc’s input filters.

I’ve fixed this bug in ngx\_memc v0.08:

```
http://wiki.nginx.org/NginxHttpMemcModule#v0.08

```

ngx\_memc didn’t support subrequests in memory for memcached commands  
other than “get” in earlier versions. Now it’s finally fixed by  
setting r-\>upstream-\>buffer’s .pos and .last pointers properly in the  
upstream input filters.

Also I’ve fixed a nasty bug in the discard\_bufs function in my fork of  
ngx\_eval. It used to produce random hanging or segfaults when  
eval\_subrequest\_in\_memory was turned off.

Thanks!  
-agentzh
