什么是更快,更平的文件或MySQL RAM数据库?

时间:2021-09-13 00:02:35

I need a simple way for multiple running PHP scripts to share data.

我需要一种简单的方法来运行多个PHP脚本来共享数据。

Should I create a MySQL DB with a RAM storage engine, and share data via that (can multiple scripts connect to the same DB simultaneously?)

我应该创建一个带有RAM存储引擎的MySQL数据库,并通过它共享数据(多个脚本可以同时连接到同一个数据库吗?)

Or would flat files with one piece of data per line be better?

或者每行一个数据的平面文件会更好吗?

8 个解决方案

#1


13  

Flat files? Nooooooo...

平面文件? Nooooooo ...

Use a good DB engine (MySQL, SQLite, etc). Then, for maximum performance, use memcached to cache content.

使用一个好的数据库引擎(MySQL,SQLite等)。然后,为了获得最佳性能,请使用memcached缓存内容。


In this way, you have the ease and reliability of sharing data between processes using proven server software that handles concurrency, etc... But you get the speed of having your data cached.

Keep in mind a couple things:

请记住以下几点:

  1. MySQL has a query cache. If you are issuing the same queries repeteadly, you can gain a lot of performance without adding a caching layer.
  2. MySQL有一个查询缓存。如果您反复发出相同的查询,则无需添加缓存层即可获得大量性能。

  3. MySQL is really fast anyway. Have you load-tested to demonstrate it is not fast enough?
  4. 无论如何,MySQL真的很快。您是否经过负载测试以证明它不够快?

#2


6  

Please don't use flat files, for the sanity of the maintainers.

请不要使用平面文件,以保证维护者的理智。

If you're just looking to have shared data, as fast as possible, and you can hold it all in RAM, then memcached is the perfect solution.

如果你只想尽可能快地拥有共享数据,并且你可以将它全部保存在RAM中,那么memcached就是完美的解决方案。

If you'd like persistence of data, then use a DBMS, like MySQL.

如果您想要持久化数据,那么使用像MySQL这样的DBMS。

#3


2  

Generally, a DB is better, however, if you are sharing a small, mostly static amount of data, there might be performance benefits (and simplicity) of doing it with flat files.

通常,数据库更好,但是,如果您共享一个小的,大部分是静态的数据量,那么使用平面文件执行它可能会带来性能优势(和简单性)。

Anything other than trivial data sharing and I would pick a DB however.

除了琐碎的数据共享之外的任何东西,我会选择一个数据库。

#4


2  

1- Where the flat file can be usefull: Flat file can be faster than a database, but in very specific applications. They are faster if the data is read from start to finish without any search or write. If the data dont fit in memory and need to be read fully to get the job done, It 'can' be faster than a database. Also if there is lot more write than read, flat file also shine, most default databases setups will need to make the read queries wait for the write to finish in order maintain indexes and foreign keys. Making the write queries usually slower than simple reads.

1-平面文件有用的地方:平面文件比数据库快,但在非常特定的应用程序中。如果在没有任何搜索或写入的情况下从头到尾读取数据,它们会更快。如果数据不适合内存并且需要完全读取以完成工作,那么它“可以”比数据库更快。另外如果写入比读取多得多,平面文件也会闪耀,大多数默认数据库设置都需要使读取查询等待写入完成以便维护索引和外键。使写查询通常比简单读取慢。

TD/LR vesion: Use flat files for jobs based system(Aka, simple logs parsing), not for web searches queries.

TD / LR vesion:将平面文件用于基于作业的系统(Aka,简单日志解析),而不是用于Web搜索查询。

2- Flat files pit falls: If your going with a flat file, you will need to synchronize your scripts when the file change using custom lock mechanism. Which can lead to slowdown, corruption up to dead lock if you have a bug.

2-平面文件凹陷:如果您使用平面文件,则需要在使用自定义锁定机制更改文件时同步脚本。如果你有一个bug,这会导致减速,腐败直至死锁。

