Jump to content

Photo
* * * * * 1 votes

[SE4] Speed up SocialEngine using Memcached / APC /Xcache


  • Please log in to reply
9 replies to this topic

#1 Les

Les

    Blue Team Lima 1

  • Moderators
  • Level
  • 5,126 points
  • 3,428 posts
    • Gender:Male
    • Location:Westland, Michigan U.S.A.
    • Software:SE 4.8.x


Users Awards

Posted 02 February 2016 - 08:05 PM

Attached File  se4x32.gif   995bytes   0 downloads Speed up SocialEngine using Memcached / APC /Xcache


Recently we were working on the migration of socialengine v2 to socialengine v4.1.4 for one of our clients. The current socialengine website was loading very slowly even though there were not much users on the site. We tried to speed up the site by using the APC opcode, compressing the html, js and css but couldn’t improve the performance much. There were various reasons for the slowdown but main reason was due to unorganized and inefficient customized source code developer by the earlier vendor. The customized code was tightly coupled with the socialengine’s core code that we couldn’t migrate it to socialengine v4.1.4 using the migration scripts. We had to rewrite the customize code from the scratch for the obvious reasons after migrating the socialengibe v2 to v4.1.4. We shall discuss about the social migration in different article and in this article would focus on speeding up the socialengine v4.x using the caching.


Caching is the vital part of any website and helps website to respond quickly. Social engine allows variety of caching solutions like file based, memcache, APC (Alternative Php cache) and Xcache for the platform. Using one of the caching solution would speed up performance of the socialengine 4. If you don’t have configured the memcached or APC or Xcache then you can use file system based caching but its much slower than the other caching solutions. We would recommend to use one of the caching solution to speed up the socialengine. In this article, we should show the instructions to install and configure caching for socialengine. We assume that the socialengine is running on the production mode.


Memcache is a distributed caching which can be used in a scenario where application is running on several web servers. All the data stored in memcached would be distributed across the all webservers. Since it requires dealing with network protocols in order to support the distributed part of caching, it is slower compared to APC/XCache cache in case of application is running on single server. While using APC/Xcache on distributed system would require manual copy of data on all the servers. APC/XCache are non distributed cache and data can be stored on the local web-server only. APC/XCache op-code caching saves on the compile and execution times of PHP thus loading of the socialengine become faster. Some people got confused whether Memcached can be used with the APC/Xcache (opcode). We can use the combination of MEMcached (as data storage) and APC/Xcache (as opcode for php).


Now we are going to show the installation and configuration of Memcached, APC and Xcache for socialengine on Centos.


Install and Configure Memcached with socialengine


1) Install memcached


 

  1.   wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
  2. tar zxpfv memcached*
  3. cd memcached-1.4.5
  4. ./configure
  5. make install
  6. ./memcached -u memcached -d -m 64 -l 127.0.0.1 -p 11211

 

2) Install PHP Extension.

 

Download and install latest stable memcache version from PECL.


 
  1. wget http://pecl.php.net/get/memcache-2.2.5.tgz
  2. tar zxvf memcache-2.2.5.tgz
  3. cd memcache-2.2.5
  4. phpize
  5. ./configure
  6. make
  7. make install

 

memcache.so will be install in php modules directory, now enable memcache.so extension in php.ini

 

To find out your php.ini location, execute following command

 
  1. php -i | grep php.ini
  2. Configuration File (php.ini) Path = /usr/local/lib
  3. Loaded Configuration File = /usr/local/lib/php.ini
  4.  
  5. vi /usr/local/lib/php.ini
  6.  
  7. extension = memcache.so

 

save the file and restart httpd server.


 
  1. /etc init.d/httpd restart

 

To check is memcache extension loaded inphp, execute following command.


 
  1. php -i | grep memcache
  2. memcache
  3. memcache support = enabled

 

3) Configure memcached in socialengine

 

1. Go to http://yourserver/index.php/admin/core/settings/performance

2. Enable caching with memcached and add parameters specific to memcached.

3. Save the changes

 

Install and Configure APC with socialengine

By default there can be one opcode caching for php so if there is already any opcode (eaccelerator etc.) then disable that to allow APC to act as opcode.

 

1) Install APC


 
  1. yum install php-pear
  2. yum install php-devel
  3. yum install httpd-devel
  4. yum install pcre-devel
  5. pecl install apc
  6. echo "extension=apc.so"  /etc/php.d/apc.ini
  7. /etc/init.d/httpd restart

 

To check is APC extension loaded in php, execute following command.


 
  1. php phpinfo()
  2. apc.enabled=1

 

2) Configure APC in socialengine

 

1. Go to http://yourserver/index.php/admin/core/settings/performance

