我创建了一个基于spring,jms和activemq的简单的生产者消费者模拟,我试图从双方,生产者和消费者那里获得高性能,
连接设置:
<tx:annotation-driven />
<bean id="transactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="connectionFactory" />
</bean>
<amq:connectionFactory id="amqConnectionFactory" brokerURL="failover:(tcp://${broker.url}:61616)" />
<bean id="connectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="amqConnectionFactory" />
</bean>
<amq:queue id="queue" physicalName="queue" />
<beans:bean id="jsonMessageConverter" class="XXXXX.converter.JsonMessageConverter" />
Run Code Online (Sandbox Code Playgroud)
消费者设置:
<jms:listener-container concurrency="10"
acknowledge="auto" prefetch="1" message-converter="jsonMessageConverter" transaction-manager="transactionManager"
>
<jms:listener id="queueListener_1" destination="ooIntegrationQueue"
ref="myMessageListenerAdapter" />
</jms:listener-container>
<beans:bean id="myMessageListenerAdapter"
class="org.springframework.jms.listener.adapter.MessageListenerAdapter" >
<beans:property name="delegate" ref="consumer"/>
</beans:bean>
<beans:bean id="consumer" class="XXX.ConsumerImpl"/>
Run Code Online (Sandbox Code Playgroud)
制片人设置:
<beans:bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"
p:connectionFactory-ref="connectionFactory" p:messageConverter-ref="jsonMessageConverter"
p:defaultDestination-ref="ooIntegrationQueue" p:sessionTransacted="true" />
Run Code Online (Sandbox Code Playgroud)
从消费者开始,我设法每秒消耗大约25条消息,这是非常慢的,我发现瓶颈是我正在使用交易,谷歌搜索后,玩配置,我发现自动装配DefaultMessageListenerContainer并将cachelevel更改为
listenerContainer.setCacheLevelName("CACHE_SESSION")
Run Code Online (Sandbox Code Playgroud)
我的性能增加到每秒约1500条消息,同时仍然有交易.
我的问题是现在生产者仍然停留在每秒约25次操作,我的生产者测试很简单:
int numOfMessages = getNumberOfMessages();
double startTime = System.currentTimeMillis();
for (int …Run Code Online (Sandbox Code Playgroud) 我有以下非常简单的代码 -
int x=15000
int z=0.7*x
cout<<"z = "<<z<<endl;
Run Code Online (Sandbox Code Playgroud)
我得到了输出
z=10499
Run Code Online (Sandbox Code Playgroud)
但如果我改变它
int z=0.7*15000
cout<<"z = "<<z<<endl;
Run Code Online (Sandbox Code Playgroud)
输出
z=10500
Run Code Online (Sandbox Code Playgroud)
我知道它与z将结果转换为int有关,但为什么它在两种情况下都不同?
谢谢,
编辑 - 我正在使用ubuntu的10.10 GCC版本
我正在开始组装,我正在使用nasm来组装代码,我正在尝试处理驻留在内存中的字符串并更改它,我想检查一个字节是否在某个范围内(ascii)所以我可以决定怎么处理它,我似乎无法想象如何检查一个值是否在一定范围内,我知道所有关于不同类型的跳转标志但我如何组合2个cmp语句?
我的问题是:我如何在装配中生产类似的东西?
if (x>=20 && x<=100)
do something
Run Code Online (Sandbox Code Playgroud)
非常感谢 !
Evented和Threaded模型很受欢迎,通常会讨论很多.
每个I/O操作都可以阻塞的"线程"方法更简单.编写和调试同步代码更容易,事实上大多数生态系统提供了阻塞I/O库,只需使用线程池,正确配置它就可以了.
但是......它没有扩展.
然后是'Evented'方法,其中有一个线程(或每个cpu一个)永远不会阻塞并仅执行CPU指令.当IO返回时,它会激活适当的计算,从而更好地利用CPU.
但是......代码更难编写,更容易创建不可读的意大利面条代码,没有足够的库用于异步I/O等......非阻塞和阻塞I/O不能很好地混合.在生态系统中使用非常有问题,这些生态系统并非从头开始设计为非阻塞.在NodeJS中,所有I/O从一开始就是非阻塞的(因为javascript从未有过I/O库).祝你在C++/Java中实现同样的功能.你可以尽力而为,但需要一个同步调用来扼杀你的表现.
然后来了Go.我最近开始研究Go因为我发现它的并发模型很有趣.Go使您能够"充分利用两个世界",所有I/O都阻塞,编写同步代码,但享受CPU的充分利用.
Go有一个名为'Go Routines'的Threads抽象,它基本上是用户级线程,'Go Runtime'(用你的程序编译)负责在实际操作系统线程上调度不同的Go Routines(比方说1)每个CPU执行一个系统调用时,'Go Runtime'计划另一个Go Routine在一个OS线程中运行,它将go-routines'多路复用'到OS线程上.
用户级线程不是一个新概念,Go的方法很好,而且很简单,所以我开始想知道,为什么JVM世界不使用类似的抽象,它与孩子的游戏相比,通常发生在幕后.
然后我发现它确实如此,Sun的1.2 JVM称它们是绿色线程,它们是用户级线程,但是它们只被复用到一个OS线程中,它们转移到真正的OS线程以允许使用多核CPU.
在1.2之后,为什么这与JVM世界无关?我没有看到Go方法的缺点吗?也许某些概念适用于Go,但是不能在JVM上实现?
我有以下方法:
string Company::cheap(list<Candidate*>& candidates) {
candidates.sort(candidateSalaryCompare);
for (std::list<Candidate*>::iterator iter = candidates.begin(); iter
!= candidates.end(); ++iter) {
}
int m(candidates.front()->getExpectedSalary());
list<Candidate*> potentialList;
for (std::list<Candidate*>::iterator iter = candidates.begin(); (*iter)->getExpectedSalary()
== m && iter != candidates.end(); ++iter)
potentialList.push_back(*iter);
if (potentialList.size() > 0)
potentialList.sort(candidateIdCompare);
return potentialList.front()->getId();
}
Run Code Online (Sandbox Code Playgroud)
按原样运行它,我的程序工作,但如果我在开头删除空FOR循环(没有做任何事情),我得到一个分段错误.任何线索?
编辑
候选类,实际上我不知道我在哪个行得到段错误,我正在使用eclipse并且调试器似乎不起作用
#include "../include/Candidate.h"
#include <iostream>
#include "../include/AppLogger.h"
#include <sstream>
Candidate::Candidate(string id, list<Skill> skills, list<
string> desiredJobs, double expectedSalary) :
id_(id), dateJoined_(), skills_(skills),
desiredJobs_(desiredJobs), expectedSalary_(expectedSalary),
originalSalary_(expectedSalary), gotJob_(0) {
}
void Candidate::compromise(const DateTime& currentDate) {
double salaryAfter30(0.9*this->originalSalary_); …Run Code Online (Sandbox Code Playgroud)