设为首页 收藏本站
查看: 1203|回复: 0

[经验分享] Memcached windows下编译

[复制链接]

尚未签到

发表于 2015-9-1 03:44:05 | 显示全部楼层 |阅读模式
以下为转载国外网站关于 Memcache windows下的编译文章

Tuesday, March 30, 2010















Building Memcached on Windows






  I like to be able to compile my software on multiple platforms with different compilers, because it force me to write that complies to standards (if not you'll most likely have a spaghetti of #ifdefs all over your code). One of the bonuses you get from using multiple compilers is that you'll get "more eyes" looking at your code, and they may warn you on different things. Supporting multiple platforms will also make it easier to ensure that you don't have 'hidden bombs' in your code (byte order, alignment, assumptions that you can dereference a NIL pointer etc)...
  Building software that runs on different flavors of Unix/Linux isn't that hard, but adding support for Microsoft Windows offers some challenges. Among the challenges are:


  • Microsoft Windows doesn't provide the headerfiles found on most Unix-like systems (unistd.h etc).
  • Sockets is implemented in a separate "subsystem" on windows.
  • Win32 provides another threads/mutex implementation than what most software written for Unix-like systems use (pthreads).
  • Microsoft doesn't supply a C99 compiler. One would think that it would be safe to assume that one could use a C standard that is more than 10 years old....
  I am really glad to announce that we just pushed a number of changesets to memcached to allow you to build memcached on windows "just as easy" as you would on your favorite Unix/Linux system. This means that as of today users using Microsoft Windows is no longer stuck with an ancient version!
  `The first thing you need to do in order to build memcached on Windows is to install the "fullversion" of msysgit. In addition to installing git, it also installs a compiler capable of building a 32 bit version of memcached.
  So let's go ahead and build the dependencies we need to get our 32bit memcached version up and running!
  The first thing up is libevent. You should download the latest 2.x release available (there is a bug in all versions up to (and including) 2.0.4, so unless there is a new one out there you can grab a development version I pushed to libevent-2.0.4-alpha-dev.tar.gz), and install it with the following commands (from within your msysgit-shell). Please note that I'm using /tmp because I've had problems using my "home directory" because of spaces in the directory name (or at least I guess that's the reason ;-) ):
$ cd /tmp
$ tar xfz libevent-2.0.4-alpha-dev.tar.gz
$ cd libevent-2.0.4-alpha-dev
$ ./configure --prefix=/usr/local
$ make all                    (this will fail with an error, but don't care about that.. it's is in the example code)
$ make install             (this will fail with an error, but don't care about that.. it's just an example)


  It's time to start build memcached!!! Let's check out the source code and build it!
  $ git clone git://github.com/trondn/memcached.git
$ git checkout -t origin/engine
$ make -f win32/Makefile.mingw

  You should now be able to start memcached with the following command:
$ ./memcached.exe -E ./libs/default_engine.so

  Go ahead and telnet to port 11211 and issue the "stats" command to verify that it works!
  You don't need to install msysgit on the systems where you want to run memcached, but you do need to include pthreadGC2.dll from the msysgit distribution. That means that if you want to run memcached on another machine you need to copy the following files: memcached.exe .libs/default_engine.so and /mingw/bin/pthreadGC2.dll (Just place them in the same directory on the machine you want to run memcached on :-)

But wait, the world is 64 bit by now. Lets build a 64 bit binary instead
  The msysgit we installed previously isn't capable of building a 64-bit binary, so we need to install a new compiler. Download the a bundle from http://sourceforge.net/projects/mingw-w64/files/ (I used mingw-w64-bin_i686-mingw_20100129.zip ). You can "install" it by running the following commands in our msysgit shell:
$ mkdir /mingw64
$ cd /mingw64
$ unzip /mingw-w64-bin_i686-minw_20100129.zip
$ export PATH=/mingw64/bin:/usr/local/bin:$PATH

  So let's start compiling libevent:
$ cd /tmp
$ tar xfz libevent-2.0.4-alpha-dev.tar.gz
$ cd libevent-2.0.4-alpha-dev
$ ./configure --prefix=/usr/local --host=x86_64-w64-mingw32 --build=i686-pc-mingw32
$ make all
$ make install

  The compiler we just downloaded didn't come with a 64-bit version of pthreads, so we have to download and build that ourself. I've pushed a package to my machine at: pthreads-w64-2-8-0-release.tar.gz
$ cd /tmp
$ tar xfz pthreads-w64-2-8-0-release.tar.gz
$ cd pthreads-w64-2-8-0-release
$ make clean GC CC=x86_64-w64-mingw32-gcc
$ cp pthread.h semaphore.h sched.h /usr/local/include
$ cp libpthreadGC2.a /usr/local/lib/libpthread.a
$ cp pthreadGC2.dll /usr/local/lib
$ cp pthreadGC2.dll /usr/local/bin

  And finally memcached with:
$ git clone git://github.com/trondn/memcached.git
$ git checkout -t origin/engine
$ make -f win32/Makefile.mingw CC=x86_64-w64-mingw32-gcc

So how does it perform?
  I'm pretty sure a lot of the "Linux fanboys" are ready to jump in and tell how much faster the Linux version is. I have to admit that I was a bit skeptical in the beginning if the layers we added to get "Unix compatibility" had any performance impact. The only way to know for sure is to run a benchmark to measure the performance.
  I ran a small benchmark where I had my client create 512 connections to the server, and then randomly choosing a connection and perform a get or a set operation on one of the 100 000 items I had stored in the server. I ran 500 000 operation (33% of the operations are set operations), and calculated the average time. I can dual-boot one of my machines into Windows 7 and Red Hat Enterprise Linux, so my results shows the "out of the box"-numbers between Windows 7 and Red Hat Enterprise Linux running on the same hardware. I used my OpenSolaris box to drive the test (connected to the same switch). Posting numbers is always "dangerous", because people put too much into the absolute numbers. The intention with my graphs is to show that the version running on Microsoft Windows is pretty much "on par" with the Linux version.
  
  
DSC0000.png DSC0001.png DSC0002.png






Lagt inn av Trond Norbye kl. 10:05 AM

Email This BlogThis! Share to Twitter Share to Facebook Share to Google Buzz






11 kommentarer:






Ren said...
  Nice, compiled ok on XP.
Slight snag was /tmp was mapped to a path with spaces which causes libevent to not install some of its headers.

March 30, 2010 7:46 PM


lrancez said...
  Great job!!!
Buuuuut..... the version from trondn/memcached.git is 1.3.3 and the last official version is 1.4.5 (http://www.memcached.org)....
Using totalcommander I notice several differences between versions.
And if I try to use the official repository instead of trondn's repository, the code wont compile.
Also, the result exe wont work as a windows service or as a deamon either. This port does the trick but uses version 1.2.1 (Dec 23, 2006)...
Never the less, the version 1.3.3 seems to work ok. Here is the compiled result from my Intel x86:
http://fox.originsoftware.com.ar/memcached-1.3.3.zip
Cheers,
Lucas

April 22, 2010 9:06 PM


lrancez said...
  Sorry, the memcached implementation of 1.2.1 that I was referring is:
http://jehiah.cz/projects/memcached-win32/

April 22, 2010 9:09 PM


lrancez said...
  I just found http://northscale.com/.
They have a free implementation of 1.4.4!!!
Cheers.
Lucas

April 22, 2010 10:20 PM


marius constantin nicolescu said...
  broken?! why?!
fatal error: sys/utsname.h: No such file or directory
compilation terminated.
make: *** [.libs/memcached.o] Error 1

June 24, 2010 3:13 AM


Darth Muks said...
  This works very well and I can wrap the exe around a windows service for easy management.

What changes would be needed to be able to build the latest versions of memcached on Windows ? (1.4.5). As Irancez said.. it fails. I'm guessing it needs changes to the Makefile.mingw

October 19, 2010 8:26 PM


Trond Norbye said...
  We're currently working on cleaning up the next release.. I'll try to build a new 1.4.5 release that works on windows and push it somewhere... what do you folks want? a 64 bit binary?

October 19, 2010 9:51 PM


lemiel said...
  32 i 64 bit binary if it will be possible would be nice.
But because PHP is still 32bit maybe 32 bit will be enough.

November 1, 2010 7:34 PM


helpgurus said...
  Microsoft Windows doesn't provide the headerfiles found on most Unix-like systems because Microsoft Windows, pre-built binaries are available in the form of a Microsoft installer file (.msi ).

microsoft windows support

November 11, 2010 6:28 AM


NewEraCracker said...
  @Trond Norbye
Thanks for the article. Will try.
"what do you folks want? a 64 bit binary?"
binaries for 32 and 64 bits :)

January 24, 2011 3:06 PM


Trond Norbye said...
  My windows machine just died, so I need to reinstall it before I can do anything else...

January 24, 2011 3:52 PM


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-107109-1-1.html 上篇帖子: memcached client 下篇帖子: 更快bobhash, 比time33快 (memcached也使用)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表