且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java EE,EJB文件处理

更新时间:2023-12-03 13:45:52

您实际上有四个方面,


  1. 接收和发送文件

  2. 创建缩略图

  3. 将文件存储在某处每个节点都可以访问

  4. 将原始+缩略图实体存储在公共数据库中

  1. Receiving and sending files
  2. Creating thumbnails
  3. Storing the files somewhere every node can access
  4. Storing the original + thumbnail entities in a common database

既然你已经有Java EE服务器,您可能还有一个(HTTP)servlet服务器,其中有很多方法进行负载平衡,并且缓存,更不用说基于Web的互动的潜在潜力。如果有的话,支持使用目录监视器进行FTP传输作为奖励。

Since you already have Java EE server, you probably also already have a (HTTP) servlet server, in which there is numerious ways of doing load balancing and caching, not to mention the obious potential for web-based interaction. If anything, support FTP transfer with a directory watcher as a bonus.

您不应该使用无状态会话bean创建缩略图,这意味着您的服务器将在高峰时段崩溃 - 服务器将优先考虑建立新连接时的业务逻辑。相反,首先在数据库中接收并存储文件+原始实体,然后使用服务bean对缩略图创建进行排队(如果需要,可以使用n个工作线程或消息队列)。您也可以在某些情况下使用本地工具,我们在linux中。

You should not create the thumbnails using stateless session beans, this means your servers will be crap at peak time - the server will give priority to buisness logic over making new connections. Rather, first receieve and store the file + original entity in the database, and then use a service bean to queue up thumbnail creation (maybe with n worker threads or message queues if you want). You can also use native tools in some cases, we do in linux.

您应该使用共享文件系统SAN,这是几个共享文件的正确工具机器。并根据您的文件系统的限制来构建文件,例如每个目录的文件数量和读/写容量。

You should use a shared file system, SAN, which is the right tool for sharing files across several machines. And structure your files according to your file system's limits - like number of files per directory and read/write capacity.

只要您不用大二进制blob来杀死单个数据库,至少可以使用一个小型的数据库。

And a single database will be good enough for at least a small cluster, as long as you are not killing it with big binary blobs.

如果有疑问,请购买更多的ram;)特别是缩略图是非常高速缓存的,并将在Tomcat中提供良好的性能 - 如果您不熟悉多线程,请在google找到一个缓存。还自然缓存实体,不仅是文件。

If in doubt, buy more ram ;) Especially the thumbnails are very cachable and will give good performance also in Tomcat - if you are not familiar with multi-threading, find a cache at google. Also cache the entities naturally, not only the files.