我们知道Redis并没有自己实现内存池,没有在标准的系统内存分配器上再加上自己的东西。所以系统内存分配器的性能及碎片率会对Red
我们知道Redis并没有自己实现内存池,没有在标准的系统内存分配器上再加上自己的东西。所以系统内存分配器的性能及碎片率会对Redis造成一些性能上的影响。
在Redis的 zmalloc.c 源码中,我们可以看到如下代码:
48 /* Explicitly override malloc/free etc when using tcmalloc. */ 49 #if defined(USE_TCMALLOC) 50 #define malloc(size) tc_malloc(size) 51 #define calloc(count,size) tc_calloc(count,size) 52 #define realloc(ptr,size) tc_realloc(ptr,size) 53 #define free(ptr) tc_free(ptr) 54 #elif defined(USE_JEMALLOC) 55 #define malloc(size) je_malloc(size) 56 #define calloc(count,size) je_calloc(count,size) 57 #define realloc(ptr,size) je_realloc(ptr,size) 58 #define free(ptr) je_free(ptr) 59 #endif从上面的代码中我们可以看到,Redis在编译时,会先判断是否使用tcmalloc,如果是,会用tcmalloc对应的函数替换掉标准的libc中的函数实现。其次会判断jemalloc是否使得,最后如果都没有使用才会用标准的libc中的内存管理函数。
而在最新的2.4.4版本中,jemalloc已经作为源码包的一部分包含在源码包中,所以可以直接被使用。而如果你要使用tcmalloc的话,是需要自己安装的。
下面简单说一下如何安装tcmalloc包,tcmalloc是google-proftools中的一部分,所以我们实际上需要安装google-proftools。如果你是在64位机器上进行安装,需要先安装其依赖的libunwind库。
wget tar zxvf libunwind-0.99-alpha.tar.gz cd libunwind-0.99-alpha/ CFLAGS=-fPIC ./configure make CFLAGS=-fPIC make CFLAGS=-fPIC install然后再进行google-preftools的安装:
wget tar zxvf google-perftools-1.8.1.tar.gz cd google-perftools-1.8.1/ ./configure --disable-cpu-profiler --disable-heap-profiler --disable-heap-checker --disable-debugalloc --enable-minimal make && make install sudo echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf #如果没有这个文件,自己建一个 sudo /sbin/ldconfig然后再进行Redis的安装,在make时指定相应的参数以启用tcmalloc
$ curl -O $ tar xzvf redis-2.4.4.tar.gz $ cd redis-2.4.4 $ make USE_TCMALLOC=yes FORCE_LIBC_MALLOC=yes $ sudo make install再启动Redis后通过info命令就能看到使用的内存分配器了。
下面回到本文的主题,对于tcmalloc,jemalloc和libc对应的三个内存分配器。其性能和碎片率如何呢?下面是一个简单测试结果,使用Redis自带的redis-benchmark写入等量数据进行测试,数据摘自采用不同分配器时Redis info信息。我们可以看到,采用tcmalloc时碎片率是最低的,为1.01,,jemalloc为1.02,而libc的分配器碎片率为1.31,如下所未:
used_memory:708391440 used_menory_human:675.57M used_memory_rss:715169792 used_memory_peak:708814040 used_memory_peak_human:675.98M mem_fragmentation_ratio:1.01 mem_allocator:tcmalloc-1.7used_memory:708381168 used_menory_human:675.56M used_memory_rss:723587072 used_memory_peak:708803768 used_memory_peak_human:675.97M mem_fragmentation_ratio:1.02 mem_allocator:jemalloc-2.2.1used_memory:869000400 used_menory_human:828.74M used_memory_rss:1136689152 used_memory_peak:868992208 used_memory_peak_human:828.74M mem_fragmentation_ratio:1.31 mem_allocator:libc上面的测试数据都是小数据,也就是说单条数据并不大,下面我们尝试设置benchmark的-d参数,将value值调整为1k大小,测试结果发生了一些变化:
used_memory:830573680 used_memory_human:792.10M used_memory_rss:849068032 used_memory_peak:831436048 used_memory_peak_human:792.92M mem_fragmentation_ratio:1.02 mem_allocator:tcmalloc-1.7used_memory:915911024 used_memory_human:873.48M used_memory_rss:927047680 used_memory_peak:916773392 used_memory_peak_human:874.30M mem_fragmentation_ratio:1.01 mem_allocator:jemalloc-2.2.1used_memory:771963304 used_memory_human:736.20M used_memory_rss:800583680 used_memory_peak:772784056 used_memory_peak_human:736.98M mem_fragmentation_ratio:1.04 mem_allocator:libc可以看出,在分配大块内存和小块内存上,几种分配器的碎片率差距还是比较大的,大家在使用Redis的时候,还是尽量用自己真实的数据去做测试,以选择最适合自己数据的分配器。

mysqlviewshavelimitations:1)supportallsqloperations、制限、dataManipulationswithjoinsorubqueries.2)それらは、特にパフォーマンス、特にパルフェクソルラージャターセット

reperusermanmanagementInmysqliscialforenhancingsecurationsinginuring databaseaperation.1)usecreateusertoaddusers、指定connectionsourcewith@'localhost'or@'% '。

mysqldoes notimposeahardlimitontriggers、しかしpracticalfactorsdeTerminetheireffectiveuse:1)serverconufigurationStriggermanagement; 2)complentiggersincreaseSystemload;

はい、それはssafetostoreblobdatainmysql、butonsiderheSeCactors:1)Storagespace:blobscanconsumesificantspace.2)パフォーマンス:パフォーマンス:大規模なドゥエットブロブスメイズ階下3)backupandrecized recized recized recize

PHP Webインターフェイスを介してMySQLユーザーを追加すると、MySQLI拡張機能を使用できます。手順は次のとおりです。1。MySQLデータベースに接続し、MySQLI拡張機能を使用します。 2。ユーザーを作成し、CreateUserステートメントを使用し、パスワード()関数を使用してパスワードを暗号化します。 3. SQLインジェクションを防ぎ、MySQLI_REAL_ESCAPE_STRING()関数を使用してユーザー入力を処理します。 4.新しいユーザーに権限を割り当て、助成金ステートメントを使用します。

mysql'sblobissuitable forstoringbinarydatawithinarationaldatabase、whileenosqloptionslikemongodb、redis、andcassandraofferferulesions forunstructureddata.blobissimplerbutcanslowdowdowd withwithdata

toaddauserinmysql、使用:createuser'username '@' host'identifidedby'password '; here'showtodoitsely:1)chosehostcarefilytoconを選択しますTrolaccess.2)setResourcelimitslikemax_queries_per_hour.3)usestrong、uniquasswords.4)endforcessl/tlsconnectionswith

toavoidcommonMonmistakeswithStringDatatypesinmysql、undultingStringTypenuste、choosetherightType、andManageEncodingandCollationsEttingtingive.1)Usecharforfixed-LengthStrings、Varcharforaible Length、AndText/Blobforlardata.2)setCurrectCherts


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

MinGW - Minimalist GNU for Windows
このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

Dreamweaver Mac版
ビジュアル Web 開発ツール

DVWA
Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

ドリームウィーバー CS6
ビジュアル Web 開発ツール