3- Ram based Database ? Most databases have in memory cache for query results, search indexes, making them very hard to beat with a flat file. Because they cache in memory, making it run entirely from memory is most of the time ineffective and dangerous. Better to properly tune the database configuration.

3- Ram基于数据库?大多数数据库都有内存缓存用于查询结果,搜索索引,这使得它们很难被平面文件击败。因为它们在内存中缓存,使其完全从内存中运行,大部分时间都是无效且危险的。最好正确调整数据库配置。

If your looking to optimize performance using ram, I would first look at running your php scrips, html pages, and small images from a ram drive. Where the cache mechanism is more likely to be crude and hit the hard drive systematically for non changing static data.

如果您希望使用ram优化性能,我首先会看看运行您的php scrips,html页面和ram驱动器中的小图像。缓存机制更可能是粗糙的,并且系统地针对不变的静态数据命中硬盘驱动器。

Better result can be reach with a load balancer, clustering with a back plane connections up to ram based SAN array. But that's a whole other topic.

使用负载平衡器可以实现更好的结果,使用背板连接进行集群,直到基于ram的SAN阵列。但那是另一个话题。

5- can multiple scripts connect to the same DB simultaneously?

5-多个脚本可以同时连接到同一个DB吗?

Yes, its called connection pooling. In php (client side) its the function to open a connection its mysql-pconnect(http://php.net/manual/en/function.mysql-pconnect.php). You can configure the maximum open connection in php.ini I think. Similar setting on mysql server side define the maximum of concurrent client connections in /etc/mysql/my.cnf.

是的,它叫做连接池。在php(客户端)它的功能是打开一个连接它的mysql-pconnect(http://php.net/manual/en/function.mysql-pconnect.php)。你可以在php.ini中配置最大的开放连接。 mysql服务器端的类似设置定义了/etc/mysql/my.cnf中最大并发客户端连接数。

You must do this in order to take advantage of parrallel processessing of the cpu and avoid php script to wait the query of each other finish. It greatly increase performance under heavy load.

你必须这样做才能利用cpu的并行处理,并避免php脚本等待对方查询完成。它在重负载下大大提高了性能。

There is also one connection pool/thread pool in Apache configuration for regular web clients. See httpd.conf.

Apache配置中还有一个用于常规Web客户端的连接池/线程池。请参见httpd.conf。

Sorry for the wall of text, was bored. Louis.

对不起,文字的墙,很无聊。路易。

#5


1  

If you're running them on multiple servers, a filesystem-based approach will not cut it (unless you've got a consistent shared filesystem, which is unlikely and may not be scalable).

如果你在多个服务器上运行它们,基于文件系统的方法不会削减它(除非你有一个一致的共享文件系统,这是不太可能的,可能不是可扩展的)。

Therefore you'll need a server-based database anyway to allow the sharing of data between web servers. If you're serious about either performance or availability, your application will support multiple web servers.

因此,无论如何,您都需要基于服务器的数据库,以允许在Web服务器之间共享数据。如果您对性能或可用性非常认真,那么您的应用程序将支持多个Web服务器。

#6


0  

I would say that the MySql DB would be better choice unless you have some mechanism in place to deal with locks on the flat files (and some way to control access). In this case the DB layer (regardless of specific DBMS) is acting as an indirection layer, letting you not worry about it.

我会说MySql DB是更好的选择,除非你有一些机制来处理平面文件上的锁(以及控制访问的某种方式)。在这种情况下,DB层(无论特定的DBMS如何)充当间接层,让您不必担心它。

Since the OP doesn't specify a web server (and PHP actually can run from a commandline) then I'm not certain that the caching technologies are what they're after here. The OP could be looking to do some sort of flying data transform that isn't website driven. Who knows.

由于OP没有指定Web服务器(并且PHP实际上可以从命令行运行),所以我不确定缓存技术是否是他们在此之后所做的。 OP可能希望进行某种非网站驱动的飞行数据转换。谁知道。

#7


0  

If your system has a PHP cache (that caches compiled PHP code in memory, like APC), try putting your data into a PHP file, as PHP code. If you have to write data, there are some security issues.

如果您的系统有一个PHP缓存(将已编译的PHP代码缓存在内存中,如APC),请尝试将您的数据作为PHP代码放入PHP文件中。如果必须写入数据,则存在一些安全问题。

#8


0  

I need a simple way for multiple running PHP scripts to share data.

我需要一种简单的方法来运行多个PHP脚本来共享数据。

APC, and memcached are both good options depending on context. shared memory may also be an option.

根据上下文,APC和memcached都是不错的选择。共享内存也可能是一种选择。

Should I create a MySQL DB with a RAM storage engine, and share data via that (can multiple scripts connect to the same DB simultaneously?)

我应该创建一个带有RAM存储引擎的MySQL数据库,并通过它共享数据(多个脚本可以同时连接到同一个数据库吗?)

That's also a decent option, but will probably not be as fast as APC or memcached.

这也是一个不错的选择,但可能不会像APC或memcached那么快。

Or would flat files with one piece of data per line be better?

或者每行一个数据的平面文件会更好吗?

If this is read-only data, that's a possibility -- but may be slower than any of the options above. Especially if the data is large. Rather than writing custom parsing code, however, consider simply building a PHP array, and include() the file.

如果这是只读数据,则可能 - 但可能比上述任何选项慢。特别是如果数据很大。但是,不要编写自定义解析代码,而应考虑简单地构建PHP数组,并包含()文件。

If this is a datastore that may be accessed by several writers simultaneously, by all means do NOT use a flat file! Writing to a flat file from multiple processes is likely to lead to file corruption. You can lock the file, but you risk lock contention issues, and long lock wait times.

如果这是一个可以由多个作者同时访问的数据存储区,那么一定不要使用平面文件!从多个进程写入平面文件可能会导致文件损坏。您可以锁定该文件,但存在锁定争用问题和长锁定等待时间的风险。

Handling concurrent writes is the reason applications like mysql and memcached exist.

处理并发写入是mysql和memcached等应用程序存在的原因。

#1


13  

Flat files? Nooooooo...

平面文件? Nooooooo ...

Use a good DB engine (MySQL, SQLite, etc). Then, for maximum performance, use memcached to cache content.

使用一个好的数据库引擎(MySQL,SQLite等)。然后,为了获得最佳性能,请使用memcached缓存内容。


In this way, you have the ease and reliability of sharing data between processes using proven server software that handles concurrency, etc... But you get the speed of having your data cached.

Keep in mind a couple things:

请记住以下几点:

  1. MySQL has a query cache. If you are issuing the same queries repeteadly, you can gain a lot of performance without adding a caching layer.
  2. MySQL有一个查询缓存。如果您反复发出相同的查询,则无需添加缓存层即可获得大量性能。

  3. MySQL is really fast anyway. Have you load-tested to demonstrate it is not fast enough?
  4. 无论如何,MySQL真的很快。您是否经过负载测试以证明它不够快?

#2


6  

Please don't use flat files, for the sanity of the maintainers.

请不要使用平面文件,以保证维护者的理智。

If you're just looking to have shared data, as fast as possible, and you can hold it all in RAM, then memcached is the perfect solution.

如果你只想尽可能快地拥有共享数据,并且你可以将它全部保存在RAM中,那么memcached就是完美的解决方案。

If you'd like persistence of data, then use a DBMS, like MySQL.

如果您想要持久化数据,那么使用像MySQL这样的DBMS。

#3


2  

Generally, a DB is better, however, if you are sharing a small, mostly static amount of data, there might be performance benefits (and simplicity) of doing it with flat files.

通常,数据库更好,但是,如果您共享一个小的,大部分是静态的数据量,那么使用平面文件执行它可能会带来性能优势(和简单性)。

Anything other than trivial data sharing and I would pick a DB however.

除了琐碎的数据共享之外的任何东西,我会选择一个数据库。

#4


2  

1- Where the flat file can be usefull: Flat file can be faster than a database, but in very specific applications. They are faster if the data is read from start to finish without any search or write. If the data dont fit in memory and need to be read fully to get the job done, It 'can' be faster than a database. Also if there is lot more write than read, flat file also shine, most default databases setups will need to make the read queries wait for the write to finish in order maintain indexes and foreign keys. Making the write queries usually slower than simple reads.

1-平面文件有用的地方:平面文件比数据库快,但在非常特定的应用程序中。如果在没有任何搜索或写入的情况下从头到尾读取数据,它们会更快。如果数据不适合内存并且需要完全读取以完成工作,那么它“可以”比数据库更快。另外如果写入比读取多得多,平面文件也会闪耀,大多数默认数据库设置都需要使读取查询等待写入完成以便维护索引和外键。使写查询通常比简单读取慢。

TD/LR vesion: Use flat files for jobs based system(Aka, simple logs parsing), not for web searches queries.

TD / LR vesion:将平面文件用于基于作业的系统(Aka,简单日志解析),而不是用于Web搜索查询。

2- Flat files pit falls: If your going with a flat file, you will need to synchronize your scripts when the file change using custom lock mechanism. Which can lead to slowdown, corruption up to dead lock if you have a bug.

2-平面文件凹陷:如果您使用平面文件,则需要在使用自定义锁定机制更改文件时同步脚本。如果你有一个bug,这会导致减速,腐败直至死锁。

3- Ram based Database ? Most databases have in memory cache for query results, search indexes, making them very hard to beat with a flat file. Because they cache in memory, making it run entirely from memory is most of the time ineffective and dangerous. Better to properly tune the database configuration.

3- Ram基于数据库?大多数数据库都有内存缓存用于查询结果,搜索索引,这使得它们很难被平面文件击败。因为它们在内存中缓存,使其完全从内存中运行,大部分时间都是无效且危险的。最好正确调整数据库配置。

If your looking to optimize performance using ram, I would first look at running your php scrips, html pages, and small images from a ram drive. Where the cache mechanism is more likely to be crude and hit the hard drive systematically for non changing static data.

如果您希望使用ram优化性能,我首先会看看运行您的php scrips,html页面和ram驱动器中的小图像。缓存机制更可能是粗糙的,并且系统地针对不变的静态数据命中硬盘驱动器。

Better result can be reach with a load balancer, clustering with a back plane connections up to ram based SAN array. But that's a whole other topic.

使用负载平衡器可以实现更好的结果,使用背板连接进行集群,直到基于ram的SAN阵列。但那是另一个话题。

5- can multiple scripts connect to the same DB simultaneously?

5-多个脚本可以同时连接到同一个DB吗?

Yes, its called connection pooling. In php (client side) its the function to open a connection its mysql-pconnect(http://php.net/manual/en/function.mysql-pconnect.php). You can configure the maximum open connection in php.ini I think. Similar setting on mysql server side define the maximum of concurrent client connections in /etc/mysql/my.cnf.

是的,它叫做连接池。在php(客户端)它的功能是打开一个连接它的mysql-pconnect(http://php.net/manual/en/function.mysql-pconnect.php)。你可以在php.ini中配置最大的开放连接。 mysql服务器端的类似设置定义了/etc/mysql/my.cnf中最大并发客户端连接数。

You must do this in order to take advantage of parrallel processessing of the cpu and avoid php script to wait the query of each other finish. It greatly increase performance under heavy load.

你必须这样做才能利用cpu的并行处理,并避免php脚本等待对方查询完成。它在重负载下大大提高了性能。

There is also one connection pool/thread pool in Apache configuration for regular web clients. See httpd.conf.

Apache配置中还有一个用于常规Web客户端的连接池/线程池。请参见httpd.conf。

Sorry for the wall of text, was bored. Louis.

对不起,文字的墙,很无聊。路易。

#5


1  

If you're running them on multiple servers, a filesystem-based approach will not cut it (unless you've got a consistent shared filesystem, which is unlikely and may not be scalable).

如果你在多个服务器上运行它们,基于文件系统的方法不会削减它(除非你有一个一致的共享文件系统,这是不太可能的,可能不是可扩展的)。

Therefore you'll need a server-based database anyway to allow the sharing of data between web servers. If you're serious about either performance or availability, your application will support multiple web servers.

因此,无论如何,您都需要基于服务器的数据库,以允许在Web服务器之间共享数据。如果您对性能或可用性非常认真,那么您的应用程序将支持多个Web服务器。

#6


0  

I would say that the MySql DB would be better choice unless you have some mechanism in place to deal with locks on the flat files (and some way to control access). In this case the DB layer (regardless of specific DBMS) is acting as an indirection layer, letting you not worry about it.

我会说MySql DB是更好的选择,除非你有一些机制来处理平面文件上的锁(以及控制访问的某种方式)。在这种情况下,DB层(无论特定的DBMS如何)充当间接层,让您不必担心它。

Since the OP doesn't specify a web server (and PHP actually can run from a commandline) then I'm not certain that the caching technologies are what they're after here. The OP could be looking to do some sort of flying data transform that isn't website driven. Who knows.

由于OP没有指定Web服务器(并且PHP实际上可以从命令行运行),所以我不确定缓存技术是否是他们在此之后所做的。 OP可能希望进行某种非网站驱动的飞行数据转换。谁知道。

#7


0  

If your system has a PHP cache (that caches compiled PHP code in memory, like APC), try putting your data into a PHP file, as PHP code. If you have to write data, there are some security issues.

如果您的系统有一个PHP缓存(将已编译的PHP代码缓存在内存中,如APC),请尝试将您的数据作为PHP代码放入PHP文件中。如果必须写入数据,则存在一些安全问题。

#8


0  

I need a simple way for multiple running PHP scripts to share data.

我需要一种简单的方法来运行多个PHP脚本来共享数据。

APC, and memcached are both good options depending on context. shared memory may also be an option.

根据上下文,APC和memcached都是不错的选择。共享内存也可能是一种选择。

Should I create a MySQL DB with a RAM storage engine, and share data via that (can multiple scripts connect to the same DB simultaneously?)

我应该创建一个带有RAM存储引擎的MySQL数据库,并通过它共享数据(多个脚本可以同时连接到同一个数据库吗?)

That's also a decent option, but will probably not be as fast as APC or memcached.

这也是一个不错的选择,但可能不会像APC或memcached那么快。

Or would flat files with one piece of data per line be better?

或者每行一个数据的平面文件会更好吗?

If this is read-only data, that's a possibility -- but may be slower than any of the options above. Especially if the data is large. Rather than writing custom parsing code, however, consider simply building a PHP array, and include() the file.

如果这是只读数据,则可能 - 但可能比上述任何选项慢。特别是如果数据很大。但是,不要编写自定义解析代码,而应考虑简单地构建PHP数组,并包含()文件。

If this is a datastore that may be accessed by several writers simultaneously, by all means do NOT use a flat file! Writing to a flat file from multiple processes is likely to lead to file corruption. You can lock the file, but you risk lock contention issues, and long lock wait times.

如果这是一个可以由多个作者同时访问的数据存储区,那么一定不要使用平面文件!从多个进程写入平面文件可能会导致文件损坏。您可以锁定该文件,但存在锁定争用问题和长锁定等待时间的风险。

Handling concurrent writes is the reason applications like mysql and memcached exist.

处理并发写入是mysql和memcached等应用程序存在的原因。