2. Enable caching with APC option.

3. Save the changes

 

Install and Configure Xcache with socialengine

 

1) Install Xcache


 
  1. wget http://xcache.lighttpd.net/pub/Releases/1.3.1/xcache-1.3.1.tar.gz
  2. tar -zxvf xcache-1.3.1.tar.gz
  3. cd xcache-1.3.1
  4. phpize
  5. ./configure --enable-xcache
  6. make
  7. make install

 

You would need to change timelib_structs.h to install Xcache

Find line:


 
  1. #include

 

Replace / update as follows:


 
  1. #include "timelib_config.h"

 

Create one password for Xcache administration:

 

# echo -n “yourpassword”| md5sum

 

Then open php.ini, and add the following append configuration directives.


 
  1. [xcache-common]
  2. zend_extension      = /usr/lib/php/modules/xcache.so
  3.  
  4. [xcache.admin]
  5. xcache.admin.user   = "admin"
  6. ;how to create md5 pwd: echo -n "password"| md5sum
  7. xcache.admin.pass   = "a364b1d54799c713b8a377de50f8ed3c"  #easywms.com
  8.  
  9. [xcache]
  10. ; Change xcache.size to tune the size of the opcode cache
  11. ; to disable: xcache.size=0
  12. ; to enable : xcache.size=64M etc (any size > 0) and your system mmap allows
  13. ; someone said, if =64 will get problem
  14.  
  15. xcache.size         = 32M
  16. xcache.shm_scheme   = "mmap"
  17. ; set to cpu count (cat /proc/cpuinfo |grep -c processor)
  18.  
  19. xcache.count        = 4
  20. ; just a hash hints, you can always store count(items) slots
  21.  
  22. xcache.slots        = 8K
  23. ; ttl of the cache item, 0=forever
  24.  
  25. xcache.ttl          = 0
  26. ; interval of gc scanning expired items, 0=no scan, other values is in seconds
  27.  
  28. xcache.gc_interval  = 0
  29.  
  30. ; Change xcache.var_size to adjust the size of variable cache
  31. ; same as aboves but for variable cache, if you have not used xcache function in script,forget it
  32.  
  33. xcache.var_size     = 8M
  34. xcache.var_count    = 1
  35. xcache.var_slots    = 8K
  36. xcache.var_ttl      = 0
  37. xcache.var_maxttl   = 0
  38. xcache.var_gc_interval =     300
  39.  
  40. xcache.test         = Off
  41. xcache.readonly_protection = On
  42. ; for *nix, xcache.mmap_path is a file path, not directory.
  43. ; Use something like "/tmp/xcache" if you want to turn on ReadonlyProtection
  44. ; 2 group of php wont share the same /tmp/xcache
  45. ; for win32, xcache.mmap_path=anonymous map name, not file path
  46.  
  47. xcache.mmap_path    = "/tmp/xcache"
  48. ; leave it blank(disabled) or "/tmp/phpcore/"
  49. ; make sure its writable by php (without checking open_basedir)
  50.  
  51. xcache.coredump_directory =   ""
  52. ; per request settings
  53.  
  54. xcache.cacher       = On
  55. xcache.stat         = On
  56. xcache.optimizer    = Off
  57.  
  58. [xcache.coverager]
  59. ; per request settings
  60. ; enable coverage data collecting for xcache.coveragedump_directory and
  61. ; xcache_coverager_start/stop/get/clean() functions (will hurt executing performance)
  62.  
  63. xcache.coverager    = On
  64. ; ini only settings
  65. ; make sure its readable (care open_basedir) by coverage viewer script
  66. ; requires xcache.coverager=On
  67.  
  68. xcache.coveragedump_directory = ""

 

2) Configure Xcache in socialengine

 

1. Go to http://yourserver/index.php/admin/core/settings/performance

2. Enable caching with Xcache option and add user’s credentials.

3. Save the changes

 

Conclusion

We found Xcache little faster than the Memcached/APC for socialengine 4 and used it for our client’s website.

 

Please feel free to comments or suggest other technique of caching.

 

It is possible to do performance tuning by yourself, or getting developers to do this. However, in our experience, the community owners are really more focused on making their community an engaging experience via functionality or graphics. Similarly, most developers can write PHP code, but very few have the experience of various tools for improving performance. One of the solutions we thought was to bake this optimization right into the hosting, so we have teamed up with Acenet hosting to provide you http://socialfoxhosting.com/ with built-in PHP, web server and database performance enhancements. Custom optimization may be required when your community grows huge, but that is different for everyone and we will continue to provide it as a separate service.

References

  • http://blog.arvixe.com/optimizing-socialengine-4-performance/
  •  
  • http://www.sohailriaz.com/how-to-install-memcached-with-memcache-php-extension-on-centos-5x/
  •  
  • http://2bits.com/articles/installing-php-apc-gnulinux-centos-5.html
  •  
  • http://www.easywms.com/easywms/?q=en/node/210
  •  
  • http://www.ducea.com/2006/10/30/php-accelerators/
  •  


Edited by Les, 02 February 2016 - 08:08 PM.

:emo: Please don't forget to  27-AwardsImgIcon.png "LIKE" if you like this post or if it is helpful to you. This is a way to show gratitude for the help that you received. After all, the "LIKE" costs you nothing. Don't you agree? Also, any and all modules, plug-ins, themes, widgets, or DB entries that are shared or posted by me are for educational purposes. Please visit the developers websites and purchase legitimately, if you like them. Thanks, Les

socialengine-experts.png

 

 


#2 zoldos

zoldos

    Level 7

  • Premium
  • Level
  • 266 points
  • 1,197 posts
    • Gender:Male
    • Location:the US south
    • Software:SE 4.8.x


Users Awards

Posted 18 July 2016 - 12:07 PM

Cool, thanks Les! :)


Be glad you still have your mind...and your soul...

#3 zoldos

zoldos

    Level 7

  • Premium
  • Level
  • 266 points
  • 1,197 posts
    • Gender:Male
    • Location:the US south
    • Software:SE 4.8.x


Users Awards

Posted 20 August 2016 - 07:03 PM

Now using Xcache. WOW, very nice performance boost.  Highly recommended!!


Be glad you still have your mind...and your soul...

#4 Anarchist1

Anarchist1

    Level 2

  • Members
  • Level
  • 50 points
  • 38 posts

Posted 16 July 2017 - 02:21 PM

xcache doesn't work with PHP7.0

https://groups.googl...che/xgEnMwcqpZQ



#5 Anarchist1

Anarchist1

    Level 2

  • Members
  • Level
  • 50 points
  • 38 posts

Posted 16 July 2017 - 02:54 PM

Id be more interested on how you setup Nginx with PHP7 on SE to Optimal speed. I have APCU installed but I don't know if i got it setup right for speeding up social engine with Nginx web server.

 i find many setups for Apache2 but I'm not using apache.


Edited by Anarchist1, 16 July 2017 - 02:55 PM.


#6 paulsj

paulsj

    Level 7

  • Premium
  • Level
  • 378 points
  • 1,255 posts


Users Awards

Posted 17 July 2017 - 02:24 AM

That's right. If you have PHP 7 Xcache will not work. APCu maybe still available but you have to enable it in php.ini and some other file locations. Cloudflare.com is probably your best option to protect and speed up your website.



#7 Anarchist1

Anarchist1

    Level 2

  • Members
  • Level
  • 50 points
  • 38 posts

Posted 17 July 2017 - 11:03 PM

Thanks,  I got APCU enabled.  I will try to add Cloudflare to the mix.



#8 Kronos

Kronos

    Level 4

  • Members
  • Level
  • 22 points
  • 136 posts
    • Gender:Not Telling
    • Software:SE 4.8.x

Posted 08 June 2020 - 01:59 AM

Can you do one for redis cache?

 Somehow socialengine is not finding my memcached



#9 varshaan

varshaan

    Level 2

  • Members
  • Level
  • 23 points
  • 33 posts
    • Gender:Male
    • Location:Bangalore
    • Software:SE 4.8.x

Posted 14 June 2020 - 07:15 AM

Installing Redis for ubuntu 1. sudo apt-get install redis-server // install 2. sudo systemctl enable redis-server.service // enable 3. sudo vim /etc/redis/redis.conf // configure 4. sudo systemctl restart redis-server.service // restart (or) use service restart 5. sudo apt-get install php-redis // install redis extension to php check based on your php version 6. redis-cli // test if redis is up and running

Can you do one for redis cache?

 Somehow socialengine is not finding my memcached

 

check if memcache for php is added 

->   libmemcached is part of php essentials
    

 



#10 Kronos

Kronos

    Level 4

  • Members
  • Level
  • 22 points
  • 136 posts
    • Gender:Not Telling
    • Software:SE 4.8.x

Posted 17 June 2020 - 03:10 AM

Thanks for replying, I've installed both already, had lots of issues with Redis.

I might try again.

I have memcached and memcache.  Still getting some issues  SE backend.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users


All the resources listed here are just for testing purpose and they shouldn't be used at any commercial environment without a valid license.
Those are for users who wants to try them before buy. Help the developer to build it better by purchasing them from original authors.