Skip to content

[$300] Initial Page Load #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rootelement opened this issue Nov 30, 2020 · 15 comments
Closed

[$300] Initial Page Load #247

rootelement opened this issue Nov 30, 2020 · 15 comments

Comments

@rootelement
Copy link
Contributor

Looks like when you go to https://discussions.topcoder.com, it takes ~9seconds for the page to load. After a couple page loads, i sorted the load time descending and see this:
Screen Shot 2020-11-30 at 10 33 51 AM
Screen Shot 2020-11-30 at 10 32 01 AM

@jmgasper jmgasper changed the title Initial Page Load [$75] Initial Page Load Nov 30, 2020
@jmgasper
Copy link
Collaborator

Contest https://www.topcoder.com/challenges/30154851 has been created for this ticket.

This is an automated message for ghostar via Topcoder X

@jmgasper
Copy link
Collaborator

Contest https://www.topcoder.com/challenges/30154851 has been updated - it has been assigned to obog.

This is an automated message for ghostar via Topcoder X

@jmgasper
Copy link
Collaborator

@atelomycterus - Can we make speeding this up top priority please?

@jmgasper jmgasper added the P0 label Nov 30, 2020
@atelomycterus
Copy link
Collaborator

@jmgasper Yes, sure

@atelomycterus
Copy link
Collaborator

@jmgasper There are 2 main issues.

Screens

Recent discussion page with a topcoder DB dump from my local env.
I've made the screens from DEV for statistics. We can compare performance after deploying.

Before any changes :
image

image

Controller - FIXED

Please apply PR -#249. Thanks!
Discussion Controller executed 31-45 sec my local env. The time of execution was count of different Users on the recent page * 0,5 sec. It executes about 3-5 secs in DEV.
image

Vanilla loads a recent discussion page and joins a list of users. UserModel loads users and checks Photo.
This piece of code works about 0,5 sec per user.

if ($column == 'Photo') {
  if ($value && !isUrl($value)) {
	$value = Gdn_Upload::url(changeBasename($value, 'n%s'));
  } elseif (!$value) {
	$value = UserModel::getDefaultAvatarUrl($user);
 }
}

After commenting it DiscussionController for recent page executes <1 sec.
image

Page rendering

Page rendering is slow due to our custom Topcoder link. Each discussion was rendered about 3,2-3,8 sec. In DEV i think about 0,5-1 sec per a discussion. Before rendering User link we request Topcoder API (Roles, Picture, Member rating) to apply proper css styles. We don't have cache for that.
image

Using default Vanilla function to render user link. The page was rendered 3 times faster.
image
image

In Dev Recent page is rendered about 20 sec, there are about 40 user links.
image

DEV

I did screens for statistics. So we can compare after fixing custom Topcoder link.

Recent page - about 40 user links:
image

https://vanilla.topcoder-dev.com/discussion/1715/home-challenges-forum-development-forums-sandy-forum-receiver-code-documents-new-discussio#latest - 1 user link:
image

https://vanilla.topcoder-dev.com/discussion/1633/review-time-extends#latest - about 25 user links:
image

https://vanilla.topcoder-dev.com/discussion/1838/test-editor-3333#latest 3 user links:
image

@atelomycterus
Copy link
Collaborator

@jmgasper I'm implementing cache in Topcoder plugin. Vanilla provides a cache layer.

@jmgasper jmgasper changed the title [$75] Initial Page Load [$200] Initial Page Load Dec 1, 2020
@jmgasper jmgasper changed the title [$200] Initial Page Load [$300] Initial Page Load Dec 1, 2020
@atelomycterus
Copy link
Collaborator

atelomycterus commented Dec 2, 2020

@jmgasper Keep you updated. I've implemented caching Topcoder User Details in Topcoder plugin. I started testing and enabled cache locally. Vanilla is full of surprises. After enabling cache, Topcoder auth isn't working because getByUserName returns always empty. It uses cached data and user wasn't found. I've fixed it. Then the same issues with permissions and roles. Vanilla couldn't start a new session because couldn't find permissions by UserID in cache. It throws errors, without any loading data from DB. Some Vanilla methods only use data from cache, others check cache and load DB.

I'm trying to fix these issues. I haven't used cache in my local env before. Sorry about that.
So don't enable cache.

$Configuration['Cache']['Enabled'] = getenv('CACHE_ENABLED'); 

DEV

