Ubercart & Performance

Events happening in the community are now at Drupal community events on www.drupal.org.
mpaler's picture

Hi,

I'm running Ubercart on a Mercury server and it appears that Ubercart requires session cookies even for anonymous users (see: https://wiki.fourkitchens.com/pages/viewpage.action?pageId=13828781).

The problem is, that sessions cookies prevent Varnish from caching those pages (see http://groups.drupal.org/node/66888) -- and on top of that, once the user hits an Ubercart page, all other non-Ubercart pages stop being served from Varnish cache as long as that session cookie is present and subsequently performance for those pages is going from ~ 200ms to ~ 1sec.

My question to the group is...is there any way to have Ubercart pages served from varnish cache and still maintain the functionality that the session cookies are required for (i assume shopping cart).

Any other recommendations for max performance with Ubercart pages?

Thanks,
Mike

Comments

I should point out that

mpaler's picture

I should point out that varnished pages are being server usually < 200ms, whereas Ubercart pages usually load 1.5 - 2 sec.

start a session upon adding item to cart

jpstrikesback's picture

check this out http://drupal.org/node/377798#comment-2640030

It doesn't continue caching once someone has added something to their cart, but until then it keeps things flying for anonymous visitors

hope that helps,
JP

what about ajaxify_regions?

ddorian's picture

what about ajaxify_regions? put your cart in an ajax block and it should(thats what i think) work.
or maybe this : http://drupal.org/project/uc_ajax_cart
im interested too cause ill have a project with ubercart so write your solution when u find it

I'm interested in this too!

pcambra's picture

I'm interested in this too!

Removed the cart block and

mpaler's picture

Removed the cart block and session cookies are still being set. :(

Looks like some other module(s) is setting a cookie. Does anyone know any debug code I can use to find out which modules are setting session cookies? This comment (http://groups.drupal.org/node/66888#comment-205203) mentions that I can put some code into drupal_session_commit() in bootstrap.inc but I'm stumped on that method...

if you are using firefox you

jpstrikesback's picture

if you are using firefox you can grab the "web developer" toolbar which let's you inspect each cookie loaded, afaik external cookies shouldn't spook varnish, but of course stuff from the site would.

one thing I forgot to mention in my last reply with that patch was to add this one as well:

http://drupal.org/node/377798#comment-2581898

this uses a pressflow function called drupal_page_is_cacheable() that tells ubercart to chill out on the session cookies...

Cheers,
JP

JP, thanks for the

mpaler's picture

JP, thanks for the tips...I'll definitely give that a try once I figure out my other problem...

I know the problem cookies are Drupal session cookies because they look like this:

SESSb2b1b9ea89332000aa61168b2edafb09=98d6f08918c2b3145d4c55b4152038b8

Still need to figure out what is setting this...

I haven't tested this, but

justintime's picture

I haven't tested this, but I'm pretty sure it will work.

Install and enable the devel module.

Open up includes/session.inc, and navigate to function sess_write. Just before the db_query command, put in this code:

<?php
dpm
($key);
dpm($value);
ddebug_backtrace();
?>

The first two Krumo are the key and the value being written to the session. Might not be much info there. The third krumo will give you the function call backtrace, so that you can figure out what functions are initiating the session modification.

Let me know if it works.

Thanks Justintime, OK, we're

mpaler's picture

Thanks Justintime,

OK, we're getting there...

the stack trace that start with drupal_page_footer()

sess_write (Array, 2 elements)
session_write_close (Array, 4 elements)
drupal_session_commit (Array, 4 elements)
drupal_page_footer (Array, 4 elements)

For testing purposes, I commented out drupal_page_footer() in index.php and Ubercart detail pages no longer set a session cookie. Now I just need to figure out what's so special about the UC detail pages (other nodes aren't triggering drupal_page_footer().
Gonna check all my blocks and templates..

uc_upsell module

mpaler's picture

To those on the edge of their seats...I tracked this problem down to the uc_upsell module. FWIW, I used the trace module and just started flipping switches until something came out. The log had one line that peaked my interest:

#a7c6e90b T+0.007145 [DEBUG  ] $_SESSION = array('uc_upsell_related' => array('node/1375' => array(...)))

Disabling this module enabled uc pages to be served by varnish.

I'm going to audit the upsell module and see what's going on in there that would require a session cookie.

Follow-up

Cayenne's picture

Thanks for posting the follow-up. I was reading this discussion with increasing concern, as I am using UC with varnish etc with no problems that I know of. Glad to know it was a module-specific issue.

Can the title of the discussion be changed to reflect that?

I found

a_c_m's picture

I found http://drupal.org/node/377798#comment-3060720 to be a better patch, but running into more situations where ubercarts module set sessions for anon users.

Wondering if this is the best / only place that this problem is being discussed or if there is more?

Uh oh

Cayenne's picture

Some time in the last few weeks or months ubercart stopped working for anonymous users under Varnish. At least on my site. I'm looking for how to temporarily disable Varnish to see if that is the problem... Anyone know how that's done?

You either pass all request

exlin's picture

You either pass all request directly to backend without cleaning cookies etc (in vlc file)... or change your dns-records and check out settings.php and coment out things relating reverse_proxy.

If this is Pressflow, you can

joestewart's picture

If this is Pressflow, you can temporarily set the caching mode to normal and every visitor will get a session and be passed through to the http server.

It is indeed Pressflow.

Cayenne's picture

It is indeed Pressflow. Tried that, but still no joy.
I did not realize that that would even turn off Caching for the site.

Update: NOT BLAME ON VARNISH

Cayenne's picture

Well, I should have had more faith.
The problem can be found here: http://www.ubercart.org/forum/support/4240/there_are_no_products_your_sh...
Basically, there was no user 0 because I had used autoincrement when porting the database. Fixed now.

Pressflow! Varnish! Mercury!

High performance

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: