首页 \ 问答 \ Java OutputStream文件使用httpclient上传性能(Java OutputStream file upload performances using httpclient)

Java OutputStream文件使用httpclient上传性能(Java OutputStream file upload performances using httpclient)

我有一个在我的linux服务器(debian 7)的后台运行的java jar应用程序。 服务器通常通过apache接收文件,然后jar定期拉出数据库,使用来自httpclient(v2.5)的http连接池将文件上传到最终目的地。

服务器是16GB RAM,8核cpu,1To磁盘和2Gb / s互联网带宽。 我的问题是,jar的上传只占10%或20%的带宽。 经过多次调查后,我认为这是因为远程服务器的容量可能是瓶颈。 所以我想在我的服务器上启动更多线程以同时处理更多文件并使用我拥有的所有带宽,不幸的是,使用httpclient进行文件上传似乎正在吃掉很多cpu!

实际上,jar正在使用20个同时上传的可运行线程,并且cpu始终处于100%,如果我尝试启动更多线程,则平均负载增加并打破记录,使系统变得如此缓慢且无法使用。 奇怪的是,iowaits似乎是null,所以我真的不知道是什么导致了平均负载。

我只使用一个线程运行一个hprof,结果如下:

CPU SAMPLES BEGIN (total = 4617) Thu Jul 28 17:42:35 2016 rank self accum count trace method 1 52.76% 52.76% 2436 301157 java.net.SocketOutputStream.socketWrite0 2 33.53% 86.29% 1548 300806 java.net.SocketInputStream.socketRead0 3 1.62% 87.91% 75 301138 org.sqlite.core.NativeDB.step 4 1.47% 89.39% 68 301158 java.io.FileInputStream.readBytes 5 1.06% 90.45% 49 300078 java.lang.ClassLoader.defineClass1 6 0.26% 90.71% 12 300781 com.mysql.jdbc.SingleByteCharsetConverter.<clinit> 7 0.19% 90.90% 9 300386 java.lang.Throwable.fillInStackTrace 8 0.19% 91.10% 9 300653 java.lang.ClassLoader.loadClass 9 0.19% 91.29% 9 300780 com.mysql.jdbc.SingleByteCharsetConverter.<clinit> 10 0.17% 91.47% 8 300387 java.net.URLClassLoader.findClass 11 0.17% 91.64% 8 300389 java.util.zip.Inflater.inflateBytes 12 0.15% 91.79% 7 300090 java.lang.ClassLoader.findBootstrapClass 13 0.15% 91.94% 7 300390 java.util.zip.ZipFile.getEntry 14 0.13% 92.07% 6 300805 java.net.PlainSocketImpl.socketConnect

这些文件使用一个常见的httpclient POST执行请求发送,该请求使用来自filebody类的覆盖writeTo()方法,该类使用8kb的bufferedInputStream。

您是否认为可以降低文件上传的性能影响,并解决我未使用的带宽问题?

在此先感谢您的帮助。


I have a java jar application running in the background of my linux servers (debian 7). The servers receives files through apache generally, then the jar pull the database regularly to upload the files to their final destination using a pool of http connections from an httpclient (v2.5).

The servers are 16gb of ram, 8 cores cpu, 1To disk and 2Gb/s internet bandwidth. My problem is that the bandwidth is only used at 10% or 20% for the uploads made by the jar. After many investigations I think it is because of the capacity of the distant server which might be the bottleneck. So I wanted to launch more threads on my servers to proceed more files at the same time and use all the bandwidth I have, unfortunately file upload with httpclient is eating a lot of cpu it seems !

Actually the jars are working with 20 simultaneous upload runnable threads and the cpu is constantly at 100%, if I try to start more threads the load average increase and break records, getting the system so slow and unusable. Strange thing is the iowaits seems to be null, so I really don't know what is causing the load average.

I have run an hprof using only one thread, here is the result :

CPU SAMPLES BEGIN (total = 4617) Thu Jul 28 17:42:35 2016 rank self accum count trace method 1 52.76% 52.76% 2436 301157 java.net.SocketOutputStream.socketWrite0 2 33.53% 86.29% 1548 300806 java.net.SocketInputStream.socketRead0 3 1.62% 87.91% 75 301138 org.sqlite.core.NativeDB.step 4 1.47% 89.39% 68 301158 java.io.FileInputStream.readBytes 5 1.06% 90.45% 49 300078 java.lang.ClassLoader.defineClass1 6 0.26% 90.71% 12 300781 com.mysql.jdbc.SingleByteCharsetConverter.<clinit> 7 0.19% 90.90% 9 300386 java.lang.Throwable.fillInStackTrace 8 0.19% 91.10% 9 300653 java.lang.ClassLoader.loadClass 9 0.19% 91.29% 9 300780 com.mysql.jdbc.SingleByteCharsetConverter.<clinit> 10 0.17% 91.47% 8 300387 java.net.URLClassLoader.findClass 11 0.17% 91.64% 8 300389 java.util.zip.Inflater.inflateBytes 12 0.15% 91.79% 7 300090 java.lang.ClassLoader.findBootstrapClass 13 0.15% 91.94% 7 300390 java.util.zip.ZipFile.getEntry 14 0.13% 92.07% 6 300805 java.net.PlainSocketImpl.socketConnect

the files are sent with a common httpclient POST execute request with an overrided writeTo() method from the filebody class that uses a bufferedInputStream of 8kb.

Do you think it is possible to reduce the performance impact of the file uploads, and solve my problem of unused bandwidth ?

Thanks in advance for your help.


原文:https://stackoverflow.com/questions/38641955
更新时间:2022-04-26 11:04

最满意答案

你需要分解每个单词并进行SOUNDEX比较,这正是我要告诉你的这个功能所做的。

使用该功能

用法示例: SELECT p.name FROM products p WHERE soundex_match('fiftythree', p.name, ' ')

它需要3个参数:

  • 针:你正在寻找的词
  • haysack:你正在搜索的字串
  • splitChar:将字符串拆分为单个单词的空白字符。 通常它是空间('')

如果干草堆中的任何单词听起来与针类似,则函数将返回1,否则返回0。

在数据库中创建函数

因此,进入你的数据库(phpMyAdmin或命令行)并执行此操作,你只需要这样做一次):

drop function if exists soundex_match;
delimiter $$
create function soundex_match (needle varchar(128), haystack text, splitChar varchar(1)) returns tinyint
  deterministic
  begin
    declare spacePos int;
    declare searchLen int default length(haystack);
    declare curWord varchar(128) default '';
    declare tempStr text default haystack;
    declare tmp text default '';
    declare soundx1 varchar(64) default soundex(needle);
    declare soundx2 varchar(64) default '';

    set spacePos = locate(splitChar, tempStr);

    while searchLen > 0 do
      if spacePos = 0 then
        set tmp = tempStr;
        select soundex(tmp) into soundx2;
        if soundx1 = soundx2 then
          return 1;
        else
          return 0;
        end if;
      end if;

      if spacePos != 0 then
        set tmp = substr(tempStr, 1, spacePos-1);
        set soundx2 = soundex(tmp);
        if soundx1 = soundx2 then
          return 1;
        end if;
        set tempStr = substr(tempStr, spacePos+1);
        set searchLen = length(tempStr);
      end if;

      set spacePos = locate(splitChar, tempStr);

    end while;

    return 0;

  end
$$
delimiter ;

http://www.imranulhoque.com/mysql/mysql-function-soundex-match-multi-word-string/


You'll need to break up each word and do the SOUNDEX comparison, which is exactly what this function I'm going to tell you about does.

Using the function

Example usage: SELECT p.name FROM products p WHERE soundex_match('fiftythree', p.name, ' ')

It takes 3 arguments:

  • needle: The word you are looking for
  • haysack: The string of words among which you are searching
  • splitChar: The whitespace charater that’ll split the string into single words. Generally it is the space(‘ ‘)

If any word in haystack sounds similar to needle, the function will return 1 and 0 otherwise.

Creating the function in your database

So go into your database (phpMyAdmin or the command line) and execute this, you only need to do it this one time):

drop function if exists soundex_match;
delimiter $$
create function soundex_match (needle varchar(128), haystack text, splitChar varchar(1)) returns tinyint
  deterministic
  begin
    declare spacePos int;
    declare searchLen int default length(haystack);
    declare curWord varchar(128) default '';
    declare tempStr text default haystack;
    declare tmp text default '';
    declare soundx1 varchar(64) default soundex(needle);
    declare soundx2 varchar(64) default '';

    set spacePos = locate(splitChar, tempStr);

    while searchLen > 0 do
      if spacePos = 0 then
        set tmp = tempStr;
        select soundex(tmp) into soundx2;
        if soundx1 = soundx2 then
          return 1;
        else
          return 0;
        end if;
      end if;

      if spacePos != 0 then
        set tmp = substr(tempStr, 1, spacePos-1);
        set soundx2 = soundex(tmp);
        if soundx1 = soundx2 then
          return 1;
        end if;
        set tempStr = substr(tempStr, spacePos+1);
        set searchLen = length(tempStr);
      end if;

      set spacePos = locate(splitChar, tempStr);

    end while;

    return 0;

  end
$$
delimiter ;

http://www.imranulhoque.com/mysql/mysql-function-soundex-match-multi-word-string/

相关问答

更多
  • 我能够通过利用临时表将列表插入临时表,然后使用我的查询表连接临时表来获得所需结果。 create temporary table searchvalues (name char(250)); insert into searchvalues values ('Name 1'),('Name 2'); select distinct id from users inner join searchvalues on soundex(fname) = soundex(name) or soundex(ln ...
  • 我怀疑这是关于SQL Server SOUNDEX()函数? 目前在jOOQ 3.2中没有对此功能的本机支持,尽管支持在#2969的路线图上。 与jOOQ中不受支持的东西一样,您可以使用纯SQL ,创建一个自定义字段,如下所示: Field fn = DSL.field("SOUNDEX({0})", String.class, argument); 有关详细信息,请参阅DSL.field() Javadoc 。 I suspect this is about the SQL Server ...
  • Geo,不知道为什么它不适合你。 我用QueryBuilder试了一下它就可以了。 但是,我确实必须用$this->stringExpression替换$this->$stringExpression $this->stringExpression 。 编辑: 我刚刚在裸应用程序中测试了您的代码,问题不在SOUNDEX中,而是在您的SQL中。 尝试为您的实体分配SQL别名: $sql = "select client.id, client.active, client.fname, client.sname ...
  • 你可能想要计算Levenshtein距离 ; 但是如果你只是想找到那些听起来类似于搜索词的记录,你可以删除任何尾随0 (仅用于填充),然后搜索带有结果前缀的soundex字符串: WHERE t.soundex LIKE CONCAT(TRIM(TRAILING '0' FROM SOUNDEX('test')), '%') You're probably looking to calculate the Levenshtein distance; but if you simply want to fi ...
  • 你需要分解每个单词并进行SOUNDEX比较,这正是我要告诉你的这个功能所做的。 使用该功能 用法示例: SELECT p.name FROM products p WHERE soundex_match('fiftythree', p.name, ' ') 它需要3个参数: 针:你正在寻找的词 haysack:你正在搜索的字串 splitChar:将字符串拆分为单个单词的空白字符。 通常它是空间('') 如果干草堆中的任何单词听起来与针类似,则函数将返回1,否则返回0。 在数据库中创建函数 因此,进入你的数 ...
  • 如果您在people表的name字段中搜索“lewis”,则执行以下查询: SELECT * FROM people WHERE soundex("lewis") = soundex(name); 这里的例子 If you're searching for "lewis" against the name field of people table, you perform this query: SELECT * FROM people WHERE soundex("lewis") = soundex( ...
  • 如果您使用的是SQl Server 2005或更高版本,则可以在SSIS中使用模糊匹配来执行此任务。 我发现我在这方面得到了明显更好的结果,而不是寻找soundex匹配或写我自己的sql scode来寻找近似的匹配。 If you are using SQl server 2005 or above, you can use fuzzy matching in SSIS to do this task. I found that I got significantly better results in d ...
  • 我用的是: # mapping from soundex to correct word soundex_to_ref = {jellyfish.soundex(w): w for w in ref_data} for line in text1: words = [soundex_to_ref.get(jellyfish.soundex(w), w) for w in line.split()] 这将为每一行生成一个单词列表,所有单词都匹配正确拼写的单词,soundex由正确拼写的单词替换。 ...
  • soundex算法用于在英语发音时用声音索引Anglo-Saxon姓氏。 如果你试图索引论坛文本 - 就像StackOverflow上的问题和答案 - 而不是名字,它可能不是一个好的选择。 请查看全文搜索 。 话虽如此,如果你碰巧索引姓氏,你可能会通过存储编码获得更好的性能。 理想情况下,您需要包含CHECK约束,以确保在名称更改时更新编码,但MySQL不会强制执行CHECK约束。 您需要编写触发器以使两列保持同步。 大多数平台上的替代方法是创建soundex()(或您使用的任何函数)返回的值的索引。 像c ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)