Quantcast
Channel: Spring Community Forums - NoSQL
Viewing all articles
Browse latest Browse all 128

Get instance of MongoDB really slow

$
0
0
Hi,

I am developing an application which use Spring Data - Mongo as main DB back end. My server acts like a REST API provider, so the resources are protected by Spring oAuth. My main problem is, every time i make a service call the Spring Data framework invokes a method call which gives back a valid Mongo instance. Actually this call is really slow (like 300-500ms), so my whole WS call takes about 2 seconds.

The main problem is not even the 3-500 ms dealy, but this calling is invoked 3 times/request. My oAuth token provider is implemented to use Mongo. So two 3-500ms call needed to even authorize my user + 1 for the actual service.

My question is: Why this mongo instance not being cached? I think the solution is pretty trivial coz I am sure i missed something in the configuration section.

I'd be happy if somebody could help me out.

application-context.xml mongodb section
Code:

<!-- MONGO DB setup -->
    <mongo:mongo id="mongo" host="@{db.connection.host}" port="@{db.connection.port}"
                replica-set="@{db.connection.replicaset}" write-concern="@{db.policy.writeconcern}">
        <mongo:options connections-per-host="@{db.policy.connectionsPerHost}"
                      threads-allowed-to-block-for-connection-multiplier="@{db.policy.threadsAllowedToBlockForConnectionMultiplier}"
                      connect-timeout="@{db.policy.connectionTimeout}"
                      max-wait-time="@{db.policy.maxWaitTime}"
                      auto-connect-retry="@{db.policy.autoConnectRetry}"
                      socket-keep-alive="@{db.policy.socketKeepalive}"
                      socket-timeout="@{db.policy.socketTimeout}"
                      slave-ok="@{db.policy.slaveOk}"
                      write-number="@{db.policy.writeNumber}"
                      write-timeout="@{db.policy.writeTimeout}"
                      write-fsync="@{db.policy.writeFsync}"/>
    </mongo:mongo>
    <mongo:db-factory id="mongoFactory" mongo-ref="mongo" username="@{db.connection.user}"
                      password="@{db.connection.password}" dbname="@{db.connection.dbname}"/>
    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
        <constructor-arg name="mongoDbFactory" ref="mongoFactory"/>
    </bean>
    <mongo:repositories base-package="com.mycompany" mongo-template-ref="mongoTemplate"/>
    <mongo:auditing />

db.properties file
Code:

##########################
# DATABASE CONNECTION INFO
##########################
db.connection.host=hostname
db.connection.port=port
db.connection.dbname=dbname
db.connection.user=developer
db.connection.password=mysecretpassword
db.connection.replicaset=

###################
# DATABASE POLICIES
###################
#Possible values are: NONE, NORMAL, SAFE (default), FSYNC_SAFE, REPLICAS_SAFE, JOURNAL_SAFE, MAJORITY
db.policy.writeconcern=SAFE
db.policy.connectionsPerHost=20
db.policy.threadsAllowedToBlockForConnectionMultiplier=4
db.policy.connectionTimeout=1000
db.policy.maxWaitTime=1500
db.policy.autoConnectRetry=false
db.policy.socketKeepalive=true
db.policy.socketTimeout=0
db.policy.slaveOk=false
db.policy.writeNumber=1
db.policy.writeTimeout=0
db.policy.writeFsync=false

oauth related setup
Code:

    <s:http pattern="/timetable/**" create-session="never" entry-point-ref="oauthAuthenticationEntryPoint"
            access-decision-manager-ref="accessDecisionManager">
        <s:anonymous enabled="false" />
        <s:intercept-url pattern="/timetable" access="ROLE_USER,SCOPE_READ" />
        <s:custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
        <s:access-denied-handler ref="oauthAccessDeniedHandler" />
    </s:http>

Thanks anyway.

Viewing all articles
Browse latest Browse all 128

Trending Articles