I've checked cache parameters and I couldn't find 'Cache.Enabled' and 'Cache.Method' in DEV. MEMCACHED_SERVER has a value. If getenv('CACHE_ENABLED') is empty then cache is disabled.
In addition, I remember when I fixed the Guests permissions issue that the active cache (Gdn_Cache::activeCache()) returned false in DEV.

PROD

Could you check if getenv('CACHE_ENABLED') and getenv('CACHE_METHOD') are defined for PROD?

@atelomycterus
Copy link
Collaborator

atelomycterus commented Dec 2, 2020

@jmgasper Ready for your review.
PRs:
#251
topcoder-platform/forums-plugins#52
topcoder-platform/forums-groups-plugin#36

Configuration

Please check getenv('CACHE_ENABLED'), getenv('CACHE_METHOD') for Dev env. See my prev comment, these params looks like empty.

Example config with working memcached:

$Configuration['Cache']['Enabled'] = true; // getenv('CACHE_ENABLED');
$Configuration['Cache']['Method'] = 'memcached';//getenv('CACHE_METHOD');
$Configuration['Cache']['Memcached']['Store']=['memcached-local:11211']; // getenv('MEMCACHED_SERVER');

You can see cache info with debug bar. If Vanilla Cache is disabled then 'Active Cache' is false.
image

Topcoder plugins

PhotoUrl, IsAdmin and Rating are cached only. Gdn_Cache::FEATURE_EXPIRY is 3600. It allows items to auto-expire.

Results

Note that debugbar has little effect on page rendering.

No memcached

Page rendering was 85-86 sec for each request.

Memcached used, no changes in Topcoder plugin

Vanilla caches data (categories, users, roles) in memcached. Page rendering was 85-86 sec for each request.
image

Memcached used + changes in Topcoder plugin

Topcoder data (PhoroUrl, Rating, isAdmin) is cached.

  1. Page rendering is 12-14 sec for the first request, no cached data in memcached due to re-build services locally.
    image

image

  1. Page rendering is < 1 sec (0.6-0.8 sec) for the next requests. Controller is about 2 sec.
    image

Rendering per a discussion:
image

Topcoder Data in cache
image

TODO

There is still room for improvement.

  • We can cache challenge roles per user (Topcoder Challenge API). It helps to render a discussion page/ a group page faster.
    Now Discussion page may load slowly if there are many comments on the page or a list of @userXXX (users mentioned).
    Group page may load slowly if there are many members because we request challenge roles and append it to handles.

@atelomycterus
Copy link
Collaborator

@jmgasper Please apply PR-#252. Thanks!

$Configuration['Cache']['Enabled'] must be boolean, getenv('CACHE_ENABLED') returns string value. I fixed it.

$Configuration['Cache']['Enabled'] = strtolower(getenv('CACHE_ENABLED')) === "true";

Sorry about that.

@jmgasper
Copy link
Collaborator

jmgasper commented Dec 2, 2020

@atelomycterus - We set those config values in dev:

"CACHE_ENABLED": true,
  "CACHE_METHOD": "memcached"

I'm redeploying now, thanks.

@jmgasper
Copy link
Collaborator

jmgasper commented Dec 2, 2020

@atelomycterus - Still seems a bit slow in dev - anything I can do to help debug what's still going on? Thanks!

@jmgasper
Copy link
Collaborator

jmgasper commented Dec 2, 2020

@atelomycterus - One other thing - is there a key or keys we can check in the memcache to make sure that the caching is working? Thanks!

@atelomycterus
Copy link
Collaborator

@jmgasper I've checked DEV.

Memcached

The Vanilla cache is enabled and works.
image

Results in DEV

I've checked page rendering (#247 (comment)):
image

image

image

@atelomycterus
Copy link
Collaborator

atelomycterus commented Dec 3, 2020

@jmgasper

@atelomycterus - One other thing - is there a key or keys we can check in the memcache to make sure that the caching is working? Thanks!

You can connect to memcached with telnet and use 'stats' or 'get' ('get YOUR_KEY').
I used php -r '$c = new Memcached(); $c->addServer("memcached-local", 11211); var_dump( $c->getAllKeys() );'
This command should be run at Vanilla server because it uses php.

Displayed all keys:
image

@jmgasper
Copy link
Collaborator

jmgasper commented Dec 3, 2020

Payment task has been updated: https://software.topcoder.com/review/actions/ViewProjectDetails?pid=30154851

This is an automated message for ghostar via Topcoder X

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants